Skip to content

Instantly share code, notes, and snippets.

@brentp brentp/euler_52.py
Created Jul 18, 2012

Embed
What would you like to do?
euler_52
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
@tanghaibao

This comment has been minimized.

Copy link

commented Jul 19, 2012

Any idea how to get this within 5s?
http://ideone.com/JiTKR

@martijnvermaat

This comment has been minimized.

Copy link

commented Jul 19, 2012

You mean instead of

for r in  euler_52():
    print r

do

print next(euler_52())

?

@brentp

This comment has been minimized.

Copy link
Owner Author

commented Jul 19, 2012

@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
You can’t perform that action at this time.