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/008-largest_product_in_a_series.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/008-largest_product_in_a_series.jl')
| -rw-r--r-- | julia/008-largest_product_in_a_series.jl | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/julia/008-largest_product_in_a_series.jl b/julia/008-largest_product_in_a_series.jl index 7a67206..c2811be 100644 --- a/julia/008-largest_product_in_a_series.jl +++ b/julia/008-largest_product_in_a_series.jl @@ -29,7 +29,7 @@ ### -const NUMBER_STRING = join(split(" +const NUMBER_STRING = join(split(""" 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 @@ -50,12 +50,16 @@ const NUMBER_STRING = join(split(" 84580156166097919133875499200524063689912560717606 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450 -")) +""")) const CHUNK_SIZE = 13 +const NUMBERS = [parse(Int, c) for c in NUMBER_STRING] -const NUMBERS = [parse(Int, c) for c in NUMBER_STRING] -const NUMBER_CHUNKS = zip([NUMBERS[start:end] for start in 1:CHUNK_SIZE]...) -const RESULT = maximum(cumprod(chunk)[end] for chunk in NUMBER_CHUNKS) +result = ( + (NUMBERS[start:end] for start in 1:CHUNK_SIZE) + |> x -> zip(x...) + |> x -> map(prod, x) + |> maximum +) -println(RESULT) +println(result) |
