diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-06-20 20:10:05 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-06-20 20:10:05 +0200 |
| commit | e794020d8b881ede726338be50eaa461a134889f (patch) | |
| tree | 99f32380378fa6813d7ccf15b56d8b48fcd263c2 /julia/002-even_fibonacci_numbers.jl | |
| parent | 16a3e5fc6728f1c0d414983f6e1fc3fc160034b3 (diff) | |
| download | project_euler-e794020d8b881ede726338be50eaa461a134889f.tar.gz project_euler-e794020d8b881ede726338be50eaa461a134889f.tar.bz2 project_euler-e794020d8b881ede726338be50eaa461a134889f.zip | |
Refactoging julia problems with function chainning
Diffstat (limited to 'julia/002-even_fibonacci_numbers.jl')
| -rw-r--r-- | julia/002-even_fibonacci_numbers.jl | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/julia/002-even_fibonacci_numbers.jl b/julia/002-even_fibonacci_numbers.jl index 052d20d..2b4b562 100644 --- a/julia/002-even_fibonacci_numbers.jl +++ b/julia/002-even_fibonacci_numbers.jl @@ -24,17 +24,12 @@ function fib(n) end # https://stackoverflow.com/questions/56137634/function-chaining-in-julia -# need curried functions -# ( (fib(n) for n in 1:1_000_000) -# |> takewhile(<(4_000_000)) -# ) -println(sum( - Iterators.filter( - x -> x % 2 == 0, - takewhile( - <(4_000_000), - fib(n) for n in 1:1_000_000 - ) - ) -)) +result = ( + (fib(n) for n in 1:1_000_000) + |> r -> takewhile(<(4_000_000), r) + |> r -> Iterators.filter(x -> (x % 2) == 0, r) + |> sum +) + +println(result) |
