Created
December 8, 2016 16:34
-
-
Save ostearn/14e5a28624fdbf037f1b38eb62f8c363 to your computer and use it in GitHub Desktop.
AoC Day 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Advent of Code Day 1</title> | |
<script> | |
var input = "L2, L3, L3, L4, R1, R2, L3, R3, R3, L1, L3, R2, R3, L3, R4, R3, R3, L1, L4, R4, L2, R5, R1, L5, R1, R3, L5, R2, L2, R2, R1, L1, L3, L3, R4, R5, R4, L1, L189, L2, R2, L5, R5, R45, L3, R4, R77, L1, R1, R194, R2, L5, L3, L2, L1, R5, L3, L3, L5, L5, L5, R2, L1, L2, L3, R2, R5, R4, L2, R3, R5, L2, L2, R3, L3, L2, L1, L3, R5, R4, R3, R2, L1, R2, L5, R4, L5, L4, R4, L2, R5, L3, L2, R4, L1, L2, R2, R3, L2, L5, R1, R1, R3, R4, R1, R2, R4, R5, L3, L5, L3, L3, R5, R4, R1, L3, R1, L3, R3, R3, R3, L1, R3, R4, L5, L3, L1, L5, L4, R4, R1, L4, R3, R3, R5, R4, R3, R3, L1, L2, R1, L4, L4, L3, L4, L3, L5, R2, R4, L2"; | |
var orientation = "N"; | |
var coordinates= new Array(); | |
var north =0; | |
var east =0; | |
var south =0; | |
var west =0; | |
var axisx = 0; | |
var axisy = 0; | |
var steps = input.split(", "); | |
for(var i=0; i<steps.length; i++) { | |
var currStep = steps[i]; | |
console.log(orientation +" " +currStep); | |
var eachinst = currStep.split(""); | |
var direction = eachinst[0]; | |
//var distance = str.substring(1, 4); | |
//var distance = eachinst[1]; | |
distance = currStep.substring(1); | |
distance = parseInt(distance); | |
//console.log("<br />" +eachinst[1]); | |
if(orientation == "N"){ | |
if(direction == "L"){ | |
for(var j=0; j<distance; j++){ | |
west++; | |
axisx--; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "W"; | |
} else{ | |
for(var j=0; j<distance; j++){ | |
east++; | |
axisx++; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "E"; | |
} | |
} else if(orientation == "E"){ | |
if(direction == "L"){ | |
for(var j=0; j<distance; j++){ | |
north++; | |
axisy++; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "N"; | |
} else{ | |
for(var j=0; j<distance; j++){ | |
south++; | |
axisy--; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "S"; | |
} | |
} else if(orientation == "S"){ | |
if(direction == "L"){ | |
for(var j=0; j<distance; j++){ | |
east++; | |
axisx++; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "E"; | |
} else{ | |
for(var j=0; j<distance; j++){ | |
west++; | |
axisx--; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "W"; | |
} | |
} else if(orientation == "W"){ | |
if(direction == "L"){ | |
for(var j=0; j<distance; j++){ | |
south++; | |
axisy--; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "S"; | |
} else{ | |
for(var j=0; j<distance; j++){ | |
north++; | |
axisy++; | |
var coordinate = axisx +" " +axisy; | |
console.log(coordinate); | |
//console.log(orientation +" " +currStep); | |
a = coordinates.indexOf(coordinate); | |
if(a == -1){ | |
coordinates.push(coordinate); | |
}else{ | |
console.log("This is the one!!!!!"); | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
} | |
} | |
orientation = "N"; | |
} | |
} | |
} | |
console.log("North:" +north +"| South:" +south +"| East:" +east +"| West:" +west); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment