Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,51 +0,0 @@
|
|||
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;
|
||||
|
|
@ -2,12 +2,11 @@ i: 42
|
|||
n: 0
|
||||
|
||||
while [n<42][
|
||||
if? prime? i [
|
||||
n: n+1
|
||||
print ["n =" pad to :string n 2 pad to :string i 20]
|
||||
i: i + i
|
||||
]
|
||||
else [
|
||||
i: i + 1
|
||||
]
|
||||
switch prime? i [
|
||||
n: n+1
|
||||
print ["n =" pad to :string n 2 pad to :string i 20]
|
||||
i: i + i
|
||||
][
|
||||
i: i + 1
|
||||
]
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
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
|
||||
] ()
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue