99 lines
1.9 KiB
Python
99 lines
1.9 KiB
Python
with open('input.txt', 'r') as f:
|
|
puzzle = f.read()
|
|
|
|
directions = list(puzzle)
|
|
|
|
santa_x = 0
|
|
santa_y = 0
|
|
|
|
robo_santa_x = 0
|
|
robo_santa_y = 0
|
|
|
|
houses = {
|
|
0: {
|
|
0: {
|
|
'presents': 1
|
|
}
|
|
}
|
|
}
|
|
|
|
house_count = 1
|
|
|
|
loop_iter = 1
|
|
|
|
for direction in directions:
|
|
if loop_iter % 2 == 0:
|
|
if direction == '>':
|
|
robo_santa_x += 1
|
|
|
|
elif direction == '<':
|
|
robo_santa_x -= 1
|
|
|
|
elif direction == '^':
|
|
robo_santa_y += 1
|
|
|
|
elif direction == 'v':
|
|
robo_santa_y -= 1
|
|
|
|
if robo_santa_x not in houses:
|
|
houses.update({
|
|
robo_santa_x: {
|
|
robo_santa_y: {
|
|
'presents': 1
|
|
}
|
|
}
|
|
})
|
|
|
|
house_count += 1
|
|
|
|
elif robo_santa_y not in houses[robo_santa_x]:
|
|
houses[robo_santa_x].update({
|
|
robo_santa_y: {
|
|
'presents': 1
|
|
}
|
|
})
|
|
|
|
house_count += 1
|
|
|
|
else:
|
|
houses[robo_santa_x][robo_santa_y]['presents'] += 1
|
|
|
|
else:
|
|
if direction == '>':
|
|
santa_x += 1
|
|
|
|
elif direction == '<':
|
|
santa_x -= 1
|
|
|
|
elif direction == '^':
|
|
santa_y += 1
|
|
|
|
elif direction == 'v':
|
|
santa_y -= 1
|
|
|
|
if santa_x not in houses:
|
|
houses.update({
|
|
santa_x: {
|
|
santa_y: {
|
|
'presents': 1
|
|
}
|
|
}
|
|
})
|
|
|
|
house_count += 1
|
|
|
|
elif santa_y not in houses[santa_x]:
|
|
houses[santa_x].update({
|
|
santa_y: {
|
|
'presents': 1
|
|
}
|
|
})
|
|
|
|
house_count += 1
|
|
|
|
else:
|
|
houses[santa_x][santa_y]['presents'] += 1
|
|
|
|
loop_iter += 1
|
|
|
|
print(house_count) |