Permalink
Browse files

code refactoring

  • Loading branch information...
1 parent 3701228 commit 3bf91a52ab44128f034ed7499ad929b9ac04a781 igorekbsu committed Mar 22, 2012
Showing with 5 additions and 7 deletions.
  1. +5 −7 50_99/src/task62/s62.py
@@ -1,12 +1,11 @@
from collections import defaultdict
-from itertools import count
from common import Watch
Watch.start()
-perm_count, cubes_dict = defaultdict(int), defaultdict(list)
-for c in count(1):
- digits, cube = [0] * 10, c ** 3
- k = cube
+lim = 10000
+cubes, perm_count, cubes_dict = set(i ** 3 for i in range(101, lim)), defaultdict(int), defaultdict(list)
+for cube in cubes:
+ digits, k = [0] * 10, cube
while k > 0:
digits[k % 10] += 1
k //= 10
@@ -15,8 +14,7 @@
n = n * 10 + d
perm_count[n] += 1
cubes_dict[n].append(cube)
- if perm_count[n] == 5: break
-print(min(min(cubes_dict[cube]) for cube, freq in perm_count.items() if freq == 5))
+print(min(min(cubes_dict[cube]) for cube, count in perm_count.items() if count == 5))
Watch.stop()

0 comments on commit 3bf91a5

Please sign in to comment.