Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
32
Task/Attractive-numbers/MiniScript/attractive-numbers.mini
Normal file
32
Task/Attractive-numbers/MiniScript/attractive-numbers.mini
Normal 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(", ")
|
||||
28
Task/Attractive-numbers/SETL/attractive-numbers.setl
Normal file
28
Task/Attractive-numbers/SETL/attractive-numbers.setl
Normal 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;
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue