PyPE solution to PE problem 52
PyPE solution to PE problem 52
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
Whiteboard
ProjectEule
===
It can be seen that the number, 125874, and its double, 251748, contain
exactly the same digits, but in a different order.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x,
contain the same digits.
Solution
--------
We begin with i=2 and work our way up from there. We know right off the bat
that once we hit a number where 6*i has more digits than i, then we can
jump to the next magnitude number (e.g. for i=17, 6*i=102, thus no other
two-digit numbers less than 100 are of interest, since 6*x will also have
more digits than x; so we skip to i=100 and continue from there).
Next, we generate a 10-element list containing the count of each numeral
from 0-9 in the representation of i. This is the digit count. For example,
the number i=27735 would have a digit count of:
0 1 2 3 4 5 6 7 8 9
[ 0, 0, 1, 1, 0, 1, 0, 2, 0, 0 ]
We then procede through the multiples of i, up to limit*i, and compare the
digit counts of each of the resulting values to the digit count of i. Once
we find a digit count that does not match, we know that the i cannot be a
solution, and skip to the next i.
Answer
------
142857