Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Permutations/Logtalk/permutations-1.logtalk
Normal file
22
Task/Permutations/Logtalk/permutations-1.logtalk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
:- object(list).
|
||||
|
||||
:- public(permutation/2).
|
||||
|
||||
permutation(List, Permutation) :-
|
||||
same_length(List, Permutation),
|
||||
permutation2(List, Permutation).
|
||||
|
||||
permutation2([], []).
|
||||
permutation2(List, [Head| Tail]) :-
|
||||
select(Head, List, Remaining),
|
||||
permutation2(Remaining, Tail).
|
||||
|
||||
same_length([], []).
|
||||
same_length([_| Tail1], [_| Tail2]) :-
|
||||
same_length(Tail1, Tail2).
|
||||
|
||||
select(Head, [Head| Tail], Tail).
|
||||
select(Head, [Head2| Tail], [Head2| Tail2]) :-
|
||||
select(Head, Tail, Tail2).
|
||||
|
||||
:- end_object.
|
||||
9
Task/Permutations/Logtalk/permutations-2.logtalk
Normal file
9
Task/Permutations/Logtalk/permutations-2.logtalk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
| ?- forall(list::permutation([1, 2, 3], Permutation), (write(Permutation), nl)).
|
||||
|
||||
[1,2,3]
|
||||
[1,3,2]
|
||||
[2,1,3]
|
||||
[2,3,1]
|
||||
[3,1,2]
|
||||
[3,2,1]
|
||||
yes
|
||||
Loading…
Add table
Add a link
Reference in a new issue