Skip to content

Commit ca4735a

Browse files
committed
day 24
1 parent 87877a9 commit ca4735a

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
|[21](https://adventofcode.com/2020/day/21)|Allergen Assessment|[py](/day21/main.py)|
2626
|[22](https://adventofcode.com/2020/day/22)|Crab Combat|[py](/day22/main.py)|
2727
|[23](https://adventofcode.com/2020/day/23)|Crab Cups|[py](/day23/main.py)|
28-
|[24](https://adventofcode.com/2020/day/24)|-|-|
28+
|[24](https://adventofcode.com/2020/day/24)|Lobby Layout|[py](/day24/main.py)|
2929
|[25](https://adventofcode.com/2020/day/25)|-|-|

day24/main.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from collections import defaultdict
2+
3+
def parse(s):
4+
i = 0
5+
res = []
6+
while s:
7+
if s[0] == "w": res.append((-1,0)); s = s[1:]
8+
elif s[0] == "e": res.append((1,0)); s = s[1:]
9+
elif s[0:2] == "se": res.append((1,-1)); s = s[2:]
10+
elif s[0:2] == "sw": res.append((0,-1)); s = s[2:]
11+
elif s[0:2] == "ne": res.append((0,1)); s = s[2:]
12+
elif s[0:2] == "nw": res.append((-1,1)); s = s[2:]
13+
return res
14+
15+
with open("input.txt") as f:
16+
lines = [parse(x.strip()) for x in f]
17+
18+
d = defaultdict(int)
19+
20+
for line in lines:
21+
xs, ys = zip(*line)
22+
coords = sum(ys), sum(xs)
23+
d[coords] = 1 - d[coords]
24+
25+
print(sum(d.values()))
26+
27+
def apply(n, ns):
28+
if n == 0:
29+
if sum(ns) == 2:
30+
return 1
31+
else:
32+
if sum(ns) == 0 or sum(ns) > 2:
33+
return 0
34+
return n
35+
36+
dirs = [(1,-1),(0,-1),(-1,1),(0,1),(1,0),(-1,0)]
37+
for _ in range(100):
38+
d2 = d.copy()
39+
for row in range(-100,100):
40+
for col in range(-100,100):
41+
coords = (row,col)
42+
d2[coords] = apply(d[coords], [d[k] for k in [(y+row, x+col) for x, y in dirs]])
43+
d = d2
44+
45+
print(sum(d.values()))

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