PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/fairsquares/smallfairsquares.py

https://github.com/Version2beta/codejam-2013-qualifying
Python | 30 lines | 24 code | 6 blank | 0 comment | 7 complexity | 3a7183a08ba8ccd5bfa87175842e90b8 MD5 | raw file
  1. import os
  2. import sys
  3. import numpy as np
  4. import pandas as pd
  5. def is_p(x):
  6. return str(x) == str(x)[::-1]
  7. def genroots():
  8. x = 1
  9. while x < 10**7:
  10. if is_p(x):
  11. yield x
  12. x += 1
  13. def fairsquares():
  14. return [y*y for y in genroots() if is_p(y*y)]
  15. def main(data):
  16. while not data[0]: data.pop(0)
  17. count = int(data.pop(0))
  18. sq = pd.Series(fairsquares())
  19. for i in range(count):
  20. (lowest, highest) = data.pop(0).split()
  21. print "Case #%i:" % (i+1),
  22. print len(sq[(sq >= int(lowest)) & (sq <= int(highest))])
  23. if __name__ == "__main__":
  24. main(sys.stdin.readlines())