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.159 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.158 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.157 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.156 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.155 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.154 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.153 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.152 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.151 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.150 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.149 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.148 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.147 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.146 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.145 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.144 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.143 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.142 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.141 tracks/erlang/exercises/largest-series-product/src/example.erl
trackler-2.2.1.140 tracks/erlang/exercises/largest-series-product/src/example.erl