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

day 5 2015

aylac.top 1e1855d6 2658a98b

verified
+21
2015/5/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_regexp = ">= 1.1.1 and < 2.0.0" 19 + 20 + [dev-dependencies] 21 + gleeunit = ">= 1.0.0 and < 2.0.0"
+16
2015/5/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_regexp", version = "1.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "9C215C6CA84A5B35BB934A9B61A9A306EC743153BE2B0425A0D032E477B062A9" }, 7 + { name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" }, 8 + { name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" }, 9 + { name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" }, 10 + ] 11 + 12 + [requirements] 13 + gleam_regexp = { version = ">= 1.1.1 and < 2.0.0" } 14 + gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" } 15 + gleeunit = { version = ">= 1.0.0 and < 2.0.0" } 16 + simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+55
2015/5/gleam/src/main.gleam
··· 1 + import gleam/int.{to_string} 2 + import gleam/io.{println} 3 + import gleam/list.{fold} 4 + import gleam/regexp.{check} 5 + import gleam/result.{unwrap} 6 + import gleam/string.{split, trim} 7 + import simplifile.{read} 8 + 9 + // regex feels like cheating idk 10 + 11 + pub fn is_nice_part_1(str: String) { 12 + let assert Ok(has_three_vowels) = 13 + regexp.from_string(".*?[aeiou].*?[aeiou].*?[aeiou].*?") 14 + let assert Ok(has_doubled_letter) = regexp.from_string("([a-z])\\1") 15 + let assert Ok(has_bad_string) = regexp.from_string("(ab|cd|pq|xy)") 16 + 17 + { has_three_vowels |> check(str) } 18 + && { has_doubled_letter |> check(str) } 19 + && !{ has_bad_string |> check(str) } 20 + } 21 + 22 + pub fn is_nice_part_2(str: String) { 23 + let assert Ok(has_doubled_pair) = regexp.from_string("([a-z])[a-z]\\1") 24 + let assert Ok(has_letter1_letter2_letter1) = 25 + regexp.from_string("([a-z][a-z]).*?\\1") 26 + 27 + { has_doubled_pair |> check(str) } 28 + && { has_letter1_letter2_letter1 |> check(str) } 29 + } 30 + 31 + pub fn main() { 32 + let input = read(from: "../input.txt") |> unwrap("") |> trim |> split("\n") 33 + 34 + println( 35 + input 36 + |> fold(0, fn(acc, str) { 37 + case is_nice_part_1(str) { 38 + True -> acc + 1 39 + False -> acc 40 + } 41 + }) 42 + |> to_string, 43 + ) 44 + 45 + println( 46 + input 47 + |> fold(0, fn(acc, str) { 48 + case is_nice_part_2(str) { 49 + True -> acc + 1 50 + False -> acc 51 + } 52 + }) 53 + |> to_string, 54 + ) 55 + }
+29
2015/5/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/5/ts/index.ts
··· 1 + const input = (await Bun.file("../input.txt").text()).trim();
+15
2015/5/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/5/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 + }