Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % This is true if the four-character sequence in Signal starting at MarkerPos could be a marker. Take the segment, turn it into a list, make it a set (removing duplicates), check that the length is 4.
- marker_at(Signal, MarkerPos) :- sub_atom(Signal, MarkerPos, 4, _, Segment), atom_chars(Segment, CharList), setof(X, member(X, CharList), UniqueList), length(UniqueList, 4).
- % Solve the puzzle. Iterate over the length of the signal, check if there could be a marker on that position. Then take the first item in the list because that is the first marker.
- solve(Signal, Counter) :- atom_length(Signal, SignalSize), MaxMarkerPos is SignalSize - 5, findall(X, (between(1, MaxMarkerPos, MarkerPos), marker_at(Signal, MarkerPos), X is MarkerPos + 4), CounterList), nth(1, CounterList, Counter).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement