Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 50 lines (39 sloc) 1.857 kB
6241c3e Solved firest 10 problems
Andrey Paramonov authored
1 %% Problem
2 %% ---------------------
3 %% Find the greatest product of five consecutive digits in the 1000-digit number.
4 %% ---------------------
5
6 -module(p008).
8b7a0ff Introduced solve function to all modules
Andrey Paramonov authored
7 -export([solve/0]).
6241c3e Solved firest 10 problems
Andrey Paramonov authored
8 -include_lib("eunit/include/eunit.hrl").
9
10 %% Solution
11 %% ---------------------
12
13 number() ->
14 "73167176531330624919225119674426574742355349194934" ++
15 "96983520312774506326239578318016984801869478851843" ++
16 "85861560789112949495459501737958331952853208805511" ++
17 "12540698747158523863050715693290963295227443043557" ++
18 "66896648950445244523161731856403098711121722383113" ++
19 "62229893423380308135336276614282806444486645238749" ++
20 "30358907296290491560440772390713810515859307960866" ++
21 "70172427121883998797908792274921901699720888093776" ++
22 "65727333001053367881220235421809751254540594752243" ++
23 "52584907711670556013604839586446706324415722155397" ++
24 "53697817977846174064955149290862569321978468622482" ++
25 "83972241375657056057490261407972968652414535100474" ++
26 "82166370484403199890008895243450658541227588666881" ++
27 "16427171479924442928230863465674813919123162824586" ++
28 "17866458359124566529476545682848912883142607690042" ++
29 "24219022671055626321111109370544217506941658960408" ++
30 "07198403850962455444362981230987879927244284909188" ++
31 "84580156166097919133875499200524063689912560717606" ++
32 "05886116467109405077541002256983155200055935729725" ++
33 "71636269561882670428252483600823257530420752963450".
34
35 fivelets([A,B,C,D,E]) -> [[A,B,C,D,E]];
36 fivelets([A,B,C,D,E|Xs]) -> [[A,B,C,D,E]|fivelets([B,C,D,E|Xs])].
37
38 prod(List) -> lists:foldl(fun(X, Prod) -> (X-$0) * Prod end, 1, List).
39
8b7a0ff Introduced solve function to all modules
Andrey Paramonov authored
40 solve() -> lists:max(lists:map(fun prod/1, fivelets(number()))).
6241c3e Solved firest 10 problems
Andrey Paramonov authored
41
42
43 %% Tests
44
45 fivelets_test() ->
46 ?assertEqual(["12345", "23456"], fivelets("123456")).
47
48 prod_test() ->
49 ?assertEqual(120, prod("12345")).
Something went wrong with that request. Please try again.