merge hand1 and hand2
This commit is contained in:
parent
45a54fe520
commit
90c2a52251
1 changed files with 7 additions and 13 deletions
20
day2.m
20
day2.m
|
@ -28,15 +28,10 @@
|
||||||
:- mode parser(I) == (pred(out(I), in, out) is semidet).
|
:- mode parser(I) == (pred(out(I), in, out) is semidet).
|
||||||
:- mode parser == parser(ground).
|
:- mode parser == parser(ground).
|
||||||
|
|
||||||
:- pred hand1(move::out, chars::in, chars::out) is semidet.
|
:- pred hand(move::out, chars::in, chars::out) is semidet.
|
||||||
hand1(rock) --> ['A'].
|
hand(rock) --> ['A']; ['X'].
|
||||||
hand1(paper) --> ['B'].
|
hand(paper) --> ['B']; ['Y'].
|
||||||
hand1(scissors) --> ['C'].
|
hand(scissors) --> ['C']; ['Z'].
|
||||||
|
|
||||||
:- pred hand2(move::out, chars::in, chars::out) is semidet.
|
|
||||||
hand2(rock) --> ['X'].
|
|
||||||
hand2(paper) --> ['Y'].
|
|
||||||
hand2(scissors) --> ['Z'].
|
|
||||||
|
|
||||||
:- pred result(result::out, chars::in, chars::out) is semidet.
|
:- pred result(result::out, chars::in, chars::out) is semidet.
|
||||||
result(you) --> ['X'].
|
result(you) --> ['X'].
|
||||||
|
@ -44,15 +39,14 @@ result(draw) --> ['Y'].
|
||||||
result(me) --> ['Z'].
|
result(me) --> ['Z'].
|
||||||
|
|
||||||
:- pred two(parser(T)::parser, parser(U)::parser,
|
:- pred two(parser(T)::parser, parser(U)::parser,
|
||||||
T::out, U::out,
|
T::out, U::out, chars::in, chars::out) is semidet.
|
||||||
chars::in, chars::out) is semidet.
|
|
||||||
two(P, Q, A, B) --> P(A), [' '], Q(B).
|
two(P, Q, A, B) --> P(A), [' '], Q(B).
|
||||||
|
|
||||||
:- pred line1(moves::out, chars::in, chars::out) is semidet.
|
:- pred line1(moves::out, chars::in, chars::out) is semidet.
|
||||||
line1(A - B) --> two(hand1, hand2, A, B).
|
line1(A - B) --> two(hand, hand, A, B).
|
||||||
|
|
||||||
:- pred line2(move_res::out, chars::in, chars::out) is semidet.
|
:- pred line2(move_res::out, chars::in, chars::out) is semidet.
|
||||||
line2(A - B) --> two(hand1, result, A, B).
|
line2(A - B) --> two(hand, result, A, B).
|
||||||
|
|
||||||
|
|
||||||
:- pred parse_line(parser(T)::parser, string::in, T::out) is semidet.
|
:- pred parse_line(parser(T)::parser, string::in, T::out) is semidet.
|
||||||
|
|
Loading…
Reference in a new issue