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,68 @@
with Ada.Text_IO;
with Ada.Containers.Ordered_Sets;
procedure Yellowstone_Sequence is
generic -- Allow more than one generator, but must be instantiated
package Yellowstones is
function Next return Integer;
function GCD (Left, Right : Integer) return Integer;
end Yellowstones;
package body Yellowstones
is
package Sequences is
new Ada.Containers.Ordered_Sets (Integer);
-- Internal package state
N_0 : Integer := 0;
N_1 : Integer := 0;
N_2 : Integer := 0;
Seq : Sequences.Set;
Min : Integer := 1;
function GCD (Left, Right : Integer) return Integer
is (if Right = 0
then Left
else GCD (Right, Left mod Right));
function Next return Integer is
begin
N_2 := N_1;
N_1 := N_0;
if N_0 < 3 then
N_0 := N_0 + 1;
else
N_0 := Min;
while
not (not Seq.Contains (N_0)
and then GCD (N_1, N_0) = 1
and then GCD (N_2, N_0) > 1)
loop
N_0 := N_0 + 1;
end loop;
end if;
Seq.Insert (N_0);
while Seq.Contains (Min) loop
Seq.Delete (Min);
Min := Min + 1;
end loop;
return N_0;
end Next;
end Yellowstones;
procedure First_30 is
package Yellowstone is new Yellowstones; -- New generator instance
use Ada.Text_IO;
begin
Put_Line ("First 30 Yellowstone numbers:");
for A in 1 .. 30 loop
Put (Yellowstone.Next'Image); Put (" ");
end loop;
New_Line;
end First_30;
begin
First_30;
end Yellowstone_Sequence;

View file

@ -0,0 +1,32 @@
def yellowstone
used = Set(Int32).new
penult, last = 2, 3
start = 4
iter = Iterator.of do
while start.in? used
used.delete start
start += 1
end
(start..).each do |n|
if !used.includes?(n) && n.gcd(last) == 1 && n.gcd(penult) > 1
used << n
penult, last = last, n
break n
end
end
end
(1..3).each.chain iter
end
p yellowstone.first(30).to_a
values = yellowstone.first(100).to_a
height = (values.max - 1) // 8
(0..height).reverse_each do |i|
values.each do |v|
d = v - i*8
print d <= 0 ? ' ' : d >= 8 ? '█' : '\u2580' + d
end
puts
end

View file

@ -0,0 +1,85 @@
! Yellowstone Sequence - Code Golf Version
! Demonstrates concise Fortran (but keep it readable!)
program yellowstone_golf
implicit none
integer :: y(100), i, c
logical :: u(1000) = .false.
! First 3 terms
y(1:3) = [(i, i=1,3)]
u(1:3) = .true.
! Generate rest
do i = 4, 100
c = 1
do while (u(c) .or. gcd(c,y(i-1))/=1 .or. gcd(c,y(i-2))==1)
c = c + 1
end do
y(i) = c
u(c) = .true.
end do
! Output
print '(A)', "First 30 Yellowstone numbers:"
print '(10I5)', y(1:30)
contains
! pure integer function gcd(a,b) !Euclid's method
! integer, intent(in) :: a, b
! integer :: x, y, t
! x = a; y = b
! do while (y /= 0)
! t = y; y = mod(x,y); x = t
! end do
! gcd = x
! end function
pure integer function gcd(a, b) !Stein's method
! Added and used Steins method of finding the GCD
! simply because everyone else was using Euclid's method
integer, intent(in) :: a, b
integer :: x, y, shift
x = abs(a)
y = abs(b)
! Handle trivial cases
if (a == 0) then
gcd = y
return
else if (b == 0) then
gcd = x
return
end if
! Count common factors of 2
shift = 0
do while ((iand(x,1) == 0) .and. (iand(y,1) == 0))
x = ishft(x,-1)
y = ishft(y,-1)
shift = shift + 1
end do
! Divide x by 2 until odd
do while (iand(x,1) == 0)
x = ishft(x,-1)
end do
do ! Divide y by 2 until odd
do while (iand(y,1) == 0)
y = ishft(y,-1)
end do
! Ensure x <= y
if (x > y) then
! swap
x = x + y
y = x - y
x = x - y
end if
y = y - x
if (y == 0) exit
end do
gcd = ishft(x, shift)
end function gcd
end program yellowstone_golf

View file

@ -0,0 +1,63 @@
MODULE YellowstoneSequence; (* Show some of the Yellowstone sequence *)
(* - translation of the Pluto sample via Agena *)
IMPORT Out;
(* returns the gcd of a and b *)
PROCEDURE gcd( a, b : INTEGER ) : INTEGER;
VAR t, m, n : INTEGER;
BEGIN
m := a;
n := b;
WHILE m # 0 DO t := m; m := n MOD m; n := t END
RETURN n
END gcd ;
(* sets a to the first elements of the Yellowstone sequence; *)
(* a must have at least 4 elements *)
(* element 0 of a is not used; i.e., a is indexed from 1 *)
(* the required size of the work array m will depend on the size of a *)
(* experimentation suggests that for sizes of a up to 100 000, *)
(* 10 * the size of a should be OK - it would probably be OK for *)
(* 1 000 000 but it will take a long time to construct a 1 000 000 *)
(* element sequence so I haven't tried it... *)
PROCEDURE yellowstone( VAR a : ARRAY OF INTEGER; VAR m : ARRAY OF BOOLEAN );
VAR n, minV, c, i : INTEGER;
more : BOOLEAN;
BEGIN
n := LEN( a ) - 1;
FOR i := 1 TO 3 DO a[ i ] := i; m[ i ] := TRUE END;
FOR i := 4 TO n DO a[ i ] := 0 END;
FOR i := 4 TO LEN( m ) - 1 DO m[ i ] := FALSE END;
minV := 4;
FOR c := 4 TO n DO
more := TRUE;
i := minV - 1;
WHILE more DO
INC( i );
IF ( ~ m[ i ] ) & ( gcd( a[ c - 1 ], i ) = 1 ) & ( gcd( a[ c - 2 ], i ) > 1 ) THEN
a[ c ] := i; m[ i ] := TRUE;
IF i = minV THEN INC( minV ) END;
more := FALSE
END
END
END
END yellowstone;
(* show the first 30 elements of the sequence *)
PROCEDURE task;
CONST ySize = 30;
VAR y : ARRAY ySize + 2 OF INTEGER;
w : ARRAY ySize * 10 OF BOOLEAN;
yPos : INTEGER;
BEGIN
yellowstone( y, w );
Out.String( "The first ");Out.Int( ySize, 0 );Out.String( " Yellowstone numbers are:" );Out.Ln;
FOR yPos := 1 TO ySize DO
Out.String( " " );Out.Int( y[ yPos ], 0 )
END;
Out.Ln
END task;
BEGIN
task
END YellowstoneSequence.

View file

@ -1,6 +1,8 @@
Gcd ← ⊙◌⍢(⟜◿:|±,)
NextY ← ⍢(+1|⟨¬≍0_1≡(=1Gcd)⊙(↙¯2)|1⟩∊,,)1 # [a0 a1...an] -> an+1
N ← 200
⍢(⊂:NextY|<N⧻)[1 2 3]
⟜(↙30) # First 30
Gcd ← ⊙◌⍢(˜⟜◿|⊃⋅±⊙∘)
# Experimental!
Gcd ←
NextY ← ⍢(+1|⨬(¬≍0_1=1≡Gcd⊙↙₋₂|1)˜∊⊃⊙∘⊙∘)1 # [a0 a1...an] -> an+1
N ← 200
⍢(˜⊂NextY|<N⧻)[1 2 3]
⟜↙₃₀ # First 30
▽⟜≡▽2⊞= ⇌⇡N # Plot 200