74 lines
2.6 KiB
Text
74 lines
2.6 KiB
Text
primes : 0b0010100000100000100010100010000010100000100010100010100010101100
|
|
|
|
| the first 25 pernicious numbers
|
|
|
|
|
|
$T | clear string
|
|
num_pn | set to zero
|
|
2 n | start at 2
|
|
5 hi_bit
|
|
if num_pn LT 25
|
|
call popcount | count ones
|
|
if primes bit pop_cnt | if pop_cnt bit of bit vector primes is one
|
|
+ num_pn | inc number of pernicious numbers
|
|
~ n $S | convert to decimal string
|
|
+ ' ' $S | pad a space
|
|
+ $S $T | add to string $T
|
|
endif
|
|
+ pop_cnt | next number (odd) has one more bit than previous (even)
|
|
+ n | next number
|
|
if primes bit pop_cnt
|
|
+ num_pn
|
|
~ n $S
|
|
+ ' ' $S
|
|
+ $S $T
|
|
endif
|
|
+ n
|
|
goif | go back to if
|
|
endif
|
|
$T [] | display numbers
|
|
|
|
|
|
|
|
| pernicious numbers in range 888888877 .. 888888888
|
|
|
|
$T | clear string
|
|
num_pn | set to zero
|
|
888888876 n | start at 888888876
|
|
29 hi_bit
|
|
if n LE 888888888
|
|
call popcount | count ones
|
|
if primes bit pop_cnt | if pop_cnt bit of bit vector primes is one
|
|
+ num_pn | inc number of pernicious numbers
|
|
~ n $S | convert to decimal string
|
|
+ ' ' $S | pad a space
|
|
+ $S $T | add to string $T
|
|
endif
|
|
+ pop_cnt | next number (odd) has one more bit than previous (even)
|
|
+ n | next number
|
|
if primes bit pop_cnt
|
|
+ num_pn
|
|
~ n $S
|
|
+ ' ' $S
|
|
+ $S $T
|
|
endif
|
|
+ n
|
|
goif | go back to if
|
|
endif
|
|
$T [] | display numbers
|
|
|
|
stop
|
|
|
|
|
|
|
|
popcount | count ones in bit field
|
|
pop_cnt | pop_cnt to zero
|
|
1 bit_num | only count even numbers so skip bit 0
|
|
if bit_num LE hi_bit
|
|
if n bit bit_num
|
|
+ pop_cnt
|
|
endif
|
|
+ bit_num
|
|
goif
|
|
endif
|
|
return
|