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

2025 day 2 damn i was stuck in part 2 because of the > 1 thingie thats so dumb

aylac.top 96ebcdbb 9c99620b

verified
Changed files
+105
2025
+20
2025/2/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
2025/2/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" }
+71
2025/2/gleam/src/main.gleam
··· 1 + import gleam/int 2 + import gleam/io 3 + import gleam/list 4 + import gleam/result 5 + import gleam/string 6 + import simplifile as file 7 + 8 + type Range { 9 + Range(start: Int, end: Int) 10 + } 11 + 12 + pub fn main() { 13 + let assert Ok(input) = file.read(from: "../input.txt") 14 + as "Input file not found" 15 + // let input = 16 + // "11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124" 17 + let input = 18 + input 19 + |> string.trim 20 + |> string.split(",") 21 + |> list.map(fn(s) { 22 + case string.split(s, "-") { 23 + [start, end] -> 24 + Range( 25 + start |> int.parse |> result.unwrap(0), 26 + end |> int.parse |> result.unwrap(0), 27 + ) 28 + _ -> panic as "invalid input" 29 + } 30 + }) 31 + 32 + // input 33 + // |> list.fold(0, fn(acc, r) { 34 + // list.range(r.start, r.end) 35 + // |> list.fold(acc, fn(acc, i) { 36 + // let s = int.to_string(i) 37 + // let len = string.length(s) 38 + // case string.slice(s, 0, len / 2) |> string.repeat(2) == s { 39 + // True -> acc + i 40 + // False -> acc 41 + // } 42 + // }) 43 + // }) 44 + // |> int.to_string 45 + // |> io.println 46 + 47 + input 48 + |> list.fold(0, fn(acc, r) { 49 + list.range(r.start, r.end) 50 + |> list.fold(acc, fn(acc, i) { 51 + let s = int.to_string(i) 52 + let len = string.length(s) 53 + case len > 1 { 54 + True -> 55 + list.range(len / 2, 1) 56 + |> list.fold_until(acc, fn(acc, cur_len) { 57 + let n = 58 + string.slice(s, 0, cur_len) 59 + |> string.repeat(len / cur_len) 60 + case n == s { 61 + True -> list.Stop(acc + i) 62 + False -> list.Continue(acc) 63 + } 64 + }) 65 + False -> acc 66 + } 67 + }) 68 + }) 69 + |> int.to_string 70 + |> io.println 71 + }