This commit is contained in:
nim-ka
2022-11-08 22:30:37 +00:00
parent b5e7f07541
commit f8e9088e67
13 changed files with 616 additions and 341 deletions

3
2021/1.js Normal file
View File

@@ -0,0 +1,3 @@
function day1(input, part2) {
return input.split`\n`.num().count((e, i, a, k = a[i - (part2 ? 3 : 1)]) => k && e > k)
}

15
2021/15.js Normal file
View File

@@ -0,0 +1,15 @@
function day15(input, part2) {
let g = Grid.fromStr(input).num()
if (part2) {
g = new Grid(g.width * 5, g.height * 5).mapMut((e, pt) => ((g.get(new Pt(pt.x % g.width, pt.y % g.height)) + (pt.x / g.width | 0) + (pt.y / g.height | 0) - 1) % 9) + 1)
}
g.graphify()
let start = g.get(new Pt(0, 0))
let end = g.get(new Pt(g.width - 1, g.height - 1))
start.dijkstraTo(end)
return end.searchData.dist
}

15
2021/2.js Normal file
View File

@@ -0,0 +1,15 @@
function day2(input, part2) {
let x = 0
let y = 0
let a = 0
input.split`\n`.forEach((e) => {
if (!part2) {
eval(e.replace("forward", "x +=").replace("up", "y -=").replace("down", "y +="))
} else {
eval(e.replace(/forward (.+)/, "x += $1; y += a * $1").replace("up", "a -=").replace("down", "a +="))
}
})
return x * y
}