PyPE solution to PE problem 35
PyPE solution to PE problem 35
Blueprint information
- Status:
- Complete
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- Approved
- Series goal:
- None
- Implementation:
-
Implemented
- Milestone target:
- None
- Started by
- Scott Armitage
- Completed by
- Scott Armitage
Related branches
Related bugs
Sprints
Whiteboard
ProjectEule
===
The number, 197, is called a circular prime because all rotations of the
digits: 197, 971, and 719, are themselves prime.
There are thirteen such primes below 100:
2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
How many circular primes are there below one million?
Solution
--------
We start by generating a list of all primes below the limit. We proceed to
check each prime to see if it is circular by obtaining a list of its
rotations and comparing this set against the set of primes. If they are all
primes, all rotations are added to the set of circular primes; otherwise,
all rotations are added to the set of non-circular primes. Checking against
these sets allows for caching of results.
Answer
------
55