Day 3, Year 2015: Perfectly Spherical Houses in a Vacuum
First read the problem description.
def count_houses(it, santas=1):
= []
positions for _ in range(santas):
0,0])
positions.append([
= set()
houses = 0
turn for pos in positions:
tuple(pos))
houses.add(
for ch in it:
if ch == '^':
1] += 1
positions[turn][elif ch == 'v':
1] -= 1
positions[turn][elif ch == '>':
0] += 1
positions[turn][elif ch == '<':
0] -= 1
positions[turn][else:
continue
tuple(positions[turn]))
houses.add(= (turn + 1) % santas
turn
return len(houses)
import import_ipynb
import helper
= helper.read_file('2015_3.txt') s
assert count_houses('>') == 2
assert count_houses('^>v<') == 4
assert count_houses('^v^v^v^v^v') == 2
count_houses(s)
2592
assert count_houses('^v', 2) == 3
assert count_houses('^>v<', 2) == 3
assert count_houses('^v^v^v^v^v', 2) == 11
2) count_houses(s,
2360
Source code of the solution(s):