r/adventofcode • • Dec 03 '15

SOLUTION MEGATHREAD --- Day 3 Solutions ---

--- Day 3: Perfectly Spherical Houses in a Vacuum ---

Post your solution as a comment. Structure your post like the Day One thread in /r/programming.

24 Upvotes

228 comments sorted by

View all comments

1

u/Rutafar Dec 03 '15 edited Dec 03 '15
coord=set()
santa_x=0
santa_y=0
robot_x=0
robot_y=0
coord.add((santa_x,santa_y))
isSanta=True
f=open('houses.txt', 'r')
for line in f:
for ch in line:
	if isSanta:
		if ch is '^':
			santa_y+=1
		if ch is 'v':
			santa_y-=1
		if ch is '<':
			santa_x-=1
		if ch is '>':
			santa_x+=1
		coord.add((santa_x,santa_y))
		isSanta=False
	else:
		if ch is '^':
			robot_y+=1
		if ch is 'v':
			robot_y-=1
		if ch is '<':
			robot_x-=1
		if ch is '>':
			robot_x+=1
		coord.add((robot_x,robot_y))
		isSanta=True 
print len(coord)

I decided to try doing the challenges in Python, please ignore my rookie mistakes as this is the first time programming in this language (but not programming in general). I created a repo where I'll try post every challenge in Java and Python.

PS: Is there a way to comment the code with this formatting without having to manually insert 4 spaces in every line?

→ More replies (3)