euler/v/euler002.v

19 lines
304 B
Coq
Raw Normal View History

2020-01-08 11:06:42 +00:00
import euler
fn even_fibonacci_up_to(n int) []int {
mut result := []int
mut a := 0
mut b := 1
for a + b < n {
if euler.even(a + b) { result << a + b }
temp := b
b = a + b
a = temp
}
return result
}
fn main() {
2020-01-08 11:23:40 +00:00
println(even_fibonacci_up_to(4000000).reduce(euler.add, 0))
2020-01-08 11:06:42 +00:00
}