Browse Source

Simplify a little.

I think only two repeats of the reductions are ever needed,
so ditch tracking whether the counts are modified or not.

Golf away a couple of other minor lines.
master
Chris Smith 6 years ago
parent
commit
e262137831
1 changed files with 6 additions and 10 deletions
  1. 6
    10
      11.py

+ 6
- 10
11.py View File

@@ -17,16 +17,12 @@ reductions = [
17 17
 
18 18
 def distance(steps):
19 19
     counts = collections.defaultdict(lambda: 0, collections.Counter(steps))
20
-    last_counts = dict()
21
-    while counts != last_counts:
22
-        last_counts = dict(counts)
23
-        for a, b, result in reductions:
24
-            count = min(counts[a], counts[b])
25
-            counts[a] -= count
26
-            counts[b] -= count
27
-            counts[result] += count
28
-    counts['--'] = 0
29
-    return sum(counts.values())
20
+    for a, b, result in reductions * 2:
21
+        count = min(counts[a], counts[b])
22
+        counts[a] -= count
23
+        counts[b] -= count
24
+        counts[result] += count
25
+    return sum(counts.values()) - counts['--']
30 26
 
31 27
 
32 28
 with open('data/11.txt', 'r') as file:

Loading…
Cancel
Save