adventofcode-2017/day03/part1.js

14 lines
395 B
JavaScript
Raw Normal View History

2017-12-04 00:41:06 +00:00
function getPos(num){
var bottomCorner = Math.ceil(Math.sqrt(num));
if(bottomCorner%2 == 0){
bottomCorner++;
}
var sidelength = bottomCorner - 1;
var timesRound = (Math.pow(bottomCorner, 2) - num) / (bottomCorner - 1);
var lastsection = timesRound % 1;
var centerdistance = (Math.abs(0.5 - lastsection)) * sidelength;
console.log((sidelength / 2) + centerdistance);
}
getPos(325489);