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,5 +1,5 @@
1 1
 import string
2
-from functools import partial
2
+from functools import partial, reduce
3 3
 
4 4
 
5 5
 def spin(amount, line):
@@ -23,8 +23,7 @@ def dance(reps, moves):
23 23
     # then all of the remainder will just cycle between those two lines.
24 24
     history = []
25 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 27
         if line in history:
29 28
             start = history.index(line)
30 29
             cycle = len(history) - start

Loading…
Cancel
Save