Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/ABC-problem/Mercury/abc-problem.mercury
Normal file
34
Task/ABC-problem/Mercury/abc-problem.mercury
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
:- module abc.
|
||||
:- interface.
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
:- implementation.
|
||||
:- import_module list, string, char.
|
||||
|
||||
:- type block == {char, char}.
|
||||
|
||||
:- pred take(char, list(block), list(block)).
|
||||
:- mode take(in, in, out) is nondet.
|
||||
take(C, !Blocks) :-
|
||||
list.delete(!.Blocks, {A, B}, !:Blocks),
|
||||
( A = C ; B = C ).
|
||||
|
||||
:- pred can_make_word(list(char)::in, list(block)::in) is semidet.
|
||||
can_make_word([], _).
|
||||
can_make_word([C|Cs], !.Blocks) :-
|
||||
take(C, !Blocks),
|
||||
can_make_word(Cs, !.Blocks).
|
||||
|
||||
main(!IO) :-
|
||||
Blocks = [
|
||||
{'B', 'O'}, {'X', 'K'}, {'D', 'Q'}, {'C', 'P'}, {'N', 'A'},
|
||||
{'G', 'T'}, {'R', 'E'}, {'T', 'G'}, {'Q', 'D'}, {'F', 'S'},
|
||||
{'J', 'W'}, {'H', 'U'}, {'V', 'I'}, {'A', 'N'}, {'O', 'B'},
|
||||
{'E', 'R'}, {'F', 'S'}, {'L', 'Y'}, {'P', 'C'}, {'Z', 'M'}
|
||||
],
|
||||
Words = ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE"],
|
||||
foldl((pred(W::in, !.IO::di, !:IO::uo) is det :-
|
||||
P = can_make_word(to_char_list(W), Blocks),
|
||||
io.format("can_make_word(""%s"") :- %s.\n",
|
||||
[s(W), s(if P then "true" else "fail")], !IO)),
|
||||
Words, !IO).
|
||||
Loading…
Add table
Add a link
Reference in a new issue