use a record instead of a tuple

This commit is contained in:
rhiannon morris 2022-12-16 18:27:04 +01:00
parent c7009a608e
commit 0ca15eb016

16
day16.m
View file

@ -93,22 +93,22 @@ max_release(Time, Here, Graph, Rates, !Open, Max) :-
MaxHere = 0),
Nexts = [Here | set.to_sorted_list(lookup_from(Graph, Here))],
max_releases(Time - 1, Nexts, Graph, Rates, StartOpen, Outs),
get_max([{!.Open, MaxHere} | Outs], !:Open, Max).
get_max([o(!.Open, MaxHere) | Outs], o(!:Open, Max)).
:- type out == {open, int}.
:- type out ---> o(open :: open, max :: int).
:- pred max_releases(int, list(key), graph, rates, open, list(out)).
:- mode max_releases(in, in, in, in, in, out) is det.
max_releases(_, [], _, _, _, []).
max_releases(Time, [Here|Theres], Graph, Rates, Open0, [{Open, Max} | Rest]) :-
max_releases(Time, [Here|Theres], Graph, Rates, Open0, [o(Open, Max) | Rest]) :-
max_release(Time, Here, Graph, Rates, Open0, Open, Max) &
max_releases(Time, Theres, Graph, Rates, Open0, Rest).
:- pred get_max(list(out)::in(non_empty_list), open::out, int::out) is det.
get_max([{O, M}], O, M).
get_max([{O, M}, R | Rest], O0, M0) :-
get_max([R | Rest], OR, MR),
(if M >= MR then O0 = O, M0 = M else O0 = OR, M0 = MR).
:- pred get_max(list(out)::in(non_empty_list), out::out) is det.
get_max([O], O).
get_max([O, R | Rest], O0) :-
get_max([R | Rest], OR),
(if O^max >= OR^max then O0 = O else O0 = OR).
run(one, Lines, int(Max)) :-
if lines(Lines, G, R) then max_release(30, "AA", G, R, Max)