Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,40 +0,0 @@
with Ada.Text_IO, Population_Count; use Population_Count;
procedure Pernicious is
Prime: array(0 .. 64) of Boolean;
-- we are using 64-bit numbers, so the population count is between 0 and 64
X: Num; use type Num;
Cnt: Positive;
begin
-- initialize array Prime; Prime(I) must be true if and only if I is a prime
Prime := (0 => False, 1 => False, others => True);
for I in 2 .. 8 loop
if Prime(I) then
Cnt := I + I;
while Cnt <= 64 loop
Prime(Cnt) := False;
Cnt := Cnt + I;
end loop;
end if;
end loop;
-- print first 25 pernicious numbers
X := 1;
for I in 1 .. 25 loop
while not Prime(Pop_Count(X)) loop
X := X + 1;
end loop;
Ada.Text_IO.Put(Num'Image(X));
X := X + 1;
end loop;
Ada.Text_IO.New_Line;
-- print pernicious numbers between 888_888_877 and 888_888_888 (inclusive)
for Y in Num(888_888_877) .. 888_888_888 loop
if Prime(Pop_Count(Y)) then
Ada.Text_IO.Put(Num'Image(Y));
end if;
end loop;
Ada.Text_IO.New_Line;
end;

View file

@ -1,14 +0,0 @@
Counter: Natural;
begin
-- initialize array Prime; Prime(I) must be true if and only if I is a prime
...
Counter := 0;
-- count p. numbers below 2**32
for Y in Num(2) .. 2**32 loop
if Prime(Pop_Count(Y)) then
Counter := Counter + 1;
end if;
end loop;
Ada.Text_IO.Put_Line(Natural'Image(Counter));
end Count_Pernicious;

View file

@ -1,6 +1,6 @@
scope # find some pernicious numbers - numbers with a prime population count
local procedure populationCount( n :: number ) :: number
local proc populationCount( n :: number ) :: number
local v, count := abs n, 0;
while v > 0 do
if v && 1 = 1 then count +:= 1 fi;
@ -9,7 +9,7 @@ scope # find some pernicious numbers - numbers with a prime population count
return count
end;
local procedure isPernicious( p :: number ) :: boolean
local proc isPernicious( p :: number ) :: boolean
return p > 0 and numtheory.isprime( populationCount( p ) )
end

View file

@ -1,5 +1,5 @@
pernicious?: function [n][
prime? size filter split as.binary n 'x -> x="0"
prime? size filter split to :string .format:".b" n 'x -> x="0"
]
i: 1

View file

@ -1,94 +0,0 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. PERNICIOUS-NUMBERS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
03 AMOUNT PIC 99.
03 CAND PIC 9(9).
03 POPCOUNT PIC 99.
03 POP-N PIC 9(9).
03 FILLER REDEFINES POP-N.
05 FILLER PIC 9(8).
05 FILLER PIC 9.
88 ODD VALUES 1, 3, 5, 7, 9.
03 DSOR PIC 99.
03 DIV-RSLT PIC 99V99.
03 FILLER REDEFINES DIV-RSLT.
05 FILLER PIC 99.
05 FILLER PIC 99.
88 DIVISIBLE VALUE ZERO.
03 PRIME-FLAG PIC X.
88 PRIME VALUE '*'.
01 FORMAT.
03 SIZE-FLAG PIC X.
88 SMALL VALUE 'S'.
88 LARGE VALUE 'L'.
03 SMALL-NUM PIC ZZ9.
03 LARGE-NUM PIC Z(9)9.
03 OUT-STR PIC X(80).
03 OUT-PTR PIC 99.
PROCEDURE DIVISION.
BEGIN.
PERFORM SMALL-PERNICIOUS.
PERFORM LARGE-PERNICIOUS.
STOP RUN.
INIT-OUTPUT-VARS.
MOVE ZERO TO AMOUNT.
MOVE 1 TO OUT-PTR.
MOVE SPACES TO OUT-STR.
SMALL-PERNICIOUS.
PERFORM INIT-OUTPUT-VARS.
MOVE 'S' TO SIZE-FLAG.
PERFORM ADD-PERNICIOUS
VARYING CAND FROM 1 BY 1 UNTIL AMOUNT IS EQUAL TO 25.
DISPLAY OUT-STR.
LARGE-PERNICIOUS.
PERFORM INIT-OUTPUT-VARS.
MOVE 'L' TO SIZE-FLAG.
PERFORM ADD-PERNICIOUS
VARYING CAND FROM 888888877 BY 1
UNTIL CAND IS GREATER THAN 888888888.
DISPLAY OUT-STR.
ADD-NUM.
ADD 1 TO AMOUNT.
IF SMALL,
MOVE CAND TO SMALL-NUM,
STRING SMALL-NUM DELIMITED BY SIZE INTO OUT-STR
WITH POINTER OUT-PTR.
IF LARGE,
MOVE CAND TO LARGE-NUM,
STRING LARGE-NUM DELIMITED BY SIZE INTO OUT-STR
WITH POINTER OUT-PTR.
ADD-PERNICIOUS.
PERFORM FIND-POPCOUNT.
PERFORM CHECK-PRIME.
IF PRIME, PERFORM ADD-NUM.
FIND-POPCOUNT.
MOVE ZERO TO POPCOUNT.
MOVE CAND TO POP-N.
PERFORM COUNT-BIT UNTIL POP-N IS EQUAL TO ZERO.
COUNT-BIT.
IF ODD, ADD 1 TO POPCOUNT.
DIVIDE 2 INTO POP-N.
CHECK-PRIME.
IF POPCOUNT IS LESS THAN 2,
MOVE SPACE TO PRIME-FLAG
ELSE
MOVE '*' TO PRIME-FLAG.
PERFORM CHECK-DSOR VARYING DSOR FROM 2 BY 1
UNTIL NOT PRIME OR DSOR IS NOT LESS THAN POPCOUNT.
CHECK-DSOR.
DIVIDE POPCOUNT BY DSOR GIVING DIV-RSLT.
IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.

View file

@ -1,12 +1,8 @@
fastfunc isprim num .
if num < 2
return 0
.
if num < 2 : return 0
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
if num mod i = 0 : return 0
i += 1
.
return 1
@ -29,7 +25,6 @@ while cnt < 25
print ""
n = 1
for n = 888888877 to 888888888
if isprim popc n = 1
write n & " "
.
if isprim popc n = 1 : write n & " "
.
print ""

View file

@ -1,23 +1,13 @@
(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">pernicious</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">int_to_bits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">32</span><span style="color: #0000FF;">)))</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
with javascript_semantics
function pernicious(integer n)
return is_prime(sum(int_to_bits(n,32)))
end function
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)<</span><span style="color: #000000;">25</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">pernicious</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">n</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">pp</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">s</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;">888_888_877</span> <span style="color: #008080;">to</span> <span style="color: #000000;">888_888_888</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">pernicious</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">i</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">pp</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<!--
sequence s = {}
integer n = 1
do
do n += 1 until pernicious(n)
s &= n
until length(s)=25
?s
?filter(tagset(888_888_888,888_888_877),pernicious)

View file

@ -1,13 +1,12 @@
do -- find some pernicious numbers - numbers with a prime population count
local fmt = require( "fmt" ) -- RC Pluto formatting library
local int = require( "int" ) -- RC Pluto integer library, inc. prime utilities
-- returns the population count (number of set bits) of n
local function populationCount( n : number ) : number
local v, count = math.abs( n ), 0
while v > 0 do
if v & 1 == 1 then ++ count end
if v & 1 == 1 then count += 1 end
v >>= 1
end
return count
@ -23,15 +22,15 @@ do -- find some pernicious numbers - numbers with a prime population count
local p25, pCount = 2, 0 -- 0 and 1 aren't pernicious, so we start at 2
while pCount < 25 do
if isPernicious( p25 ) then
++ pCount
fmt.write( " %d", p25 )
pCount += 1
io.write( $" {p25}" )
end
++ p25
p25 += 1
end
print()
-- find the pernicious numbers between 888 888 877 and 888 888 888
for p = 888888877, 888888888 do
if isPernicious( p ) then fmt.write( " %d", p ) end
if isPernicious( p ) then io.write( $" {p}" ) end
end
print()
end

View file

@ -1,28 +0,0 @@
function pop-count($n) {
(([Convert]::ToString($n, 2)).toCharArray() | where {$_ -eq '1'}).count
}
function isPrime ($n) {
if ($n -eq 1) {$false}
elseif ($n -eq 2) {$true}
elseif ($n -eq 3) {$true}
else{
$m = [Math]::Floor([Math]::Sqrt($n))
(@(2..$m | where {($_ -lt $n) -and ($n % $_ -eq 0) }).Count -eq 0)
}
}
$i = 0
$num = 1
$arr = while($i -lt 25) {
if((isPrime (pop-count $num))) {
$i++
$num
}
$num++
}
"first 25 pernicious numbers"
"$arr"
""
"pernicious numbers between 888,888,877 and 888,888,888"
"$(888888877..888888888 | where{isprime(pop-count $_)})"

View file

@ -1,44 +0,0 @@
function Select-PerniciousNumber
{
[CmdletBinding()]
[OutputType([int])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$InputObject
)
Begin
{
function Test-Prime ([int]$n)
{
$n = [Math]::Abs($n)
if ($n -eq 0 -or $n -eq 1) {return $false}
for ($m = 2; $m -le [Math]::Sqrt($n); $m++)
{
if (($n % $m) -eq 0) {return $false}
}
return $true
}
[scriptblock]$popCount = {(([Convert]::ToString($this, 2)).ToCharArray() | Where-Object {$_ -eq '1'}).Count}
}
Process
{
foreach ($object in $InputObject)
{
$object | Add-Member -MemberType ScriptProperty -Name PopCount -Value $popCount -Force -PassThru | ForEach-Object {
if (Test-Prime $_.PopCount)
{
$_
}
}
}
}
}

View file

@ -1,9 +0,0 @@
$start, $end = 0, 999999
$range1 = $start..$end | Select-PerniciousNumber | Select-Object -First 25
"First {0} pernicious numbers:`n{1}`n" -f $range1.Count, ($range1 -join ", ")
$start, $end = 888888877, 888888888
$range2 = $start..$end | Select-PerniciousNumber
"Pernicious numbers between {0} and {1}:`n{2}`n" -f $start, $end, ($range2 -join ", ")

View file

@ -1,5 +1,5 @@
-- 28 Jul 2025
include Settings
-- 10 Oct 2025
include Setting
numeric digits 100
say 'PERNICIOUS NUMBERS'
@ -11,7 +11,6 @@ exit
Show:
procedure
call Time('r')
arg xx,yy
if yy = '' then
yy = xx
@ -20,7 +19,7 @@ say 'Pernicious numbers between' xx 'and' yy'...'
say
n = 0
do i = xx to yy
if Prime(Digitsum(Basenn(i,2))) then do
if Prime(Digitsum(D2b(i))) then do
n = n+1
call Charout ,i' '
if n//10 = 0 then
@ -28,9 +27,13 @@ do i = xx to yy
end
end
say
say n 'such numbers found'
say Format(Time('e'),,3) 'seconds'
say n 'found'
say
return
include Math
-- Db2
include Base
-- Prime
include Ntheory
-- Digitsum
include Special

View file

@ -1,64 +0,0 @@
'check if the number is pernicious
Function IsPernicious(n)
IsPernicious = False
bin_num = Dec2Bin(n)
sum = 0
For h = 1 To Len(bin_num)
sum = sum + CInt(Mid(bin_num,h,1))
Next
If IsPrime(sum) Then
IsPernicious = True
End If
End Function
'prime number validation
Function IsPrime(n)
If n = 2 Then
IsPrime = True
ElseIf n <= 1 Or n Mod 2 = 0 Then
IsPrime = False
Else
IsPrime = True
For i = 3 To Int(Sqr(n)) Step 2
If n Mod i = 0 Then
IsPrime = False
Exit For
End If
Next
End If
End Function
'decimal to binary converter
Function Dec2Bin(n)
q = n
Dec2Bin = ""
Do Until q = 0
Dec2Bin = CStr(q Mod 2) & Dec2Bin
q = Int(q / 2)
Loop
End Function
'display the first 25 pernicious numbers
c = 0
WScript.StdOut.Write "First 25 Pernicious Numbers:"
WScript.StdOut.WriteLine
For k = 1 To 100
If IsPernicious(k) Then
WScript.StdOut.Write k & ", "
c = c + 1
End If
If c = 25 Then
Exit For
End If
Next
WScript.StdOut.WriteBlankLines(2)
'display the pernicious numbers between 888,888,877 to 888,888,888 (inclusive)
WScript.StdOut.Write "Pernicious Numbers between 888,888,877 to 888,888,888 (inclusive):"
WScript.StdOut.WriteLine
For l = 888888877 To 888888888
If IsPernicious(l) Then
WScript.StdOut.Write l & ", "
End If
Next
WScript.StdOut.WriteLine