advent of code 2025 in gleam!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

day 2 both parts

+68 -5
+2
src/advent_2025.gleam
··· 1 1 import day1 2 + import day2 2 3 import gleam/io 3 4 4 5 pub fn main() { 5 6 day1.day1main() 7 + day2.day2main() 6 8 }
+21 -5
src/day1.gleam
··· 1 1 import gleam/int 2 + import gleam/io 2 3 import gleam/list 3 4 import gleam/string 4 5 import herbie ··· 12 13 |> string.split("\n") 13 14 14 15 let moves = list.map(file, signed) 15 - list.fold(moves, #(50, 0), make_move) 16 + list.fold(moves, #(50, 0), part1move) 16 17 |> echo 18 + list.fold(moves, #(50, 0), part2move) 19 + |> echo 20 + // nonsense() 17 21 } 18 22 19 - fn crosses_zero(starting: Int, move: Int) -> Int { 20 - todo 21 - } 23 + // fn nonsense() { 24 + // echo -123 / 100 25 + // echo -123 % 100 26 + // } 22 27 23 - fn make_move(acc: #(Int, Int), move: Int) -> #(Int, Int) { 28 + fn part2move(acc: #(Int, Int), move: Int) -> #(Int, Int) { 24 29 let position = { acc.0 + move + 100 } % 100 30 + let zeroes = case position { 31 + 0 -> acc.1 + 1 32 + _ -> acc.1 33 + } 34 + #(position, zeroes) 35 + } 36 + 37 + fn part1move(acc: #(Int, Int), move: Int) -> #(Int, Int) { 38 + let position = 39 + { acc.0 + move + 100 } % 100 40 + |> echo 25 41 let zeroes = case position { 26 42 0 -> acc.1 + 1 27 43 _ -> acc.1
+45
src/day2.gleam
··· 1 + import gleam/int 2 + import gleam/io 3 + import gleam/list 4 + import gleam/regexp 5 + import gleam/string 6 + import herbie as h 7 + import simplifile 8 + 9 + pub fn day2main() { 10 + let assert Ok(file) = simplifile.read("./data/day2") 11 + let ranges = 12 + file 13 + |> string.trim() 14 + |> string.split(",") 15 + |> list.flat_map(fn(x) { 16 + let assert [start, finish] = string.trim(x) |> string.split("-") 17 + list.range(h.quickint(start), h.quickint(finish)) 18 + }) 19 + 20 + let part_1 = 21 + list.filter(ranges, part1_filter) 22 + |> list.fold(0, int.add) 23 + |> int.to_string 24 + 25 + let part_2 = 26 + list.filter(ranges, part2_filter) 27 + |> list.fold(0, int.add) 28 + |> int.to_string 29 + 30 + io.println("Part 1: " <> part_1 <> "\nPart 2: " <> part_2) 31 + } 32 + 33 + fn part2_filter(input: Int) -> Bool { 34 + let pid = int.to_string(input) 35 + let assert Ok(re) = regexp.from_string("^(\\d+)\\1+$") 36 + regexp.check(re, pid) 37 + } 38 + 39 + fn part1_filter(input: Int) -> Bool { 40 + let pid = int.to_string(input) 41 + let is_even = string.length(pid) % 2 == 0 42 + let half = string.slice(pid, 0, string.length(pid) / 2) 43 + let halfsies = pid == half <> half 44 + halfsies && is_even 45 + }