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,6 @@
with Interfaces;
package Population_Count is
subtype Num is Interfaces.Unsigned_64;
function Pop_Count(N: Num) return Natural;
end Population_Count;

View file

@ -0,0 +1,18 @@
package body Population_Count is
function Pop_Count(N: Num) return Natural is
use Interfaces;
K5555: constant Unsigned_64 := 16#5555555555555555#;
K3333: constant Unsigned_64 := 16#3333333333333333#;
K0f0f: constant Unsigned_64 := 16#0f0f0f0f0f0f0f0f#;
K0101: constant Unsigned_64 := 16#0101010101010101#;
X: Unsigned_64 := N;
begin
X := X - (Shift_Right(X, 1) and k5555);
X := (X and k3333) + (Shift_Right(X, 2) and k3333);
X := (X + (Shift_Right(X, 4)) and K0f0f);
X := Shift_Right((x * k0101), 56);
return Natural(X);
end Pop_Count;
end Population_Count;

View file

@ -0,0 +1,37 @@
with Ada.Text_IO, Population_Count; use Ada.Text_IO; use Population_Count;
procedure Test_Pop_Count is
X: Num; use type Num;
begin
Put("Pop_Cnt(3**i):"); -- print pop_counts of powers of three
X := 1; -- X=3**0
for I in 1 .. 30 loop
Put(Natural'Image(Pop_Count(X)));
X := X * 3;
end loop;
New_Line;
Put("Evil: "); -- print first thirty evil numbers
X := 0;
for I in 1 .. 30 loop
while Pop_Count(X) mod 2 /= 0 loop -- X is not evil
X := X + 1;
end loop;
Put(Num'Image(X));
X := X + 1;
end loop;
New_Line;
Put("Odious: "); -- print thirty oudous numbers
X := 1;
for I in 1 .. 30 loop
while Pop_Count(X) mod 2 /= 1 loop -- X is not odious
X := X + 1;
end loop;
Put(Num'Image(X));
X := X + 1;
end loop;
New_Line;
end Test_Pop_Count;

View file

@ -0,0 +1,73 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. HAMMING.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 POPCOUNT-VARIABLES.
03 POPCOUNT-IN PIC 9(15)V9.
03 FILLER REDEFINES POPCOUNT-IN.
05 POPCOUNT-REST PIC 9(15).
05 FILLER PIC 9.
88 BIT-IS-SET VALUE 5.
03 POPCOUNT-OUT PIC 99.
03 FILLER REDEFINES POPCOUNT-OUT.
05 FILLER PIC 9.
05 FILLER PIC 9.
88 EVIL VALUES 0, 2, 4, 6, 8.
88 ODIOUS VALUES 1, 3, 5, 7, 9.
01 STATE-VARIABLES.
03 CUR-POWER-3 PIC 9(15) VALUE 1.
03 CUR-EVIL-NUM PIC 99 VALUE 0.
03 CUR-ODIOUS-NUM PIC 99 VALUE 0.
03 LINE-INDEX PIC 99 VALUE 1.
01 OUTPUT-FORMAT.
03 LINENO PIC Z9.
03 FILLER PIC X VALUE '.'.
03 FILLER PIC XX VALUE SPACES.
03 OUT-POW3 PIC Z9.
03 FILLER PIC X(4) VALUE SPACES.
03 OUT-EVIL PIC Z9.
03 FILLER PIC X(4) VALUE SPACES.
03 OUT-ODIOUS PIC Z9.
PROCEDURE DIVISION.
BEGIN.
DISPLAY " 3^ EVIL ODD"
PERFORM MAKE-LINE 30 TIMES.
STOP RUN.
MAKE-LINE.
MOVE LINE-INDEX TO LINENO.
MOVE CUR-POWER-3 TO POPCOUNT-IN.
PERFORM FIND-POPCOUNT.
MOVE POPCOUNT-OUT TO OUT-POW3.
PERFORM FIND-EVIL.
MOVE CUR-EVIL-NUM TO OUT-EVIL.
PERFORM FIND-ODIOUS.
MOVE CUR-ODIOUS-NUM TO OUT-ODIOUS.
DISPLAY OUTPUT-FORMAT.
MULTIPLY 3 BY CUR-POWER-3.
ADD 1 TO CUR-EVIL-NUM.
ADD 1 TO CUR-ODIOUS-NUM.
ADD 1 TO LINE-INDEX.
FIND-EVIL.
MOVE CUR-EVIL-NUM TO POPCOUNT-IN.
PERFORM FIND-POPCOUNT.
IF NOT EVIL, ADD 1 TO CUR-EVIL-NUM, GO TO FIND-EVIL.
FIND-ODIOUS.
MOVE CUR-ODIOUS-NUM TO POPCOUNT-IN.
PERFORM FIND-POPCOUNT.
IF NOT ODIOUS, ADD 1 TO CUR-ODIOUS-NUM, GO TO FIND-ODIOUS.
FIND-POPCOUNT.
MOVE 0 TO POPCOUNT-OUT.
PERFORM PROCESS-BIT UNTIL POPCOUNT-IN IS EQUAL TO ZERO.
PROCESS-BIT.
DIVIDE 2 INTO POPCOUNT-IN.
IF BIT-IS-SET, ADD 1 TO POPCOUNT-OUT.
MOVE POPCOUNT-REST TO POPCOUNT-IN.

View file

@ -0,0 +1,21 @@
popcount(n) := block(
bits: makelist(bit_onep(n, i), i, 0, bit_length(n)),
length(sublist(bits, "+"))
)$
makelist(popcount(3^i), i, 0, 29);
evilp(n) := evenp(popcount(n))$
odiousp(n) := oddp(popcount(n))$
firstnums(lim, pred, name) := block(
sprint("First", lim, name, "numbers:"),
newline(),
count: 0, n: 0, while count<lim do(
if pred(n) then block(sprint(n), count: count+1),
n: n+1))$
firstnums(30, evilp, "evil")$
firstnums(30, odiousp, "odious")$

View file

@ -0,0 +1,32 @@
local function popcount(n)
local count = 0
while n != 0 do
n = n & (n - 1)
count += 1
end
return count
end
print("The population count of the first 30 powers of 3 is:")
local p3 = 1
for i = 0, 29 do
io.write($"{popcount(p3)} ")
p3 *= 3
end
local odious = {}
print("\n\nThe first 30 evil numbers are:")
local count = 0
local n = 0
while count < 30 do
local pc = popcount(n)
if pc % 2 == 0 then
io.write($"{n} ")
count += 1
else
odious:insert(n)
end
n += 1
end
odious:insert(n)
print("\n\nThe first 30 odious numbers are:")
print(odious:concat(" "))

View file

@ -0,0 +1,6 @@
function pop-count($n) {
(([Convert]::ToString($n, 2)).toCharArray() | where {$_ -eq '1'}).count
}
"pop_count 3^n: $(1..29 | foreach -Begin {$n = 1; (pop-count $n)} -Process {$n = 3*$n; (pop-count $n)} )"
"even pop_count: $($m = $n = 0; while($m -lt 30) {if(0 -eq ((pop-count $n)%2)) {$m += 1; $n}; $n += 1} )"
"odd pop_count: $($m = $n = 0; while($m -lt 30) {if(1 -eq ((pop-count $n)%2)) {$m += 1; $n}; $n += 1} )"

View file

@ -0,0 +1,3 @@
Pop ← /+⋯
≡(Pop˜ⁿ3)⇡30
°□₂⊕□¬◿2⊸≡Pop⇡60

View file

@ -0,0 +1,33 @@
' Population count - VBScript - 10/05/2019
nmax=30
b=3
n=0: list="": bb=1
For i=0 To nmax-1
list=list & " " & popcount(bb)
bb=bb*b
Next 'i
Msgbox list,,"popcounts of the powers of " & b
For j=0 to 1
If j=0 Then c="evil numbers": Else c="odious numbers"
n=0: list="": i=0
While n<nmax
If (popcount(i) Mod 2)=j Then
n=n+1
list=list & " " & i
End If
i=i+1
Wend
Msgbox list,,c
Next 'j
Function popcount(x)
Dim y,xx,xq,xr
xx=x
While xx>0
xq=Int(xx/2)
xr=xx-xq*2
If xr=1 Then y=y+1
xx=xq
Wend
popcount=y
End Function 'popcount