summaryrefslogtreecommitdiff
path: root/aoc22/day6/solve.pl
diff options
context:
space:
mode:
Diffstat (limited to 'aoc22/day6/solve.pl')
-rw-r--r--aoc22/day6/solve.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/aoc22/day6/solve.pl b/aoc22/day6/solve.pl
new file mode 100644
index 0000000..8452fff
--- /dev/null
+++ b/aoc22/day6/solve.pl
@@ -0,0 +1,24 @@
+% vim: ft=prolog
+
+main(Filepath) :- read_file_to_string(Filepath, InputString, []),
+ atom_chars(InputString, Input),
+ p1(Input, Ans1),
+ writeln(Ans1),
+ % p2(Input, Ans2),
+ % writeln(Ans2),
+ !.
+
+% p1([A,B,C,D|_], 4) :- unique([A,B,C,D]).
+p1(XS, 4) :- take(XS, 4, YS), unique(YS).
+p1([_|T], L) :- p1(T, L1), L is L1+1.
+
+
+unique([H|T]) :- \+ member(H, T), unique(T).
+unique([]).
+
+p2(XS, 14) :- take(XS, 14, YS), unique(YS).
+p2([_|T], L) :- p2(T, L1), L is L1+1.
+
+% take(XS, N, YS) :- take(XS, N, [], YS).
+% take(_, 0, Acc, Acc).
+% take([X|XS], N, Acc, YS) :- N1 is N - 1, take(XS, N1, [X|Acc], YS).