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,33 @@
with Ada.Text_IO; use Ada.Text_IO;
with Unbounded_Unsigneds; use Unbounded_Unsigneds;
with Unbounded_Unsigneds.Primes; use Unbounded_Unsigneds.Primes;
with Strings_Edit.Integers; use Strings_Edit.Integers;
procedure Descending_Primes is
use Strings_Edit;
Line : String (1..90);
Pointer : Integer := 1;
procedure Check (Value, Digit : Half_Word; Length : Natural) is
This : constant Half_Word := Value * 10;
begin
if Length = 0 then
if Value > 1 and then Is_Prime (Value) = Prime then
Put (Line, Pointer, Integer (Value), 10, False, 9, Right);
if Pointer > 80 then
Put_Line (Line (1..Pointer - 1));
Pointer := 1;
end if;
end if;
else
for Next in 1..Digit - 1 loop
Check (This + Next, Next, Length - 1);
end loop;
end if;
end Check;
begin
for Length in 1..9 loop
Check (0, 10, Length);
end loop;
Put_Line (Line (1..Pointer - 1));
end Descending_Primes;

View file

@ -0,0 +1,20 @@
scope # generate primes with strictly descending digits
local proc ascending_primes()
local constant digits, candidates, primes := seq( 9, 8, 7, 6, 5, 4, 3, 2, 1 ), seq( 0 ), [];
for i to size digits do
for j to size candidates do
local constant value := candidates[ j ] * 10 + digits[ i ];
if numtheory.isprime( value ) then primes[ size primes + 1 ] := value fi
candidates[ size candidates + 1 ] := value
od
od;
sort( primes )
return primes
end;
for n, v in ipairs( ascending_primes() ) do
printf( "%10d" & if n mod 10 = 0 then "\n" else "" fi, v )
od
epocs

View file

@ -0,0 +1,33 @@
(do ;;; generate primes with strictly descending digits
(fn is-prime [p]
(if (or (<= p 1) (= 0 (% p 2)))
(= p 2)
;else
(do (var (prime i root-p) (values true 3 (math.floor (math.sqrt p))))
(while (and (<= i root-p) prime)
(set (prime i) (values (not= 0 (% p i)) (+ i 1)))
)
prime
)
)
)
(fn ascending-primes []
(local (digits candidates primes) (values [ 9 8 7 6 5 4 3 2 1 ] [ 0 ] []))
(for [i 1 (length digits)]
(for [j 1 (length candidates)]
(local value (+ (* 10 (. candidates j)) (. digits i)))
(when (is-prime value) (tset primes (+ 1 (length primes)) value))
(tset candidates (+ 1 (length candidates)) value)
)
)
(table.sort primes)
primes
)
(each [n v (ipairs (ascending-primes))]
(io.write (string.format (.. "%10d" (if (= 0 (% n 10)) "\n" "")) v))
)
)

View file

@ -0,0 +1,18 @@
import Data.List (sort, subsequences)
isPrime :: Integer -> Bool
isPrime n
| n < 2 = False
| n == 2 = True
| otherwise = 0 == length [i | i <- [2..floor(sqrt (fromIntegral n))], n `mod` i == 0]
isDescending :: [Integer] -> Bool
isDescending [] = True
isDescending [x] = True
isDescending (x:xs) = (if x <= (head xs) then False else isDescending xs)
getInt :: [Integer] -> Integer
getInt = foldl (\acc x -> acc * 10 + x) 0
descendingInts = sort [getInt xs | xs <- subsequences([9,8..1]), 0 < length xs, isDescending xs]
main = print [n | n <- descendingInts, isPrime n]

View file

@ -0,0 +1,22 @@
link factors
procedure main(A)
every writes(" ",descprimes())
write()
end
# Blatantly stolen from Lua example..
procedure descprimes()
primes := []
digits := [: 9 to 1 by -1 :]
candidates := [0]
every i := 1 to *digits do
every j := 1 to *candidates do {
value := 10*candidates[j] + digits[i]
put(primes, (isprime(value),value))
put(candidates, value)
}
suspend !sort(primes)
end

View file

