You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
782 B
24 lines
782 B
-module(day4).
|
|
|
|
-export([solve/1]).
|
|
|
|
solve(InputData) ->
|
|
Lines = binary:split(InputData, <<$\n>>, [trim_all, global]),
|
|
{part1(Lines), none}.
|
|
|
|
part1([]) -> 0;
|
|
part1([Entry | Rest]) ->
|
|
Ranges = binary:split(Entry, <<",">>, [trim_all, global]),
|
|
[[F1, F2], [S1, S2]] = lists:map(fun(Range) -> binary:split(Range, <<"-">>, [trim_all, global]) end, Ranges),
|
|
First = {binary_to_integer(F1), binary_to_integer(F2)},
|
|
Second = {binary_to_integer(S1), binary_to_integer(S2)},
|
|
io:format("~n~p ~p", [First, Second]),
|
|
case range_intersect(First, Second) of
|
|
First -> 1;
|
|
Second -> 1;
|
|
_SomethingElse -> io:format(" out"), 0
|
|
end + part1(Rest).
|
|
|
|
range_empty() -> {0, -1}.
|
|
range_is_empty({Bottom, Top}) -> Top < Bottom.
|
|
range_intersect({B1, T1}, {B2, T2}) -> {max(B1, B2), min(T1, T2)}.
|