Created
July 18, 2012 21:19
-
-
Save brentp/3138970 to your computer and use it in GitHub Desktop.
euler_52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
from collections import Counter | |
def euler_52(): | |
for i in itertools.count(1): | |
nums = [str(i * j) for j in range(1, 7)] | |
s = frozenset(nums[0]) | |
sall = set() | |
sall.update(*nums) | |
if sall == s: | |
c = Counter(nums[0]) | |
# double-check since set will hide frequencies | |
if all(c == Counter(n) for n in nums[1:]): | |
yield i, nums | |
for r in euler_52(): | |
print r |
You mean instead of
for r in euler_52():
print r
do
print next(euler_52())
?
@tanghaibao, not with python or at least need a better algorithm (or change the starting point).
@martijnvermaat yes, but if you keep printing, there's an interesting pattern.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any idea how to get this within 5s?
http://ideone.com/JiTKR