Sha256: 41701129c2c81ce3ba7453ede2a72b351051fa97fc466d87aadcdfa31421ef57

Contents?: true

Size: 724 Bytes

Versions: 310

Compression:

Stored size: 724 Bytes

Contents

-module(example).

-export([lsp/2, test_version/0]).

-define(is_digit(C), ((C >= $0) and (C =< $9))).

lsp(_String, N) when N < 0 -> error;
lsp(String, N) -> lsp(erlang:length(String), String, N).

test_version() ->
    1.


lsp(Length, _String, N) when Length < N -> error;
lsp(Length, String, N) ->
  Sets = sets(Length, N, String),
  lists:max([product(X) || X <- Sets]).

product(Set) -> lists:foldl(fun product/2, 1, Set).

product(_C, error) -> error;
product(C, _Acc) when not ?is_digit(C) -> error;
product(C, Acc) -> (C - $0) * Acc.

sets(Length, Width, [_ | T] = String) when Length > Width ->
  Set = lists:sublist(String, Width),
  [Set | sets(Length - 1, Width, T)];
sets(_Length, _Width, String) -> [String].

Version data entries

310 entries across 310 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.179 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.178 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.177 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.176 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.175 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.174 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.173 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.172 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.171 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.170 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.169 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.167 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.166 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.165 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.164 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.163 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.162 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.161 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.160 tracks/erlang/exercises/largest-series-product/src/example.erl