You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.4 KiB
71 lines
1.4 KiB
import os
|
|
import sys
|
|
|
|
file = open('in.txt', 'r')
|
|
input = file.read()
|
|
|
|
x = 0
|
|
y = 0
|
|
|
|
deliveries = {}
|
|
deliveries[str(x) + "," + str(y)] = 1
|
|
|
|
for char in input:
|
|
if char == "^":
|
|
y = y + 1
|
|
elif char == "v":
|
|
y = y - 1
|
|
elif char == ">":
|
|
x = x + 1
|
|
elif char == "<":
|
|
x = x - 1
|
|
|
|
value = deliveries.get(str(x) + "," + str(y), 0)
|
|
deliveries[str(x) + "," + str(y)] = value + 1
|
|
|
|
print("Santa made it to " + str(len(deliveries)) + " houses")
|
|
|
|
santa_x = 0
|
|
santa_y = 0
|
|
|
|
robo_santa_x = 0
|
|
robo_santa_y = 0
|
|
|
|
deliveries = {}
|
|
deliveries[str(santa_x) + "," + str(santa_y)] = 1
|
|
deliveries[str(robo_santa_x) + "," + str(robo_santa_y)] = deliveries[str(santa_x) + "," + str(santa_y)] + 1
|
|
|
|
real_santa = True
|
|
|
|
for char in input:
|
|
x = 0
|
|
y = 0
|
|
if real_santa == True:
|
|
x = santa_x
|
|
y = santa_y
|
|
else:
|
|
x = robo_santa_x
|
|
y = robo_santa_y
|
|
|
|
if char == "^":
|
|
y = y + 1
|
|
elif char == "v":
|
|
y = y - 1
|
|
elif char == ">":
|
|
x = x + 1
|
|
elif char == "<":
|
|
x = x - 1
|
|
|
|
value = deliveries.get(str(x) + "," + str(y), 0)
|
|
deliveries[str(x) + "," + str(y)] = value + 1
|
|
|
|
if real_santa == True:
|
|
santa_x = x
|
|
santa_y = y
|
|
else:
|
|
robo_santa_x = x
|
|
robo_santa_y = y
|
|
|
|
real_santa = (not real_santa)
|
|
|
|
print("Santa and Robo Santa made it to " + str(len(deliveries)) + " houses")
|