-
-
Save Mellen/bc5388b96ed3b1dfef3af3c6b4d5138b to your computer and use it in GitHub Desktop.
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
function treeHitCount() | |
{ | |
const lines = document.getElementsByTagName('pre')[0].innerHTML; | |
const input = lines.split('\n').map(line => line.split('')); | |
let slopes = [[1,1],[3,1],[5,1],[7,1],[1,2]]; | |
let total = 1; | |
for(let slope of slopes) | |
{ | |
let [xinc, yinc] = slope; | |
let x = 0; | |
let hitcount = 0; | |
for(let y = 0; y < input.length; y += yinc) | |
{ | |
if(input[y][x] == '#') | |
{ | |
hitcount++ | |
} | |
x += xinc; | |
if(x >= input[y].length) | |
{ | |
x = x%input[y].length; | |
} | |
} | |
total = total * hitcount; | |
} | |
return total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment