Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- def is_palindrome(n):
- p = str(n)
- if p == p[::-1]:
- return True
- else:
- return False
- def run(case, A, B):
- print B
- palindromes = filter(is_palindrome, range(1, 1000))
- squares = map(lambda x: x*x, palindromes)
- fair_and_square = filter(is_palindrome, squares)
- fair_and_square = len(filter(lambda x: x in range(A,B+1), fair_and_square))
- return "Case #%d: %d\n" % (case, fair_and_square)
- def main():
- with open("C-small-practice.in", "r") as f:
- lines = f.readlines()[1:]
- with open("out1.txt", "a") as w:
- for line in enumerate(lines, start=1):
- nums = map(int, line[1].split())
- run(line[0], nums[0], nums[1])
- w.write(run(line[0], nums[0], nums[1]))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement