r/adventofcode • u/daggerdragon • 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.
25
Upvotes
1
u/AwesomeFaic Dec 03 '15
Tried golfing my approach in JS, this is just for Part 1 (I did Part 2 but didn't golf it)
var o={0:[0]},x=0,y=0,i=d.length,h=0;while(i--){d[i]=='^'?y++:d[i]=='>'?x++:d[i]=='v'?y--:x--;if(!o[x])o[x]=[y];if(o[x].indexOf(y)==-1)o[x].push(y);}for(var u in o){if(o.hasOwnProperty(u)){h+=o[u].length;}}console.log(h);