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.

15 lines
643 B

-module(day6).
-export([solve/1]).
solve(InputData) ->
{solve(InputData, 1), none}.
solve(<<A, A, Rest/binary>>, N) -> solve(<<A, Rest/binary>>, N+1);
solve(<<A, B, A, Rest/binary>>, N) -> solve(<<B, A, Rest/binary>>, N+1);
solve(<<A, B, C, A, Rest/binary>>, N) -> solve(<<B, C, A, Rest/binary>>, N+1);
solve(<<A, B, B, Rest/binary>>, N) -> solve(<<B, Rest/binary>>, N+2);
solve(<<A, B, C, C, Rest/binary>>, N) -> solve(<<C, Rest/binary>>, N+3);
solve(<<A, B, C, D, _Rest/binary>>, N) when A /= B andalso B /= C andalso C /= D andalso
A /= C andalso B /= D andalso A /= D -> N+3;
solve(<<_, Rest/binary>>, N) -> solve(Rest, N+1).