Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Weird-numbers/Zkl/weird-numbers-1.zkl
Normal file
27
Task/Weird-numbers/Zkl/weird-numbers-1.zkl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
fcn properDivs(n){
|
||||
if(n==1) return(T);
|
||||
( pd:=[1..(n).toFloat().sqrt()].filter('wrap(x){ n%x==0 }) )
|
||||
.pump(pd,'wrap(pd){ if(pd!=1 and (y:=n/pd)!=pd ) y else Void.Skip })
|
||||
}
|
||||
fcn abundant(n,divs){ divs.sum(0) > n }
|
||||
fcn semiperfect(n,divs){
|
||||
if(divs){
|
||||
h,t := divs[0], divs[1,*];
|
||||
if(n<h) return(semiperfect(n,t));
|
||||
return((n==h) or semiperfect(n - h, t) or semiperfect(n, t));
|
||||
}
|
||||
False
|
||||
}
|
||||
fcn sieve(limit){
|
||||
// False denotes abundant and not semi-perfect.
|
||||
// Only interested in even numbers >= 2
|
||||
w:=List.createLong(limit,False);
|
||||
foreach i in ([2..limit - 1, 2]){
|
||||
if(w[i]) continue;
|
||||
divs:=properDivs(i);
|
||||
if(not abundant(i,divs)) w[i]=True;
|
||||
else if(semiperfect(i,divs))
|
||||
{ foreach j in ([i..limit - 1, i]){ w[j]=True; } }
|
||||
}
|
||||
w
|
||||
}
|
||||
7
Task/Weird-numbers/Zkl/weird-numbers-2.zkl
Normal file
7
Task/Weird-numbers/Zkl/weird-numbers-2.zkl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
w,count,max := sieve(17_000), 0, 25;
|
||||
println("The first 25 weird numbers are:");
|
||||
foreach n in ([2..* ,2]){
|
||||
if(not w[n]){ print("%d ".fmt(n)); count+=1; }
|
||||
if(count>=max) break;
|
||||
}
|
||||
println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue