Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
48
Task/Proper-divisors/Prolog/proper-divisors-1.pro
Normal file
48
Task/Proper-divisors/Prolog/proper-divisors-1.pro
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
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.
|
||||
|
||||
|
||||
%% Task 1
|
||||
%
|
||||
|
||||
proper_divisors(N, Ds) :-
|
||||
setof(D, proper_divisor(N, D), Ds).
|
||||
|
||||
|
||||
%% Task 2
|
||||
%
|
||||
|
||||
show_proper_divisors_of_range(Low, High) :-
|
||||
findall( N:Ds,
|
||||
( between(Low, High, N),
|
||||
proper_divisors(N, Ds) ),
|
||||
Results ),
|
||||
maplist(writeln, Results).
|
||||
|
||||
|
||||
%% Task 3
|
||||
%
|
||||
|
||||
proper_divisor_count(N, Count) :-
|
||||
proper_divisors(N, Ds),
|
||||
length(Ds, Count).
|
||||
|
||||
find_most_proper_divisors_in_range(Low, High, Result) :-
|
||||
aggregate_all( max(Count, N),
|
||||
( between(Low, High, N),
|
||||
proper_divisor_count(N, Count) ),
|
||||
max(MaxCount, Num) ),
|
||||
Result = (num(Num)-divisor_count(MaxCount)).
|
||||
14
Task/Proper-divisors/Prolog/proper-divisors-2.pro
Normal file
14
Task/Proper-divisors/Prolog/proper-divisors-2.pro
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
?- show_proper_divisors_of_range(1,10).
|
||||
2:[1]
|
||||
3:[1]
|
||||
4:[1,2]
|
||||
5:[1]
|
||||
6:[1,2,3]
|
||||
7:[1]
|
||||
8:[1,2,4]
|
||||
9:[1,3]
|
||||
10:[1,2,5]
|
||||
true.
|
||||
|
||||
?- find_most_proper_divisors_in_range(1,20000,Result).
|
||||
Result = num(15120)-divisor_count(79).
|
||||
Loading…
Add table
Add a link
Reference in a new issue