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