use a record instead of a tuple
This commit is contained in:
parent
c7009a608e
commit
0ca15eb016
1 changed files with 8 additions and 8 deletions
16
day16.m
16
day16.m
|
@ -93,22 +93,22 @@ max_release(Time, Here, Graph, Rates, !Open, Max) :-
|
||||||
MaxHere = 0),
|
MaxHere = 0),
|
||||||
Nexts = [Here | set.to_sorted_list(lookup_from(Graph, Here))],
|
Nexts = [Here | set.to_sorted_list(lookup_from(Graph, Here))],
|
||||||
max_releases(Time - 1, Nexts, Graph, Rates, StartOpen, Outs),
|
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)).
|
:- pred max_releases(int, list(key), graph, rates, open, list(out)).
|
||||||
:- mode max_releases(in, in, in, in, in, out) is det.
|
:- mode max_releases(in, in, in, in, in, out) is det.
|
||||||
max_releases(_, [], _, _, _, []).
|
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_release(Time, Here, Graph, Rates, Open0, Open, Max) &
|
||||||
max_releases(Time, Theres, Graph, Rates, Open0, Rest).
|
max_releases(Time, Theres, Graph, Rates, Open0, Rest).
|
||||||
|
|
||||||
:- pred get_max(list(out)::in(non_empty_list), open::out, int::out) is det.
|
:- pred get_max(list(out)::in(non_empty_list), out::out) is det.
|
||||||
get_max([{O, M}], O, M).
|
get_max([O], O).
|
||||||
get_max([{O, M}, R | Rest], O0, M0) :-
|
get_max([O, R | Rest], O0) :-
|
||||||
get_max([R | Rest], OR, MR),
|
get_max([R | Rest], OR),
|
||||||
(if M >= MR then O0 = O, M0 = M else O0 = OR, M0 = MR).
|
(if O^max >= OR^max then O0 = O else O0 = OR).
|
||||||
|
|
||||||
run(one, Lines, int(Max)) :-
|
run(one, Lines, int(Max)) :-
|
||||||
if lines(Lines, G, R) then max_release(30, "AA", G, R, Max)
|
if lines(Lines, G, R) then max_release(30, "AA", G, R, Max)
|
||||||
|
|
Loading…
Reference in a new issue