Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -0,0 +1,32 @@
isPrime = function(n)
if n < 2 then return false
if n < 4 then return true
for i in range(2,floor(n ^ 0.5))
if n % i == 0 then return false
end for
return true
end function
countFactors = function(n)
cnt = 0
for i in range(2, n)
while n % i == 0
cnt += 1
n /= i
end while
end for
return cnt
end function
isAttractive = function(n)
if n < 1 then return false
factorCnt = countFactors(n)
return isPrime(factorCnt)
end function
numbers = []
for i in range(2, 120)
if isAttractive(i) then numbers.push(i)
end for
print numbers.join(", ")

View file

@ -0,0 +1,28 @@
program attractive_numbers;
numbers := [n in [2..120] | attractive(n)];
printtab(numbers, 20, 3);
proc printtab(list, cols, width);
lines := [list(k..cols+k-1) : k in [1, cols+1..#list]];
loop for line in lines do
print(+/[lpad(str item, width+1) : item in line]);
end loop;
end proc;
proc attractive(n);
return #factorize(#factorize(n)) = 1;
end proc;
proc factorize(n);
factors := [];
d := 2;
loop until d > n do
loop while n mod d = 0 do
factors with:= d;
n div:= d;
end loop;
d +:= 1;
end loop;
return factors;
end proc;
end program;

View file

@ -1,5 +1,5 @@
import "/fmt" for Fmt
import "/math" for Int
import "./fmt" for Fmt
import "./math" for Int
var max = 120
System.print("The attractive numbers up to and including %(max) are:")
@ -7,7 +7,7 @@ var count = 0
for (i in 1..max) {
var n = Int.primeFactors(i).count
if (Int.isPrime(n)) {
System.write(Fmt.d(4, i))
Fmt.write("$4d", i)
count = count + 1
if (count%20 == 0) System.print()
}