Skip to content

Instantly share code, notes, and snippets.

@brentp
Created July 18, 2012 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentp/3138970 to your computer and use it in GitHub Desktop.
Save brentp/3138970 to your computer and use it in GitHub Desktop.
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
Copy link

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

@martijnvermaat
Copy link

You mean instead of

for r in  euler_52():
    print r

do

print next(euler_52())

?

@brentp
Copy link
Author

brentp 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