From 6a0060567f026e38bba353a8be3521d52dded852 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Wed, 8 Jan 2020 03:23:40 -0800 Subject: [PATCH] style changes --- v/euler/euler.v | 2 ++ v/euler001.v | 17 +++++------------ v/euler002.v | 6 +----- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/v/euler/euler.v b/v/euler/euler.v index 405b57f..645fb66 100644 --- a/v/euler/euler.v +++ b/v/euler/euler.v @@ -9,6 +9,8 @@ pub fn range(start int, end int) []int { return result } +pub fn add(i int, j int) int { return i + j } + pub fn even(n int) bool { return n % 2 == 0 } diff --git a/v/euler001.v b/v/euler001.v index e2e38b3..87632c5 100644 --- a/v/euler001.v +++ b/v/euler001.v @@ -1,17 +1,10 @@ +import euler + fn multiples_of_three_and_five_below(n int) []int { - mut nums := []int - for i := 3; i < n; i++ { - if i % 3 == 0 || i % 5 == 0 { - nums << i - } - } - return nums + nums := euler.range(3, n-1) + return nums.filter(it % 3 == 0 || it % 5 == 0) } fn main() { - mut result := 0 - for n in multiples_of_three_and_five_below(1000) { - result += n - } - println(result) + println(multiples_of_three_and_five_below(1000).reduce(euler.add, 0)) } diff --git a/v/euler002.v b/v/euler002.v index cd78c5e..e0398d9 100644 --- a/v/euler002.v +++ b/v/euler002.v @@ -14,9 +14,5 @@ fn even_fibonacci_up_to(n int) []int { } fn main() { - mut result := 0 - for n in even_fibonacci_up_to(4000000) { - result += n - } - println(result) + println(even_fibonacci_up_to(4000000).reduce(euler.add, 0)) }