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

this is all so ugly...

aylac.top fd8c61e2 ecf8623a

verified
+20
2015/7/gleam/gleam.toml
··· 1 + name = "main" 2 + version = "1.0.0" 3 + 4 + # Fill out these fields if you intend to generate HTML documentation or publish 5 + # your project to the Hex package manager. 6 + # 7 + # description = "" 8 + # licences = ["Apache-2.0"] 9 + # repository = { type = "github", user = "", repo = "" } 10 + # links = [{ title = "Website", href = "" }] 11 + # 12 + # For a full reference of all the available options, you can have a look at 13 + # https://gleam.run/writing-gleam/gleam-toml/. 14 + 15 + [dependencies] 16 + gleam_stdlib = ">= 0.44.0 and < 2.0.0" 17 + simplifile = ">= 2.3.0 and < 3.0.0" 18 + 19 + [dev-dependencies] 20 + gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2015/7/gleam/manifest.toml
··· 1 + # This file was generated by Gleam 2 + # You typically do not need to edit this file 3 + 4 + packages = [ 5 + { name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" }, 6 + { name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" }, 7 + { name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" }, 8 + { name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" }, 9 + ] 10 + 11 + [requirements] 12 + gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } 13 + gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 14 + simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+117
2015/7/gleam/src/main.gleam
··· 1 + import gleam/dict.{type Dict} 2 + import gleam/int.{to_string} 3 + import gleam/io.{println} 4 + import gleam/list.{fold} 5 + import gleam/result.{unwrap} 6 + import gleam/string.{split, trim} 7 + import simplifile.{read} 8 + 9 + pub type Circuit = 10 + Dict(String, Operation) 11 + 12 + pub type CircuitCache = 13 + Dict(String, Int) 14 + 15 + pub type Operation { 16 + Not(var: String) 17 + And(var1: String, var2: String) 18 + Or(var1: String, var2: String) 19 + Rshift(var: String, n: Int) 20 + Lshift(var: String, n: Int) 21 + Set(n: String) 22 + OpError 23 + } 24 + 25 + pub type GetCircRes { 26 + GetCircRes(value: Int, cache: CircuitCache) 27 + } 28 + 29 + pub fn get_circuit_var( 30 + circuit: Circuit, 31 + name: String, 32 + cache: CircuitCache, 33 + ) -> GetCircRes { 34 + let get = fn(name, cache) { get_circuit_var(circuit, name, cache) } 35 + 36 + let parsed_name = int.base_parse(name, 10) 37 + let GetCircRes(value, cache) = case result.is_ok(parsed_name) { 38 + True -> GetCircRes(parsed_name |> unwrap(0), cache) 39 + False -> { 40 + case dict.get(cache, name) { 41 + Ok(value) -> GetCircRes(value, cache) 42 + Error(_) -> { 43 + case dict.get(circuit, name) |> unwrap(OpError) { 44 + Not(var) -> { 45 + let GetCircRes(value, cache) = get(var, cache) 46 + GetCircRes(int.bitwise_not(value), cache) 47 + } 48 + And(var1, var2) -> { 49 + let GetCircRes(value1, cache) = get(var1, cache) 50 + let GetCircRes(value2, cache) = get(var2, cache) 51 + GetCircRes(int.bitwise_and(value1, value2), cache) 52 + } 53 + Or(var1, var2) -> { 54 + let GetCircRes(value1, cache) = get(var1, cache) 55 + let GetCircRes(value2, cache) = get(var2, cache) 56 + GetCircRes(int.bitwise_or(value1, value2), cache) 57 + } 58 + Rshift(var, n) -> { 59 + let GetCircRes(value, cache) = get(var, cache) 60 + GetCircRes(int.bitwise_shift_right(value, n), cache) 61 + } 62 + Lshift(var, n) -> { 63 + let GetCircRes(value, cache) = get(var, cache) 64 + GetCircRes(int.bitwise_shift_left(value, n), cache) 65 + } 66 + Set(var) -> get(var, cache) 67 + OpError -> GetCircRes(0, cache) 68 + } 69 + } 70 + } 71 + } 72 + } 73 + GetCircRes(value, dict.insert(cache, name, value)) 74 + } 75 + 76 + pub fn main() { 77 + let input: Circuit = 78 + read(from: "../input.txt") 79 + |> unwrap("") 80 + |> trim() 81 + |> split("\n") 82 + |> fold(dict.new(), fn(circ, v) { 83 + case split(v, " ") { 84 + ["NOT", var, "->", target] -> dict.insert(circ, target, Not(var)) 85 + [var1, "AND", var2, "->", target] -> 86 + dict.insert(circ, target, And(var1, var2)) 87 + [var1, "OR", var2, "->", target] -> 88 + dict.insert(circ, target, Or(var1, var2)) 89 + [var, "RSHIFT", n, "->", target] -> 90 + dict.insert( 91 + circ, 92 + target, 93 + Rshift(var, int.base_parse(n, 10) |> unwrap(0)), 94 + ) 95 + [var, "LSHIFT", n, "->", target] -> 96 + dict.insert( 97 + circ, 98 + target, 99 + Lshift(var, int.base_parse(n, 10) |> unwrap(0)), 100 + ) 101 + [v, "->", target] -> dict.insert(circ, target, Set(v)) 102 + 103 + _ -> circ 104 + } 105 + }) 106 + 107 + let result_part_1 = get_circuit_var(input, "a", dict.new()).value 108 + println(result_part_1 |> to_string) 109 + 110 + let result_part_2 = 111 + get_circuit_var( 112 + dict.insert(input, "b", Set(int.to_string(result_part_1))), 113 + "a", 114 + dict.new(), 115 + ).value 116 + println(result_part_2 |> to_string) 117 + }
+29
2015/7/ts/bun.lock
··· 1 + { 2 + "lockfileVersion": 1, 3 + "workspaces": { 4 + "": { 5 + "name": "ts", 6 + "devDependencies": { 7 + "@types/bun": "latest", 8 + }, 9 + "peerDependencies": { 10 + "typescript": "^5", 11 + }, 12 + }, 13 + }, 14 + "packages": { 15 + "@types/bun": ["@types/bun@1.3.1", "", { "dependencies": { "bun-types": "1.3.1" } }, "sha512-4jNMk2/K9YJtfqwoAa28c8wK+T7nvJFOjxI4h/7sORWcypRNxBpr+TPNaCfVWq70tLCJsqoFwcf0oI0JU/fvMQ=="], 16 + 17 + "@types/node": ["@types/node@24.9.2", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA=="], 18 + 19 + "@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="], 20 + 21 + "bun-types": ["bun-types@1.3.1", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="], 22 + 23 + "csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="], 24 + 25 + "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], 26 + 27 + "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="], 28 + } 29 + }
+1
2015/7/ts/index.ts
··· 1 + const input = (await Bun.file("../input.txt").text()).trim();
+15
2015/7/ts/package.json
··· 1 + { 2 + "name": "ts", 3 + "module": "index.ts", 4 + "type": "module", 5 + "scripts": { 6 + "start": "bun index.ts" 7 + }, 8 + "private": true, 9 + "devDependencies": { 10 + "@types/bun": "latest" 11 + }, 12 + "peerDependencies": { 13 + "typescript": "^5" 14 + } 15 + }
+29
2015/7/ts/tsconfig.json
··· 1 + { 2 + "compilerOptions": { 3 + // Environment setup & latest features 4 + "lib": ["ESNext"], 5 + "target": "ESNext", 6 + "module": "Preserve", 7 + "moduleDetection": "force", 8 + "jsx": "react-jsx", 9 + "allowJs": true, 10 + 11 + // Bundler mode 12 + "moduleResolution": "bundler", 13 + "allowImportingTsExtensions": true, 14 + "verbatimModuleSyntax": true, 15 + "noEmit": true, 16 + 17 + // Best practices 18 + "strict": true, 19 + "skipLibCheck": true, 20 + "noFallthroughCasesInSwitch": true, 21 + "noUncheckedIndexedAccess": true, 22 + "noImplicitOverride": true, 23 + 24 + // Some stricter flags (disabled by default) 25 + "noUnusedLocals": false, 26 + "noUnusedParameters": false, 27 + "noPropertyAccessFromIndexSignature": false 28 + } 29 + }