Pernicious numbers in Python


SUBMITTED BY: Guest

DATE: June 5, 2015, 10:42 a.m.

FORMAT: Python

SIZE: 589 Bytes

HITS: 1375

  1. >>> def popcount(n): return bin(n).count("1")
  2. >>> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61}
  3. >>> p, i = [], 0
  4. >>> while len(p) < 25:
  5. if popcount(i) in primes: p.append(i)
  6. i += 1
  7. >>> p
  8. [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]
  9. >>> p, i = [], 888888877
  10. >>> while i <= 888888888:
  11. if popcount(i) in primes: p.append(i)
  12. i += 1
  13. >>> p
  14. [888888877, 888888878, 888888880, 888888883, 888888885, 888888886]
  15. >>>

comments powered by Disqus