Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Amicable-pairs/Prolog/amicable-pairs-1.pro
Normal file
33
Task/Amicable-pairs/Prolog/amicable-pairs-1.pro
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
divisor(N, Divisor) :-
|
||||
UpperBound is round(sqrt(N)),
|
||||
between(1, UpperBound, D),
|
||||
0 is N mod D,
|
||||
(
|
||||
Divisor = D
|
||||
;
|
||||
LargerDivisor is N/D,
|
||||
LargerDivisor =\= D,
|
||||
Divisor = LargerDivisor
|
||||
).
|
||||
|
||||
proper_divisor(N, D) :-
|
||||
divisor(N, D),
|
||||
D =\= N.
|
||||
|
||||
assoc_num_divsSum_in_range(Low, High, Assoc) :-
|
||||
findall( Num-DivSum,
|
||||
( between(Low, High, Num),
|
||||
aggregate_all( sum(D),
|
||||
proper_divisor(Num, D),
|
||||
DivSum )),
|
||||
Pairs ),
|
||||
list_to_assoc(Pairs, Assoc).
|
||||
|
||||
get_amicable_pair(Assoc, M-N) :-
|
||||
gen_assoc(M, Assoc, N),
|
||||
M < N,
|
||||
get_assoc(N, Assoc, M).
|
||||
|
||||
amicable_pairs_under_20000(Pairs) :-
|
||||
assoc_num_divsSum_in_range(1,20000, Assoc),
|
||||
findall(P, get_amicable_pair(Assoc, P), Pairs).
|
||||
2
Task/Amicable-pairs/Prolog/amicable-pairs-2.pro
Normal file
2
Task/Amicable-pairs/Prolog/amicable-pairs-2.pro
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
?- amicable_pairs_under_20000(R).
|
||||
R = [220-284, 1184-1210, 2620-2924, 5020-5564, 6232-6368, 10744-10856, 12285-14595, 17296-18416].
|
||||
Loading…
Add table
Add a link
Reference in a new issue