Advent of Code 2025
0
fork

Configure Feed

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

day 5 part 1

+48 -1
+1 -1
README.md
··· 14 14 | 02 | ⭐ | ⭐ | 15 15 | 03 | ⭐ | ⭐ | 16 16 | 04 | ⭐ | ⭐ | 17 - | 05 | | | 17 + | 05 | ⭐ | | 18 18 | 06 | | | 19 19 | 07 | | | 20 20 | 08 | | |
+41
src/aoc_2025/day_5.gleam
··· 1 + import aoc_2025/util 2 + import gleam/list 3 + import gleam/string 4 + 5 + pub type Input { 6 + Input(ranges: List(#(Int, Int)), ids: List(Int)) 7 + } 8 + 9 + pub fn parse(input: String) -> Input { 10 + let lines = string.split(input, "\n") 11 + 12 + let #(ranges, ids) = { 13 + let #(ranges, ids) = lines |> list.split_while(fn(line) { line != "" }) 14 + 15 + #(ranges, list.drop(ids, 1)) 16 + } 17 + 18 + let ranges = 19 + list.map(ranges, fn(range_str) { 20 + let assert [start, end] = string.split(range_str, "-") 21 + 22 + #(util.int_from_string(start), util.int_from_string(end)) 23 + }) 24 + 25 + let ids = list.map(ids, util.int_from_string) 26 + 27 + Input(ranges, ids) 28 + } 29 + 30 + pub fn pt_1(input: Input) -> Int { 31 + let Input(ranges:, ids:) = input 32 + 33 + ids 34 + |> list.count(fn(id) { 35 + list.any(ranges, fn(range) { id >= range.0 && id <= range.1 }) 36 + }) 37 + } 38 + 39 + pub fn pt_2(input: Input) { 40 + todo as "part 2 not implemented" 41 + }
+6
src/aoc_2025/util.gleam
··· 1 + import gleam/int 2 + 3 + pub fn int_from_string(num: String) -> Int { 4 + let assert Ok(num) = int.parse(num) 5 + num 6 + }