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

idk if im gonna keep doing the ts ones - day 4 2015 gleam

aylac.top 2658a98b e6cd4b0a

verified
Changed files
+163 -1
2015
template
gleam
+22
2015/4/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 + gleam_crypto = ">= 1.5.1 and < 2.0.0" 19 + gleam_yielder = ">= 1.1.0 and < 2.0.0" 20 + 21 + [dev-dependencies] 22 + gleeunit = ">= 1.0.0 and < 2.0.0"
+18
2015/4/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_crypto", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "50774BAFFF1144E7872814C566C5D653D83A3EBF23ACC3156B757A1B6819086E" }, 7 + { name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" }, 8 + { name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" }, 9 + { name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" }, 10 + { name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" }, 11 + ] 12 + 13 + [requirements] 14 + gleam_crypto = { version = ">= 1.5.1 and < 2.0.0" } 15 + gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } 16 + gleam_yielder = { version = ">= 1.1.0 and < 2.0.0" } 17 + gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 18 + simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+42
2015/4/gleam/src/main.gleam
··· 1 + import gleam/bit_array 2 + import gleam/crypto.{Md5, hash} 3 + import gleam/int.{to_string} 4 + import gleam/io.{println} 5 + import gleam/result.{unwrap} 6 + import gleam/string.{trim} 7 + import gleam/yielder.{Next, find, unfold} 8 + import simplifile.{read} 9 + 10 + // claude just helped me with understanding how yield works. didn't want to add that 1 manually because it's ugly. here's my pure mine attempt 11 + // let res = 12 + // yielder.unfold(0, fn(v) { 13 + // let hash = 14 + // crypto.hash(Md5, <<{ input <> to_string(v) }:utf8>>) 15 + // |> bit_array.base16_encode 16 + // 17 + // case hash { 18 + // "00000" <> _ -> yielder.Done 19 + // ______ -> yielder.Next(v, v + 1) 20 + // } 21 + // }) 22 + // |> yielder.last() 23 + // |> unwrap(0) 24 + // |> int.add(1) 25 + // |> to_string 26 + 27 + pub fn find_first_with_leading(input: String, leading: String) { 28 + unfold(0, fn(v) { Next(v, v + 1) }) 29 + |> find(fn(v) { 30 + hash(Md5, <<{ input <> to_string(v) }:utf8>>) 31 + |> bit_array.base16_encode 32 + |> string.starts_with(leading) 33 + }) 34 + |> unwrap(0) 35 + |> to_string 36 + } 37 + 38 + pub fn main() { 39 + let input = read(from: "../input.txt") |> unwrap("") |> trim() 40 + println(find_first_with_leading(input, "00000")) 41 + println(find_first_with_leading(input, "000000")) 42 + }
+29
2015/4/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/4/ts/index.ts
··· 1 + const input = (await Bun.file("../input.txt").text()).trim();
+15
2015/4/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/4/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 + }
+7 -1
template/gleam/src/main.gleam
··· 1 + import gleam/int.{to_string} 2 + import gleam/io.{println} 1 3 import gleam/result.{unwrap} 2 4 import gleam/string.{trim} 3 5 import simplifile.{read} 4 6 5 7 pub fn main() { 6 8 let input = read(from: "../input.txt") |> unwrap("") |> trim() 7 - echo input 9 + 10 + println( 11 + 5 12 + |> to_string, 13 + ) 8 14 }