my solutions to advent of code
aoc advent-of-code

apparently i am not supposed to have the inputs on my repo. so restarting this all. lost one of the solutions but it was the most boring (and first :( ) one

aylac.top e6cd4b0a

verified
+1
.envrc
···
+
use flake
+4
.gitignore
···
+
node_modules
+
build
+
input.txt
+
input.json
+1
.zed/settings.json
···
+
{ "disable_ai": true, "edit_predictions": { "disabled_globs": ["*"] } }
+20
2015/1/gleam/gleam.toml
···
+
name = "main"
+
version = "1.0.0"
+
+
# Fill out these fields if you intend to generate HTML documentation or publish
+
# your project to the Hex package manager.
+
#
+
# description = ""
+
# licences = ["Apache-2.0"]
+
# repository = { type = "github", user = "", repo = "" }
+
# links = [{ title = "Website", href = "" }]
+
#
+
# For a full reference of all the available options, you can have a look at
+
# https://gleam.run/writing-gleam/gleam-toml/.
+
+
[dependencies]
+
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
+
simplifile = ">= 2.3.0 and < 3.0.0"
+
+
[dev-dependencies]
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2015/1/gleam/manifest.toml
···
+
# This file was generated by Gleam
+
# You typically do not need to edit this file
+
+
packages = [
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
+
]
+
+
[requirements]
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+45
2015/1/gleam/src/main.gleam
···
+
import gleam/int.{to_string}
+
import gleam/io.{println}
+
import gleam/list.{Continue, Stop, fold, fold_until}
+
import gleam/result.{unwrap}
+
import gleam/string.{split, trim}
+
import simplifile.{read}
+
+
pub type FloorIndex {
+
FloorIndex(floor: Int, index: Int)
+
}
+
+
pub fn main() {
+
let input = read(from: "../input.txt") |> unwrap("") |> trim() |> split("")
+
+
// part 1 - get final floor
+
println(
+
fold(input, 0, fn(fl, cur) {
+
case cur {
+
"(" -> fl + 1
+
")" -> fl - 1
+
___ -> 0
+
}
+
})
+
|> to_string,
+
)
+
+
// part 2 - get first time in the basement
+
println(
+
{
+
input
+
|> fold_until(FloorIndex(0, 1), fn(fi, cur) {
+
let new = case cur {
+
"(" -> fi.floor + 1
+
")" -> fi.floor - 1
+
___ -> 0
+
}
+
case new < 0 {
+
True -> Stop(FloorIndex(new, fi.index))
+
False -> Continue(FloorIndex(new, fi.index + 1))
+
}
+
})
+
}.index
+
|> to_string,
+
)
+
}
+29
2015/1/ts/bun.lock
···
+
{
+
"lockfileVersion": 1,
+
"workspaces": {
+
"": {
+
"name": "ts",
+
"devDependencies": {
+
"@types/bun": "latest",
+
},
+
"peerDependencies": {
+
"typescript": "^5",
+
},
+
},
+
},
+
"packages": {
+
"@types/bun": ["@types/bun@1.3.1", "", { "dependencies": { "bun-types": "1.3.1" } }, "sha512-4jNMk2/K9YJtfqwoAa28c8wK+T7nvJFOjxI4h/7sORWcypRNxBpr+TPNaCfVWq70tLCJsqoFwcf0oI0JU/fvMQ=="],
+
+
"@types/node": ["@types/node@24.9.2", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA=="],
+
+
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
+
+
"bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
+
+
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
+
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
+
+
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
+
}
+
}
+3
2015/1/ts/index.ts
···
+
const input = (await Bun.file("../input.txt").text()).trim();
+
+
// i lost the old repo and im too lazy to do this one again :)
+15
2015/1/ts/package.json
···
+
{
+
"name": "ts",
+
"module": "index.ts",
+
"type": "module",
+
"scripts": {
+
"start": "bun index.ts"
+
},
+
"private": true,
+
"devDependencies": {
+
"@types/bun": "latest"
+
},
+
"peerDependencies": {
+
"typescript": "^5"
+
}
+
}
+29
2015/1/ts/tsconfig.json
···
+
{
+
"compilerOptions": {
+
// Environment setup & latest features
+
"lib": ["ESNext"],
+
"target": "ESNext",
+
"module": "Preserve",
+
"moduleDetection": "force",
+
"jsx": "react-jsx",
+
"allowJs": true,
+
+
// Bundler mode
+
"moduleResolution": "bundler",
+
"allowImportingTsExtensions": true,
+
"verbatimModuleSyntax": true,
+
"noEmit": true,
+
+
// Best practices
+
"strict": true,
+
"skipLibCheck": true,
+
"noFallthroughCasesInSwitch": true,
+
"noUncheckedIndexedAccess": true,
+
"noImplicitOverride": true,
+
+
// Some stricter flags (disabled by default)
+
"noUnusedLocals": false,
+
"noUnusedParameters": false,
+
"noPropertyAccessFromIndexSignature": false
+
}
+
}
+21
2015/2/gleam/gleam.toml
···
+
name = "main"
+
version = "1.0.0"
+
+
# Fill out these fields if you intend to generate HTML documentation or publish
+
# your project to the Hex package manager.
+
#
+
# description = ""
+
# licences = ["Apache-2.0"]
+
# repository = { type = "github", user = "", repo = "" }
+
# links = [{ title = "Website", href = "" }]
+
#
+
# For a full reference of all the available options, you can have a look at
+
# https://gleam.run/writing-gleam/gleam-toml/.
+
+
[dependencies]
+
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
+
simplifile = ">= 2.3.0 and < 3.0.0"
+
gleam_json = ">= 3.0.2 and < 4.0.0"
+
+
[dev-dependencies]
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+16
2015/2/gleam/manifest.toml
···
+
# This file was generated by Gleam
+
# You typically do not need to edit this file
+
+
packages = [
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
+
{ name = "gleam_json", version = "3.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "874FA3C3BB6E22DD2BB111966BD40B3759E9094E05257899A7C08F5DE77EC049" },
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
+
]
+
+
[requirements]
+
gleam_json = { version = ">= 3.0.2 and < 4.0.0" }
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+52
2015/2/gleam/src/main.gleam
···
+
import gleam/dynamic/decode
+
import gleam/int.{add, min, multiply, to_string}
+
import gleam/io.{println}
+
import gleam/json
+
import gleam/list.{combinations, fold, map, reduce}
+
import gleam/result.{unwrap}
+
import gleam/string.{trim}
+
import simplifile.{read}
+
+
pub fn main() {
+
let input =
+
read(from: "../input.json")
+
|> unwrap("")
+
|> trim()
+
|> json.parse(decode.list(decode.list(decode.int)))
+
|> unwrap([])
+
+
// part 1
+
println(
+
input
+
|> fold(0, fn(prev, cur) {
+
let sides =
+
cur
+
|> combinations(2)
+
|> map(fn(v) { fold(v, 1, multiply) })
+
+
prev
+
+ fold(sides, 0, fn(prev, cur) { prev + 2 * cur })
+
+ { reduce(sides, min) |> unwrap(0) }
+
})
+
|> to_string,
+
)
+
+
// part 2
+
println(
+
input
+
|> fold(0, fn(prev, cur) {
+
let smallest_perimeter =
+
reduce(
+
cur
+
|> map(fn(v) { multiply(v, 2) })
+
|> combinations(2)
+
|> map(fn(v) { fold(v, 0, add) }),
+
min,
+
)
+
|> unwrap(0)
+
+
prev + smallest_perimeter + fold(cur, 1, multiply)
+
})
+
|> to_string,
+
)
+
}
+29
2015/2/ts/bun.lock
···
+
{
+
"lockfileVersion": 1,
+
"workspaces": {
+
"": {
+
"name": "ts",
+
"devDependencies": {
+
"@types/bun": "latest",
+
},
+
"peerDependencies": {
+
"typescript": "^5",
+
},
+
},
+
},
+
"packages": {
+
"@types/bun": ["@types/bun@1.3.1", "", { "dependencies": { "bun-types": "1.3.1" } }, "sha512-4jNMk2/K9YJtfqwoAa28c8wK+T7nvJFOjxI4h/7sORWcypRNxBpr+TPNaCfVWq70tLCJsqoFwcf0oI0JU/fvMQ=="],
+
+
"@types/node": ["@types/node@24.9.2", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA=="],
+
+
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
+
+
"bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
+
+
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
+
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
+
+
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
+
}
+
}
+27
2015/2/ts/index.ts
···
+
const input = (await Bun.file("../input.json").json()) as [
+
number,
+
number,
+
number,
+
][];
+
+
// part 1
+
console.log(
+
input.reduce((prev, cur) => {
+
const sides = [cur[0] * cur[1], cur[1] * cur[2], cur[0] * cur[2]] as const;
+
return (
+
prev + (2 * sides[0] + 2 * sides[1] + 2 * sides[2] + Math.min(...sides))
+
);
+
}, 0),
+
);
+
+
// part 2
+
console.log(
+
input.reduce((prev, cur) => {
+
const smallestPerimeter = Math.min(
+
2 * cur[0] + 2 * cur[1],
+
2 * cur[1] + 2 * cur[2],
+
2 * cur[2] + 2 * cur[0],
+
);
+
return prev + (smallestPerimeter + cur[0] * cur[1] * cur[2]);
+
}, 0),
+
);
+15
2015/2/ts/package.json
···
+
{
+
"name": "ts",
+
"module": "index.ts",
+
"type": "module",
+
"scripts": {
+
"start": "bun index.ts"
+
},
+
"private": true,
+
"devDependencies": {
+
"@types/bun": "latest"
+
},
+
"peerDependencies": {
+
"typescript": "^5"
+
}
+
}
+29
2015/2/ts/tsconfig.json
···
+
{
+
"compilerOptions": {
+
// Environment setup & latest features
+
"lib": ["ESNext"],
+
"target": "ESNext",
+
"module": "Preserve",
+
"moduleDetection": "force",
+
"jsx": "react-jsx",
+
"allowJs": true,
+
+
// Bundler mode
+
"moduleResolution": "bundler",
+
"allowImportingTsExtensions": true,
+
"verbatimModuleSyntax": true,
+
"noEmit": true,
+
+
// Best practices
+
"strict": true,
+
"skipLibCheck": true,
+
"noFallthroughCasesInSwitch": true,
+
"noUncheckedIndexedAccess": true,
+
"noImplicitOverride": true,
+
+
// Some stricter flags (disabled by default)
+
"noUnusedLocals": false,
+
"noUnusedParameters": false,
+
"noPropertyAccessFromIndexSignature": false
+
}
+
}
+20
2015/3/gleam/gleam.toml
···
+
name = "main"
+
version = "1.0.0"
+
+
# Fill out these fields if you intend to generate HTML documentation or publish
+
# your project to the Hex package manager.
+
#
+
# description = ""
+
# licences = ["Apache-2.0"]
+
# repository = { type = "github", user = "", repo = "" }
+
# links = [{ title = "Website", href = "" }]
+
#
+
# For a full reference of all the available options, you can have a look at
+
# https://gleam.run/writing-gleam/gleam-toml/.
+
+
[dependencies]
+
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
+
simplifile = ">= 2.3.0 and < 3.0.0"
+
+
[dev-dependencies]
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2015/3/gleam/manifest.toml
···
+
# This file was generated by Gleam
+
# You typically do not need to edit this file
+
+
packages = [
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
+
]
+
+
[requirements]
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+95
2015/3/gleam/src/main.gleam
···
+
import gleam/dict.{type Dict}
+
import gleam/int.{to_string}
+
import gleam/io.{println}
+
import gleam/list.{fold}
+
import gleam/result.{unwrap}
+
import gleam/string.{split, trim}
+
import simplifile.{read}
+
+
pub type Location {
+
Location(x: Int, y: Int)
+
}
+
+
pub type World =
+
Dict(Location, Int)
+
+
pub type State {
+
State(location: Location, world: World)
+
}
+
+
pub type Turn {
+
Santa
+
Robo
+
}
+
+
pub type RoboState {
+
RoboState(
+
turn: Turn,
+
santa_location: Location,
+
robo_location: Location,
+
world: World,
+
)
+
}
+
+
pub fn give_gift(world: World, location: Location) {
+
dict.insert(world, location, { dict.get(world, location) |> unwrap(0) } + 1)
+
}
+
+
pub fn move_to(location: Location, direction: String) {
+
case direction {
+
"^" -> Location(location.x, location.y - 1)
+
"v" -> Location(location.x, location.y + 1)
+
"<" -> Location(location.x - 1, location.y)
+
">" -> Location(location.x + 1, location.y)
+
___ -> Location(location.x, location.y)
+
}
+
}
+
+
pub fn main() {
+
let input = read(from: "../input.txt") |> unwrap("") |> trim() |> split("")
+
+
// part 1
+
println(
+
{
+
input
+
|> fold(State(Location(0, 0), dict.new()), fn(state, direction) {
+
let loc = state.location
+
State(move_to(loc, direction), give_gift(state.world, loc))
+
})
+
}.world
+
|> dict.size()
+
|> to_string(),
+
)
+
+
// part 2
+
println(
+
{
+
input
+
|> fold(
+
RoboState(Santa, Location(0, 0), Location(0, 0), dict.new()),
+
fn(state, direction) {
+
let sloc = state.santa_location
+
let rloc = state.robo_location
+
case state.turn {
+
Santa ->
+
RoboState(
+
Robo,
+
move_to(sloc, direction),
+
Location(rloc.x, rloc.y),
+
give_gift(state.world, sloc),
+
)
+
Robo ->
+
RoboState(
+
Santa,
+
Location(sloc.x, sloc.y),
+
move_to(rloc, direction),
+
give_gift(state.world, rloc),
+
)
+
}
+
},
+
)
+
}.world
+
|> dict.size()
+
|> to_string(),
+
)
+
}
+29
2015/3/ts/bun.lock
···
+
{
+
"lockfileVersion": 1,
+
"workspaces": {
+
"": {
+
"name": "ts",
+
"devDependencies": {
+
"@types/bun": "latest",
+
},
+
"peerDependencies": {
+
"typescript": "^5",
+
},
+
},
+
},
+
"packages": {
+
"@types/bun": ["@types/bun@1.3.1", "", { "dependencies": { "bun-types": "1.3.1" } }, "sha512-4jNMk2/K9YJtfqwoAa28c8wK+T7nvJFOjxI4h/7sORWcypRNxBpr+TPNaCfVWq70tLCJsqoFwcf0oI0JU/fvMQ=="],
+
+
"@types/node": ["@types/node@24.9.2", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA=="],
+
+
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
+
+
"bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
+
+
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
+
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
+
+
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
+
}
+
}
+56
2015/3/ts/index.ts
···
+
type Direction = "^" | "v" | "<" | ">";
+
interface Location {
+
x: number;
+
y: number;
+
}
+
type World = Map<string, number>;
+
type Turn = "Santa" | "Robo";
+
+
function giveGift(world: World, location: Location) {
+
const locationString = JSON.stringify(location);
+
return world.set(locationString, (world.get(locationString) ?? 0) + 1);
+
}
+
+
function moveTo(location: Location, direction: Direction) {
+
if (direction === "^") {
+
location.y -= 1;
+
} else if (direction === "v") {
+
location.y += 1;
+
} else if (direction === "<") {
+
location.x -= 1;
+
} else if (direction === ">") {
+
location.x += 1;
+
}
+
return location;
+
}
+
+
const input = (await Bun.file("../input.txt").text())
+
.trim()
+
.split("") as Direction[];
+
+
// the gleam one is so much better...
+
// part 1
+
{
+
const location: Location = { x: 0, y: 0 };
+
const world: World = new Map();
+
input.forEach((direction) => {
+
giveGift(world, location);
+
moveTo(location, direction);
+
});
+
console.log(world.size);
+
}
+
+
// part 2
+
{
+
const santa_location: Location = { x: 0, y: 0 };
+
const robo_location: Location = { x: 0, y: 0 };
+
const world: World = new Map();
+
let turn: Turn = "Santa";
+
const location = () => (turn === "Santa" ? santa_location : robo_location);
+
input.forEach((direction) => {
+
giveGift(world, location());
+
moveTo(location(), direction);
+
turn = turn === "Santa" ? "Robo" : "Santa";
+
});
+
console.log(world.size);
+
}
+15
2015/3/ts/package.json
···
+
{
+
"name": "ts",
+
"module": "index.ts",
+
"type": "module",
+
"scripts": {
+
"start": "bun index.ts"
+
},
+
"private": true,
+
"devDependencies": {
+
"@types/bun": "latest"
+
},
+
"peerDependencies": {
+
"typescript": "^5"
+
}
+
}
+29
2015/3/ts/tsconfig.json
···
+
{
+
"compilerOptions": {
+
// Environment setup & latest features
+
"lib": ["ESNext"],
+
"target": "ESNext",
+
"module": "Preserve",
+
"moduleDetection": "force",
+
"jsx": "react-jsx",
+
"allowJs": true,
+
+
// Bundler mode
+
"moduleResolution": "bundler",
+
"allowImportingTsExtensions": true,
+
"verbatimModuleSyntax": true,
+
"noEmit": true,
+
+
// Best practices
+
"strict": true,
+
"skipLibCheck": true,
+
"noFallthroughCasesInSwitch": true,
+
"noUncheckedIndexedAccess": true,
+
"noImplicitOverride": true,
+
+
// Some stricter flags (disabled by default)
+
"noUnusedLocals": false,
+
"noUnusedParameters": false,
+
"noPropertyAccessFromIndexSignature": false
+
}
+
}
+27
flake.lock
···
+
{
+
"nodes": {
+
"nixpkgs": {
+
"locked": {
+
"lastModified": 1761880412,
+
"narHash": "sha256-QoJjGd4NstnyOG4mm4KXF+weBzA2AH/7gn1Pmpfcb0A=",
+
"owner": "nixos",
+
"repo": "nixpkgs",
+
"rev": "a7fc11be66bdfb5cdde611ee5ce381c183da8386",
+
"type": "github"
+
},
+
"original": {
+
"owner": "nixos",
+
"ref": "nixpkgs-unstable",
+
"repo": "nixpkgs",
+
"type": "github"
+
}
+
},
+
"root": {
+
"inputs": {
+
"nixpkgs": "nixpkgs"
+
}
+
}
+
},
+
"root": "root",
+
"version": 7
+
}
+28
flake.nix
···
+
{
+
description = "advent_of_code";
+
+
inputs = {
+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
+
};
+
+
outputs = {
+
self,
+
nixpkgs,
+
}: let
+
forAllSystems = function:
+
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
+
system: function nixpkgs.legacyPackages.${system}
+
);
+
in {
+
#packages = forAllSystems (pkgs: {
+
# example = pkgs.callPackage ./default.nix { };
+
# default = self.packages.${pkgs.stdenv.hostPlatform.system}.example;
+
#});
+
+
devShells = forAllSystems (pkgs: {
+
default = pkgs.callPackage ./shell.nix {inherit pkgs;};
+
});
+
+
#overlays.default = final: _: {example = final.callPackage ./default.nix {};};
+
};
+
}
+15
shell.nix
···
+
{pkgs}:
+
#let
+
# defaultPackage = callPackage ./default.nix { };
+
#in
+
pkgs.mkShellNoCC {
+
#inputsFrom = [ defaultPackage ];
+
+
packages = with pkgs; [
+
bun
+
+
gleam
+
beam28Packages.erlang
+
beam28Packages.rebar3
+
];
+
}
+20
template/gleam/gleam.toml
···
+
name = "main"
+
version = "1.0.0"
+
+
# Fill out these fields if you intend to generate HTML documentation or publish
+
# your project to the Hex package manager.
+
#
+
# description = ""
+
# licences = ["Apache-2.0"]
+
# repository = { type = "github", user = "", repo = "" }
+
# links = [{ title = "Website", href = "" }]
+
#
+
# For a full reference of all the available options, you can have a look at
+
# https://gleam.run/writing-gleam/gleam-toml/.
+
+
[dependencies]
+
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
+
simplifile = ">= 2.3.0 and < 3.0.0"
+
+
[dev-dependencies]
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
template/gleam/manifest.toml
···
+
# This file was generated by Gleam
+
# You typically do not need to edit this file
+
+
packages = [
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
+
]
+
+
[requirements]
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+8
template/gleam/src/main.gleam
···
+
import gleam/result.{unwrap}
+
import gleam/string.{trim}
+
import simplifile.{read}
+
+
pub fn main() {
+
let input = read(from: "../input.txt") |> unwrap("") |> trim()
+
echo input
+
}
+29
template/ts/bun.lock
···
+
{
+
"lockfileVersion": 1,
+
"workspaces": {
+
"": {
+
"name": "ts",
+
"devDependencies": {
+
"@types/bun": "latest",
+
},
+
"peerDependencies": {
+
"typescript": "^5",
+
},
+
},
+
},
+
"packages": {
+
"@types/bun": ["@types/bun@1.3.1", "", { "dependencies": { "bun-types": "1.3.1" } }, "sha512-4jNMk2/K9YJtfqwoAa28c8wK+T7nvJFOjxI4h/7sORWcypRNxBpr+TPNaCfVWq70tLCJsqoFwcf0oI0JU/fvMQ=="],
+
+
"@types/node": ["@types/node@24.9.2", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA=="],
+
+
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
+
+
"bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
+
+
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
+
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
+
+
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
+
}
+
}
+1
template/ts/index.ts
···
+
const input = (await Bun.file("../input.txt").text()).trim();
+15
template/ts/package.json
···
+
{
+
"name": "ts",
+
"module": "index.ts",
+
"type": "module",
+
"scripts": {
+
"start": "bun index.ts"
+
},
+
"private": true,
+
"devDependencies": {
+
"@types/bun": "latest"
+
},
+
"peerDependencies": {
+
"typescript": "^5"
+
}
+
}
+29
template/ts/tsconfig.json
···
+
{
+
"compilerOptions": {
+
// Environment setup & latest features
+
"lib": ["ESNext"],
+
"target": "ESNext",
+
"module": "Preserve",
+
"moduleDetection": "force",
+
"jsx": "react-jsx",
+
"allowJs": true,
+
+
// Bundler mode
+
"moduleResolution": "bundler",
+
"allowImportingTsExtensions": true,
+
"verbatimModuleSyntax": true,
+
"noEmit": true,
+
+
// Best practices
+
"strict": true,
+
"skipLibCheck": true,
+
"noFallthroughCasesInSwitch": true,
+
"noUncheckedIndexedAccess": true,
+
"noImplicitOverride": true,
+
+
// Some stricter flags (disabled by default)
+
"noUnusedLocals": false,
+
"noUnusedParameters": false,
+
"noPropertyAccessFromIndexSignature": false
+
}
+
}