adding 2015 & 2025 advents
This commit is contained in:
43
2025/01/JS/main.ts
Normal file
43
2025/01/JS/main.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user