Advertisement
Guest User

Untitled

a guest
Dec 24th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def day24_1():
  2.     import re
  3.     from collections import defaultdict
  4.    
  5.     with open("input24.txt", "r") as file:
  6.         data = file.readlines()
  7.        
  8.     floor = defaultdict(lambda: False)
  9.     for line in data:
  10.         coords = re.findall(r"e|se|sw|w|nw|ne", line)
  11.         ns = coords.count("se") + coords.count("sw") - coords.count("ne") - coords.count("nw")
  12.         we = coords.count("e") + coords.count("ne") - coords.count("w") - coords.count("sw")
  13.  
  14.         floor[(ns, we)] = not floor[(ns, we)]
  15.        
  16.     return sum([v for v in floor.values()])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement