Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Amb/Picat/amb.picat
Normal file
38
Task/Amb/Picat/amb.picat
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
go ?=>
|
||||
% select which version of amb/2 and joins/2 to test
|
||||
member(Amb,[amb,amb2]),
|
||||
member(Joins,[joins,join2]),
|
||||
println([amb=Amb,joins=Joins]),
|
||||
test_amb(amb,joins, Word1,Word2,Word3,Word4),
|
||||
println([Word1, Word2, Word3, Word4]),
|
||||
nl,
|
||||
fail, % get other solutions
|
||||
nl.
|
||||
go => true.
|
||||
|
||||
% Test a combination of amb and joins
|
||||
test_amb(Amb,Joins, Word1,Word2,Word3,Word4) =>
|
||||
call(Amb, Word1, ["the","that","a"]),
|
||||
call(Amb, Word2, ["frog","elephant","thing"]),
|
||||
call(Amb, Word3, ["walked","treaded","grows"]),
|
||||
call(Amb, Word4, ["slowly","quickly"]),
|
||||
call(Joins, Word1, Word2),
|
||||
call(Joins, Word2, Word3),
|
||||
call(Joins, Word3, Word4).
|
||||
|
||||
% Based on the Prolog solution.
|
||||
amb(E, [E|_]).
|
||||
amb(E, [_|ES]) :- amb(E, ES).
|
||||
|
||||
joins(Left, Right) =>
|
||||
append(_, [T], Left),
|
||||
append([R], _, Right),
|
||||
( T != R -> amb(_, [])
|
||||
; true ).
|
||||
|
||||
% Another approach, using member/2 for
|
||||
% generating the words.
|
||||
amb2([],[]).
|
||||
amb2(Word,Words) :- member(Word,Words).
|
||||
|
||||
joins2(Word1,Word2) :- Word1.last() = Word2.first().
|
||||
Loading…
Add table
Add a link
Reference in a new issue