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.

14 lines
415 B

-module(day6).
-export([solve/1]).
solve(InputData) ->
{solve2(InputData, 4), solve2(InputData, 14)}.
solve2(Symbols, Target) -> solve2(Symbols, #{}, 0, 0, Target).
solve2(_Symbols, _State, Target, N, Target) -> N;
solve2(<<Symbol, Symbols/binary>>, LastSeen, ChainLength, N, Target) ->
Last = maps:get(Symbol, LastSeen, 0),
solve2(Symbols, LastSeen#{Symbol => N}, min(N-Last, ChainLength+1), N+1, Target).