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

Show parent comment

2

u/JShultz89 Dec 04 '15

I did something very similar but used numpy and numpy.unique.

import numpy as np

directions = 'ya know' 
moves = list(directions)
locations = np.empty([len(moves),2])

x = 0
y = 0 

for i in range(len(moves)):
	if moves[i] == '^':
		y += 1
	elif moves[i] == 'v':
		y -= 1
	elif moves[i] == '>':
		x += 1
	elif moves[i] == '<':
		x -= 1
	else:
		print 'There is a move that is not ^v<>'
		break
	
	locations[i] = np.array([x,y])

tupleLocations = [tuple(row) for row in locations]
u = np.unique(tupleLocations)
print len(u)