adding 2015 & 2025 advents
This commit is contained in:
5
2025/01/JS/deno.json
Normal file
5
2025/01/JS/deno.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"tasks": {
|
||||
"dev": "deno run --watch main.ts"
|
||||
}
|
||||
}
|
||||
10
2025/01/JS/example.txt
Normal file
10
2025/01/JS/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
4732
2025/01/JS/input.txt
Normal file
4732
2025/01/JS/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
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