Skip to content

Commit c3453d3

Browse files
committed
simplification
1 parent 225fb84 commit c3453d3

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

2023/02/main.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,17 @@
1111
game_id = int(re.search(r"\d+", game_id).group(0))
1212
cubes = [x.strip() for x in re.split(', |;', cubes)]
1313

14+
color_map = {'red': (0, 12), 'green': (1, 13), 'blue': (2, 14)}
1415
maxes = [0, 0, 0]
1516
game_possible = True
17+
1618
for c in cubes:
1719
n, color = c.split(' ')
1820
n = int(n)
19-
if color == 'red':
20-
maxes[0] = max(maxes[0], n)
21-
if n > 12:
22-
game_possible = False
23-
elif color == 'green':
24-
maxes[1] = max(maxes[1], n)
25-
if n > 13:
26-
game_possible = False
27-
elif color == 'blue':
28-
maxes[2] = max(maxes[2], n)
29-
if n > 14:
30-
game_possible = False
21+
index, limit = color_map[color]
22+
maxes[index] = max(maxes[index], n)
23+
if n > limit:
24+
game_possible = False
3125

3226
if game_possible:
3327
part1 += game_id

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy