Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,51 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Text_IO.Editing; use Ada.Text_IO.Editing;
with Ada.Numerics.Generic_Elementary_Functions;
procedure Main is
type nums is delta 0.1 digits 15;
format : String := "zz_zzz_zzz_zzz_zzz_zz9.9";
pic : picture := To_Picture (format);
package Nums_io is new Decimal_Output (Nums);
use Nums_IO;
type U_64 is mod 2**64;
package mod_io is new Modular_IO (U_64);
use mod_io;
function Is_Prime (Num : U_64) return boolean is
package Flt_Funcs is new Ada.Numerics.Generic_Elementary_Functions
(Float);
use Flt_Funcs;
T : U_64 := 2;
Limit : constant U_64 := U_64 (Sqrt (Float (Num)));
begin
if Num = 2 then
return True;
end if;
while T <= Limit loop
if Num mod T = 0 then
return False;
end if;
T := T + (if T > 2 then 2 else 1);
end loop;
return True;
end Is_Prime;
Prime_Count : natural := 0;
Prime_Test : U_64 := 42;
begin
loop
if Is_Prime (Prime_Test) then
Prime_Count := Prime_Count + 1;
Put ("n =");
Put (Item => Prime_Count, Width => 3);
Put (Item => Nums (Prime_Test), Pic => pic);
New_Line;
Prime_Test := (Prime_Test * 2) - 1;
end if;
Prime_Test := Prime_Test + 1;
exit when Prime_Count = 42;
end loop;
end Main;

View file

@ -1,19 +1,19 @@
int LIMIT = 42
fun isPrime = logic by int n
if n % 2 == 0 do return n == 2 end
if n % 3 == 0 do return n == 3 end
int d = 5
while d * d <= n
if n % d == 0 do return false end
d += 2
if n % d == 0 do return false end
d += 4
int LIMIT 42
fun isPrime logic by int n
if n % 2 æ 0 do return n æ 2 end
if n % 3 æ 0 do return n æ 3 end
int d 5
while d * d n
if n % d æ 0 do return false end
d + 2
if n % d æ 0 do return false end
d + 4
end
return true
end
for int i = LIMIT, int n = 0; n < LIMIT; ++i
for int i ← LIMIT, int n ← 0; n < LIMIT; ++i
if not isPrime(i) do continue end
++n
writeLine("n = " + n + ",\ti = " + i)
i += i - 1
writeLine("n ← " + n + ",\ti ← " + i)
i + i - 1
end

View file

@ -1,22 +1,20 @@
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
if num mod i = 0 : return 0
i += 1
.
return 1
.
counter = 0
maxnum = pow 2 53
for i = 42 to maxnum
for i = 42 to pow 2 53
if isprim i = 1
counter += 1
print "n=" & counter & " " & i
if counter >= 42
break 1
cnt += 1
if cnt <= 5 or cnt >= 38
print "n=" & cnt & " " & i
elif cnt mod 15 = 0
print "."
.
if cnt >= 42 : break 1
i += i - 1
.
.

View file

@ -0,0 +1,37 @@
using StringTools;
import haxe.Int64;
class PrimeNumberLoops {
private static var limit = 42;
static function isPrime(i:Int64):Bool {
if (i == 2 || i == 3) {
return true;
} else if (i % 2 == 0 || i % 3 ==0) {
return false;
}
var idx:haxe.Int64 = 5;
while (idx * idx <= i) {
if (i % idx == 0) return false;
idx += 2;
if (i % idx == 0) return false;
idx += 4;
}
return true;
}
static function main() {
var i:Int64 = 42;
var n:Int64 = 0;
while (n < limit) {
if (isPrime(i)) {
n++;
Sys.println('n ${Int64.toStr(n).lpad(' ', 2)} ' +
'= ${Int64.toStr(i).lpad(' ', 19)}');
i += i;
continue;
}
i++;
}
}
}

View file

@ -0,0 +1,10 @@
def isPrime(long x) {
x.sqrt().map{it+2}.noneMatch{ x % it == 0 }
}
for (long i = 42, count = 0; count < 42; i++) {
isPrime(i) or continue
count++
println "Prime $count is $i"
i += i - 1
}

View file

@ -0,0 +1,42 @@
Prime 1 is 43
Prime 2 is 89
Prime 3 is 179
Prime 4 is 359
Prime 5 is 719
Prime 6 is 1439
Prime 7 is 2879
Prime 8 is 5779
Prime 9 is 11579
Prime 10 is 23159
Prime 11 is 46327
Prime 12 is 92657
Prime 13 is 185323
Prime 14 is 370661
Prime 15 is 741337
Prime 16 is 1482707
Prime 17 is 2965421
Prime 18 is 5930887
Prime 19 is 11861791
Prime 20 is 23723597
Prime 21 is 47447201
Prime 22 is 94894427
Prime 23 is 189788857
Prime 24 is 379577741
Prime 25 is 759155483
Prime 26 is 1518310967
Prime 27 is 3036621941
Prime 28 is 6073243889
Prime 29 is 12146487779
Prime 30 is 24292975649
Prime 31 is 48585951311
Prime 32 is 97171902629
Prime 33 is 194343805267
Prime 34 is 388687610539
Prime 35 is 777375221081
Prime 36 is 1554750442183
Prime 37 is 3109500884389
Prime 38 is 6219001768781
Prime 39 is 12438003537571
Prime 40 is 24876007075181
Prime 41 is 49752014150467
Prime 42 is 99504028301131

View file

@ -0,0 +1,50 @@
Rebol [
title: "Rosetta code: Increment loop index within loop body"
file: %Increment_loop_index_within_loop_body.r3
url: https://rosettacode.org/wiki/Increment_loop_index_within_loop_body
needs: 3.0.0
]
;; prime? native function is available since 3.19.5
if unset? 'prime? [
;; Naive Rebol implementation
prime?: function [n [integer!]] [
if n < 2 [return false]
if zero? n % 2 [return n == 2]
if zero? n % 3 [return n == 3]
d: 5
while [d * d <= n][
if zero? n % d [return false]
d: d + 2
if zero? n % d [return false]
d: d + 4
]
true
]
]
;; Helper to format number with commas
format-commas: function [num [integer!]] [
str: reverse form num
while [not tail? str: skip str 3][
str: insert str ","
]
reverse head str
]
;; Main logic
index: 42 ;; start index at 42 (before first increment)
count-primes: 0 ;; count of primes found
while [count-primes < 42] [
index: index + 1 ;; increment index by 1 at iteration start
if prime? index [
count-primes: count-primes + 1
print rejoin [
pad count-primes -2
": prime = "
pad format-commas index -18
]
;; increment index by the prime itself (old index + prime)
index: index + index
] ()
]