Pernicious numbers



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



OUTPUT
     
3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36 37
888888877 888888878 888888880 888888883 888888885 888888886 888888889