Data update
This commit is contained in:
parent
72eb4943cb
commit
4d5544505c
2347 changed files with 62432 additions and 16731 deletions
|
|
@ -0,0 +1,43 @@
|
|||
begin
|
||||
|
||||
boolean procedure isprime(n);
|
||||
value n; integer n;
|
||||
begin
|
||||
if n < 2 then
|
||||
isprime := false
|
||||
else if n = entier(n / 2) * 2 then
|
||||
isprime := (n = 2)
|
||||
else
|
||||
begin
|
||||
comment - check odd divisors up to sqrt(n);
|
||||
integer i, limit;
|
||||
boolean divisible;
|
||||
i := 3;
|
||||
limit := entier(sqrt(n));
|
||||
divisible := false;
|
||||
for i := i while i <= limit and not divisible do
|
||||
begin
|
||||
if entier(n / i) * i = n then
|
||||
divisible := true;
|
||||
i := i + 2
|
||||
end;
|
||||
isprime := not divisible;
|
||||
end;
|
||||
end;
|
||||
|
||||
integer i, count;
|
||||
|
||||
count := 0;
|
||||
for i := 42, i + 1 while count < 26 do
|
||||
begin
|
||||
if isprime(i) then
|
||||
begin
|
||||
count := count + 1;
|
||||
outinteger(1,count);
|
||||
outinteger(1,i);
|
||||
i := i + (i - 1);
|
||||
outstring(1,"\n");
|
||||
end;
|
||||
end;
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import ballerina/io;
|
||||
|
||||
function isPrime(int n) returns boolean {
|
||||
if n < 2 { return false; }
|
||||
if n % 2 == 0 { return n == 2; }
|
||||
if n % 3 == 0 { return n == 3; }
|
||||
int d = 5;
|
||||
while d * d <= n {
|
||||
if n % d == 0 { return false; }
|
||||
d += 2;
|
||||
if n % d == 0 { return false; }
|
||||
d += 4;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function commatize(int n) returns string {
|
||||
string s = n.toString();
|
||||
if n < 0 { s = s.substring(1); }
|
||||
int le = s.length();
|
||||
foreach int i in int:range(le - 3, 0, -3) {
|
||||
s = s.substring(0, i) + "," + s.substring(i);
|
||||
}
|
||||
if n >= 0 { return s; }
|
||||
return "-" + s;
|
||||
}
|
||||
|
||||
public function main() {
|
||||
int c = 0;
|
||||
int i = 42;
|
||||
while c < 42 {
|
||||
if isPrime(i) {
|
||||
c += 1;
|
||||
io:println(commatize(c).padStart(2), ": ", commatize(i).padStart(18));
|
||||
i = 2 * i - 1;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
procedure main()
|
||||
I_START := 42
|
||||
LIMIT := I_START
|
||||
|
||||
i := I_START
|
||||
n := 0
|
||||
until n = LIMIT do {
|
||||
if is_prime(i) then {
|
||||
n +:= 1
|
||||
write(right(n,2),": ",comma_string(i))
|
||||
i +:= i
|
||||
} else
|
||||
i +:= 1
|
||||
}
|
||||
end
|
||||
|
||||
procedure is_prime(n)
|
||||
if n < 2 then fail
|
||||
if n%2 = 0 then return n = 2
|
||||
if n%3 = 0 then return n = 3
|
||||
d := 5
|
||||
while d*d <= n do {
|
||||
if n%d = 0 then fail
|
||||
d +:= 2
|
||||
if n%d = 0 then fail
|
||||
d +:= 4
|
||||
}
|
||||
return n
|
||||
end
|
||||
|
||||
procedure comma_string(n)
|
||||
s := ""
|
||||
n ? {
|
||||
tab(0)
|
||||
while s := "," || move(-3) || s
|
||||
if pos(1) then s := s[2:0]
|
||||
else s := tab(1) || s
|
||||
}
|
||||
return s
|
||||
end
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
$lines
|
||||
|
||||
$constant FALSE = 0
|
||||
$constant TRUE = 0FFFFH
|
||||
|
||||
rem - return n mod m
|
||||
function mod(n, m = integer) = integer
|
||||
end = n - m * (n / m)
|
||||
|
||||
rem - return true if n is prime, otherwise false
|
||||
function isprime(n = integer) = integer
|
||||
var i, limit, result = integer
|
||||
if n = 2 then
|
||||
result = TRUE
|
||||
else if (n < 2) or (mod(n,2) = 0) then
|
||||
result = FALSE
|
||||
else
|
||||
begin
|
||||
limit = int(sqr(n))
|
||||
i = 3
|
||||
while (i <= limit) and (mod(n, i) <> 0) do
|
||||
i = i + 2
|
||||
result = not (i <= limit)
|
||||
end
|
||||
end = result
|
||||
|
||||
var i, count = integer
|
||||
count = 0
|
||||
for i = 42 to 32760
|
||||
if isprime(i) then
|
||||
begin
|
||||
count = count + 1
|
||||
print using "## ##,###"; count; i
|
||||
if count >= 10 then
|
||||
i = 32760
|
||||
else
|
||||
i = i + (i - 1)
|
||||
end
|
||||
next i
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
program primes42;
|
||||
loop
|
||||
init n := 42; p := 0;
|
||||
step n +:= 1;
|
||||
until p = 42 do
|
||||
if prime(n) then
|
||||
print(lpad(str(p +:= 1), 2) + ": " + lpad(commatize(n), 20));
|
||||
n +:= n;
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
proc prime(n);
|
||||
if n<=4 then return n in [2,3]; end if;
|
||||
if n mod 2=0 or n mod 3=0 then return False; end if;
|
||||
loop init d := 5; while d*d <= n do
|
||||
if n mod d=0 then return false; end if;
|
||||
d +:= 2;
|
||||
if n mod d=0 then return false; end if;
|
||||
d +:= 4;
|
||||
end loop;
|
||||
return True;
|
||||
end proc;
|
||||
|
||||
proc commatize(n);
|
||||
if n<1000 then return str n; end if;
|
||||
p := "00" + str(n mod 1000);
|
||||
return commatize(n div 1000) + "," + p(#p-2..#p);
|
||||
end proc;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue