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.139 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.138 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.137 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.136 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.135 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.134 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.133 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.132 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.131 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.130 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.129 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.128 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.127 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.126 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.125 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.124 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.123 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.122 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.121 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.120 tracks/erlang/exercises/largest-series-product/src/example.erl