Files
Advent-of-Code/2025/01/JS/main.ts

44 lines
887 B
TypeScript

const input = await Deno.readTextFile("input.txt");
const START = 50
const TOTAL = 100
function part1(){
let password = 0
let current = START
for (const rotation of input.split('\n')) {
const direction = rotation[0]
let amount = Number(rotation.slice(1))
if (direction === "L") {
amount *= -1
}
let change = current + amount
while (change < 0) {
change = TOTAL + change
}
current = change % TOTAL
if (current === 0) {
password += 1
}
}
console.log(password)
}
function part2(){
let password = 0
let current = START
for (const rotation of input.split('\n')) {
const direction = rotation[0]
let amount = Number(rotation.slice(1))
if (direction === "L") {
const divisions = Math.floor((amount * -1) / TOTAL * -1)
password += divisions
}
}
console.log(password)
}
//part1()
part2()