commit 780f6e573457e1e371b2e37a01b49ae60598d3fc Author: Shanti Chellaram Date: Thu Dec 1 20:46:17 2022 +0900 Problem 1-1 diff --git a/problem1.erl b/problem1.erl new file mode 100644 index 0000000..0368946 --- /dev/null +++ b/problem1.erl @@ -0,0 +1,16 @@ +-module(foo). + +-export([main/1]). + +main(Args) -> + [Filename] = Args, + {ok, Filedata} = file:read_file(Filename), + Elves = binary:split(Filedata, <<"\n\n">>, [global, trim_all]), + Loads = lists:map(fun elf_load/1, Elves), + {lists:max(Loads), ok}. + +elf_load([]) -> 0; +elf_load([Load | Rest]) -> binary_to_integer(Load) + elf_load(Rest); +elf_load(LoadString) when is_binary(LoadString) -> elf_load(binary:split(LoadString, <<$\n>>, [global, trim_all])). + +