generated from eric/adventofcode2023
Day one part two
This commit is contained in:
26
01/code.js
26
01/code.js
@@ -29,12 +29,32 @@ console.log(zeroCount);
|
||||
|
||||
// Part Two
|
||||
|
||||
for (const element of inputArray) {
|
||||
let zeroCount2 = 0;
|
||||
let currentPosition2 = 50;
|
||||
|
||||
for (const element of inputArray) {
|
||||
const instruction = element;
|
||||
const direction = instruction[0];
|
||||
const steps = Number.parseInt(instruction.slice(1));
|
||||
|
||||
if (direction === 'L') {
|
||||
for (let i = 1; i < steps + 1; i++) {
|
||||
currentPosition2 -= 1;
|
||||
if (currentPosition2 === 0 || (currentPosition2 % 100) === 0) {
|
||||
zeroCount2++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 1; i < steps + 1; i++) {
|
||||
currentPosition2 += 1;
|
||||
if (currentPosition2 === 0 || (currentPosition2 % 100) === 0) {
|
||||
zeroCount2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
console.log();
|
||||
console.log(zeroCount2);
|
||||
|
||||
// functions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user