@ -0,0 +1,4 @@
isprime: {(x>1)&&/(`pri 1+_%x)!'x}
nums: (10/|1+&|2\)'!512
primes: {x@<x} nums@&isprime'nums

View file

@ -1,16 +1,14 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">descending_primes</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">max_digit</span><span style="color: #0000FF;">=</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">max_digit</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">np</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span><span style="color: #0000FF;">+</span><span style="color: #000000;">d</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">odd</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #000000;">np</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">np</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">descending_primes</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">np</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
with javascript_semantics
function descending_primes(sequence res, atom p=0, max_digit=9)
for d=1 to max_digit do
atom np = p*10+d
if odd(d) and is_prime(np) then res &= np end if
res = descending_primes(res,np,d-1)
end for
return res
end function
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">descending_primes</span><span style="color: #0000FF;">({</span><span style="color: #000000;">2</span><span style="color: #0000FF;">})),</span>
<span style="color: #000080;font-style:italic;">--sequence r = descending_primes({2}),</span>
<span style="color: #000000;">j</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%8d"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"There are %,d descending primes:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">),</span><span style="color: #000000;">j</span><span style="color: #0000FF;">})</span>
<!--
sequence r = sort(descending_primes({2})),
--sequence r = descending_primes({2}),
j = join_by(r,1,11," ","\n","%8d")
printf(1,"There are %,d descending primes:\n%s\n",{length(r),j})

View file

@ -1,22 +1,19 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">descending_primes</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">powerset</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">9</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">powerset</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #000000;">powerset</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">next</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">powerset</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">powerset</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">next</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">powerset</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]*</span><span style="color: #000000;">10</span><span style="color: #0000FF;">+</span><span style="color: #000000;">d</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">powerset</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">next</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
with javascript_semantics
function descending_primes()
sequence powerset = tagset(9), res = {}
do
res &= filter(powerset,is_prime)
sequence next = {}
for p in powerset do
for d=1 to remainder(p,10)-1 do
next &= p*10+d
end for
end for
powerset = next
until length(powerset)=0
return res
end function
<span style="color: #004080;">sequence</span> <span style="color: #000000;">r</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">descending_primes</span><span style="color: #0000FF;">(),</span>
<span style="color: #000000;">j</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">11</span><span style="color: #0000FF;">,</span><span style="color: #008000;">" "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%8d"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"There are %,d descending primes:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">r</span><span style="color: #0000FF;">),</span><span style="color: #000000;">j</span><span style="color: #0000FF;">})</span>
<!--
sequence r = descending_primes(),
j = join_by(r,1,11," ","\n","%8d")
printf(1,"There are %,d descending primes:\n%s\n",{length(r),j})

View file

@ -0,0 +1,45 @@
-- 21 Feb 2026
include Setting
say 'DESCENDING PRIMES'
say version
say
say Collect() 'found'; say
call Show
call Timer
exit
Collect:
procedure expose Prim.
say 'Collect descending primes...'
Prim.=0; n=0; a='1 2 3 4 5 6 7 8 9'
do 9
b=''
do i = 1 to Words(a)
w=Word(a,i)
if Prime(w) then do
n=n+1; Prim.n=w
end
do j = Right(w,1)-1 by -1 to 1
b=b w||j
end
end
a=b
end
Prim.0=n
call SortSt 'Prim.'
return n
Show:
procedure expose Prim.
say 'All descending primes below 1,000,000,000'
do i = 1 to Prim.0
call CharOut ,Right(Prim.i,10)
if i//10 = 0 then
say
end
say
return 0
-- Prime; SortSt; Timer
include Math

View file

@ -0,0 +1,55 @@
proc isprime n {
set wheel {6 4 2 4 2 4 6 2}
if {$n < 2} {
return 0
}
if {$n % 2 == 0} {expr {$n == 2}} \
elseif {$n % 3 == 0} {expr {$n == 3}} \
elseif {$n % 5 == 0} {expr {$n == 5}} \
else {
set k 0
set d 1
while {true} {
incr d [lindex $wheel $k]
incr k
if {$k == 8} {set k 0}
if {$d*$d > $n} {
return 1
}
if {$n % $d == 0} {
return 0
}
}
}
}
set primes {}
for {set i 1} {$i < 512} {incr i} {
set d 9
set n ""
foreach b [split [format "%09b" $i] ""] {
if {$b} {
set n "$n$d"
}
incr d -1
}
if {[isprime $n]} {
lappend primes $n
}
}
set primes [lsort -integer $primes]
set k 0
foreach p $primes {
puts -nonewline [format "%10i" $p]
incr k
if {$k == 8} {
set k 0
puts ""
}
}
puts ""

View file

@ -0,0 +1,3 @@
IsP ← =⊣⊸°/×
/◇⊂≡⍚(▽⊸≡IsP▽⊸>₁°⊥₁₀˜⧅<⇡10)↘1⇡10
&p$"Found _ primes:\n_"⊸⧻