style changes
parent
920853c7bd
commit
6a0060567f
|
@ -9,6 +9,8 @@ pub fn range(start int, end int) []int {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add(i int, j int) int { return i + j }
|
||||||
|
|
||||||
pub fn even(n int) bool {
|
pub fn even(n int) bool {
|
||||||
return n % 2 == 0
|
return n % 2 == 0
|
||||||
}
|
}
|
||||||
|
|
17
v/euler001.v
17
v/euler001.v
|
@ -1,17 +1,10 @@
|
||||||
|
import euler
|
||||||
|
|
||||||
fn multiples_of_three_and_five_below(n int) []int {
|
fn multiples_of_three_and_five_below(n int) []int {
|
||||||
mut nums := []int
|
nums := euler.range(3, n-1)
|
||||||
for i := 3; i < n; i++ {
|
return nums.filter(it % 3 == 0 || it % 5 == 0)
|
||||||
if i % 3 == 0 || i % 5 == 0 {
|
|
||||||
nums << i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nums
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut result := 0
|
println(multiples_of_three_and_five_below(1000).reduce(euler.add, 0))
|
||||||
for n in multiples_of_three_and_five_below(1000) {
|
|
||||||
result += n
|
|
||||||
}
|
|
||||||
println(result)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,5 @@ fn even_fibonacci_up_to(n int) []int {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut result := 0
|
println(even_fibonacci_up_to(4000000).reduce(euler.add, 0))
|
||||||
for n in even_fibonacci_up_to(4000000) {
|
|
||||||
result += n
|
|
||||||
}
|
|
||||||
println(result)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue