You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
498 B
Plaintext
18 lines
498 B
Plaintext
10 years ago
|
partition([], _, [], []).
|
||
|
partition([X|Xs], Pivot, Smalls, Bigs) :-
|
||
|
( X @< Pivot ->
|
||
|
Smalls = [X|Rest],
|
||
|
partition(Xs, Pivot, Rest, Bigs)
|
||
|
; Bigs = [X|Rest],
|
||
|
partition(Xs, Pivot, Smalls, Rest)
|
||
|
).
|
||
|
|
||
|
quicksort([]) --> [].
|
||
|
quicksort([X|Xs]) -->
|
||
|
{ partition(Xs, X, Smaller, Bigger) },
|
||
|
quicksort(Smaller), [X], quicksort(Bigger).
|
||
|
|
||
|
perfect(N) :-
|
||
|
between(1, inf, N), U is N // 2,
|
||
|
findall(D, (between(1,U,D), N mod D =:= 0), Ds),
|
||
|
sumlist(Ds, N).
|