Skip to content

Commit 90ac7fd

Browse files
author
emiruz
committed
Day 09 (removing yall dependency: causes regression.)
1 parent 51422f9 commit 90ac7fd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

09.prolog

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
:- use_module(library(yall)).
2-
31
add_idx(Xs, Ys) :- findall(I-X, nth1(I, Xs, X), Ys).
42

53
expand(Xs0, Ys) :-
64
add_idx(Xs0, Xs),
75
maplist([I0-X,L]>>(I is mod(I0,2)*(1+I0//2), length(L,X), maplist(=(I),L)), Xs, Xs2),
86
flatten(Xs2, Xs3), maplist([A,B]>>(B is A-1), Xs3, Ys).
97

8+
f1(I-A,J-B,C) :- I<J->C=[J-A,I-B];C=[].
9+
f2(SwapDict, I-_) :- get_assoc(I, SwapDict, _).
10+
1011
insert(Xs, Empty, Full, N, Ys) :-
1112
length(EmptyTrim, N), length(FullTrim, N),
1213
append(EmptyTrim, _, Empty), append(FullTrim, _, Full),
13-
maplist([I-A,J-B,C]>>(I<J->C=[J-A,I-B];C=[]), EmptyTrim, FullTrim, Swap0),
14+
maplist(f1, EmptyTrim, FullTrim, Swap0),
1415
flatten(Swap0, Swap), list_to_assoc(Swap, SwapDict),
15-
exclude({SwapDict}/[I-_]>>(get_assoc(I, SwapDict, _)), Xs, Rem),
16+
exclude(f2(SwapDict), Xs, Rem),
1617
append(Rem, Swap, Final), sort(Final, Ys).
1718

1819
next_empty(_, N, Ys0, Ys) :- length(Ys0, N), reverse(Ys0, Ys), !.
@@ -37,7 +38,7 @@ solve(In, Part1, Part2) :-
3738
include([I-A]>>(A\=(-1)), ExpIdx, Full0), reverse(Full0, Full),
3839
length(Empty, N1), length(Full,N2), N is min(N1,N2),
3940
insert(ExpIdx, Empty, Full, N, Exp1),
40-
aggregate_all(sum(I*M), (nth0(I,Exp1,_-M), M \= -1), Part1),
41+
aggregate_all(sum(I2*M), (nth0(I2,Exp1,_-M), M \= -1), Part1),
4142
pairs_values(Full, Values0), sort(Values0,Values1), reverse(Values1,Values),
4243
insert2(Values, ExpIdx, Exp2),
4344
aggregate_all(sum(I*M), (nth0(I,Exp2,_-M), M \= -1), Part2).

0 commit comments

Comments
 (0)