Browse Source

Reduce instead of iterating.

master
Chris Smith 6 years ago
parent
commit
4705fb8f1f
1 changed files with 2 additions and 3 deletions
  1. 2
    3
      16.py

+ 2
- 3
16.py View File

1
 import string
1
 import string
2
-from functools import partial
2
+from functools import partial, reduce
3
 
3
 
4
 
4
 
5
 def spin(amount, line):
5
 def spin(amount, line):
23
     # then all of the remainder will just cycle between those two lines.
23
     # then all of the remainder will just cycle between those two lines.
24
     history = []
24
     history = []
25
     for i in range(reps):
25
     for i in range(reps):
26
-        for move in moves:
27
-            line = move(line)
26
+        line = reduce(lambda v, m: m(v), moves, line)
28
         if line in history:
27
         if line in history:
29
             start = history.index(line)
28
             start = history.index(line)
30
             cycle = len(history) - start
29
             cycle = len(history) - start

Loading…
Cancel
Save