Skip to content

Instantly share code, notes, and snippets.

@Mellen

Mellen/aoc2020 day3.js Secret

Created Dec 3, 2020
Embed
What would you like to do?
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