Browse Source

Style fixes

master
Chris Smith 7 years ago
parent
commit
2195b89d7b
5 changed files with 10 additions and 7 deletions
  1. 1
    1
      04.py
  2. 2
    0
      05.py
  3. 3
    3
      08.py
  4. 2
    1
      09.py
  5. 2
    2
      11.py

+ 1
- 1
04.py View File

@@ -9,7 +9,7 @@ with open('04.txt', 'r') as file:
9 9
     checksum = lambda x: re.sub(r'(.)\1+', r'\1',
10 10
                                 ''.join(sorted(x.name.replace('-', ''),
11 11
                                                key=lambda c: -128 * x.name.count(c) + ord(c)))
12
-                               )[:5]
12
+                                )[:5]
13 13
     valid = [room for room in rooms if room.checksum == checksum(room)]
14 14
     print("Part one: %s" % sum([int(room.sector) for room in valid]))
15 15
 

+ 2
- 0
05.py View File

@@ -6,9 +6,11 @@ from multiprocessing import Pool
6 6
 
7 7
 door = 'abbhdwsy'
8 8
 
9
+
9 10
 def hash(x):
10 11
     return hashlib.md5((door + str(x)).encode('utf-8')).hexdigest()
11 12
 
13
+
12 14
 pool = Pool()
13 15
 hashes = pool.imap(hash, itertools.count(), 10000)
14 16
 zeroes = (h for h in hashes if h.startswith('00000'))

+ 3
- 3
08.py View File

@@ -14,8 +14,8 @@ with open('08.txt', 'r') as file:
14 14
         elif words[1] == 'row':
15 15
             lights[i] = np.roll(lights[i], j)
16 16
         else:
17
-            lights[:,i] = np.roll(lights[:,i], j)
18
-        
17
+            lights[:, i] = np.roll(lights[:, i], j)
18
+
19 19
     print("Part one: %s" % np.sum(lights))
20 20
     print("Part two:")
21
-    print('\n'.join(''.join('\u2588' if p else ' '  for p in row) for row in lights))
21
+    print('\n'.join(''.join('\u2588' if p else ' ' for p in row) for row in lights))

+ 2
- 1
09.py View File

@@ -9,7 +9,8 @@ rparse = lambda x: parse(x, rparse)
9 9
 def parse(data, rfun=len):
10 10
     # Find the first bracketed part (if one exists)
11 11
     index, bracket = data.find('('), data.find(')')
12
-    if index == -1: return len(data)
12
+    if index == -1:
13
+        return len(data)
13 14
 
14 15
     # Grab the (NxR) values from the brackets
15 16
     num, reps = map(int, data[index + 1:bracket].split('x'))

+ 2
- 2
11.py View File

@@ -34,7 +34,7 @@ pickups = lambda items: map(set, itertools.chain(itertools.combinations(items, 2
34 34
 
35 35
 # Returns an enumeration of possible destinations for the lift (up or down one floor)
36 36
 dests = lambda layout: filter(is_floor, [my_floor_index(layout) + 1, my_floor_index(layout) - 1])
37
-is_floor = lambda i: i >= 0 and i < len(floors)
37
+is_floor = lambda i: 0 <= i < len(floors)
38 38
 
39 39
 # Returns an enumeration of possible moves that could be made from the given state
40 40
 moves = lambda layout: itertools.product(pickups(items(my_floor(layout))), dests(layout))
@@ -74,7 +74,7 @@ def run(floors):
74 74
         for items, to in moves(layout):
75 75
             items = set(items).union({lift})
76 76
             new_layout = [set(floor) - items for floor in layout]
77
-            new_layout[to] |= (items)
77
+            new_layout[to] |= items
78 78
             if valid_layout(new_layout):
79 79
                 serialised = serialise(new_layout)
80 80
                 if serialised not in distances:

Loading…
Cancel
Save