Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,62 @@
pragma Ada_2022;
with Ada.Text_IO;
with Ada.Containers.Vectors;
with Fifo;
procedure Ascending_Primes is
subtype Prime is Positive range 2 .. Positive'Last with
Dynamic_Predicate =>
(for all I in 2 .. (Prime / 2) => (Prime mod I) /= 0);
package Prime_Vectors is new
Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Prime);
package Positive_Fifo is new Fifo (Positive);
use Positive_Fifo;
-- Helper queue and vector for primes found
Queue : Fifo_Type;
Primes : Prime_Vectors.Vector;
begin
-- Initialise the queue with the first nine numbers
for Index in 1 .. 9 loop
Queue.Push (Index);
end loop;
-- Read the canditate numbers from the queue
-- check if they are prime and generate
-- the next possible candidates from them
while not Queue.Is_Empty loop
declare
Candidate : Positive;
Next_Digit : Positive;
begin
Queue.Pop (Candidate);
if Candidate in Prime then
Primes.Append (Candidate);
end if;
-- Generate the next possible candidates
-- from the current one
Next_Digit := Candidate mod 10 + 1;
while Next_Digit <= 9 loop
Queue.Push (Candidate * 10 + Next_Digit);
Next_Digit := @ + 1;
end loop;
end;
end loop;
-- Print the final list of prime numbers
for P of Primes loop
Ada.Text_IO.Put (P'Image);
end loop;
Ada.Text_IO.New_Line;
end Ascending_Primes;

View file

@ -0,0 +1,2 @@
/◇⊂{⍥(/◇⊂≡(□+×10:↘+1◿10,⇡10).)8 +1⇡9} # Build ascending numbers.
⊏⊸⍏▽⊸≡(=1⧻°/×) # Find primes and sort.