This is day 3 of the Advent of Code challenge. Here is my solution:
const data = $("pre").innerText.split("\n");
data.pop();
const toboggan = ([right, down]) => {
let yPos = 0;
let xPos = 0;
let colLength = data.length - down;
let rowLength = data[yPos].length - right;
let result = [];
for (let i = 0; i < data.length / down; i++) {
result.push(data[yPos][xPos]);
yPos += down;
xPos >= rowLength ? (xPos -= rowLength) : (xPos += right);
}
return result.filter((item) => item === "#").length;
};
[
[1, 1],
[3, 1],
[5, 1],
[7, 1],
[1, 2],
]
.map((config) => toboggan(config))
.reduce((a, b) => a * b, 1);
Thoughts on the challenge:
- I saw people online use modulo loop and I should work towards it
- The question statement are really confusing lol
Top comments (0)