From 780f6e573457e1e371b2e37a01b49ae60598d3fc Mon Sep 17 00:00:00 2001 From: Shanti Chellaram Date: Thu, 1 Dec 2022 20:46:17 +0900 Subject: [PATCH] Problem 1-1 --- problem1.erl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 problem1.erl 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])). + +