my aoc solutions
0
fork

Configure Feed

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

day 5 pt 1

+79 -8
+20 -8
src/aoc_2025/day_4.gleam
··· 37 37 Empty -> False 38 38 Roll -> { 39 39 let #(row, column) = coord 40 + 41 + // top row 40 42 let top_left = 41 - dict.get(warehouse, #(row - 1, column - 1)) |> result.unwrap(Empty) 43 + dict.get(warehouse, #(row - 1, column - 1)) 44 + |> result.unwrap(Empty) 42 45 let top_middle = 43 - dict.get(warehouse, #(row - 1, column)) |> result.unwrap(Empty) 46 + dict.get(warehouse, #(row - 1, column)) 47 + |> result.unwrap(Empty) 44 48 let top_right = 45 - dict.get(warehouse, #(row - 1, column + 1)) |> result.unwrap(Empty) 49 + dict.get(warehouse, #(row - 1, column + 1)) 50 + |> result.unwrap(Empty) 46 51 52 + // both sides 47 53 let left_middle = 48 - dict.get(warehouse, #(row, column - 1)) |> result.unwrap(Empty) 54 + dict.get(warehouse, #(row, column - 1)) 55 + |> result.unwrap(Empty) 49 56 let right_middle = 50 - dict.get(warehouse, #(row, column + 1)) |> result.unwrap(Empty) 57 + dict.get(warehouse, #(row, column + 1)) 58 + |> result.unwrap(Empty) 51 59 60 + // bottom row 52 61 let bottom_left = 53 - dict.get(warehouse, #(row + 1, column - 1)) |> result.unwrap(Empty) 62 + dict.get(warehouse, #(row + 1, column - 1)) 63 + |> result.unwrap(Empty) 54 64 let bottom_middle = 55 - dict.get(warehouse, #(row + 1, column)) |> result.unwrap(Empty) 65 + dict.get(warehouse, #(row + 1, column)) 66 + |> result.unwrap(Empty) 56 67 let bottom_right = 57 - dict.get(warehouse, #(row + 1, column + 1)) |> result.unwrap(Empty) 68 + dict.get(warehouse, #(row + 1, column + 1)) 69 + |> result.unwrap(Empty) 58 70 59 71 [ 60 72 top_left,
+59
src/aoc_2025/day_5.gleam
··· 1 + import gleam/int 2 + import gleam/list 3 + import gleam/result 4 + import gleam/string 5 + 6 + pub fn parse(input: String) -> #(List(#(Int, Int)), List(Int)) { 7 + let assert Ok(#(Ok(ranges), Ok(available))) = { 8 + use #(ranges, available) <- result.try(string.split_once(input, "\n\n")) 9 + 10 + let ranges = 11 + ranges 12 + |> string.split("\n") 13 + |> list.map(fn(range) { 14 + use #(start, end) <- result.try(string.split_once(range, "-")) 15 + 16 + use start <- result.try(int.parse(start)) 17 + use end <- result.try(int.parse(end)) 18 + 19 + Ok(#(start, end)) 20 + }) 21 + |> result.all() 22 + 23 + let available = 24 + available 25 + |> string.split("\n") 26 + |> list.map(int.parse) 27 + |> result.all() 28 + 29 + Ok(#(ranges, available)) 30 + } 31 + as "Invalid input" 32 + 33 + #(ranges, available) 34 + } 35 + 36 + pub fn pt_1(input: #(List(#(Int, Int)), List(Int))) { 37 + let #(ranges, available) = input 38 + 39 + available 40 + |> list.fold(0, fn(acc, item) { 41 + let in_any_range = 42 + ranges 43 + |> list.any(fn(range) { 44 + case range { 45 + #(start, end) if item >= start && item <= end -> True 46 + _ -> False 47 + } 48 + }) 49 + 50 + case in_any_range { 51 + True -> acc + 1 52 + False -> acc 53 + } 54 + }) 55 + } 56 + 57 + pub fn pt_2(input: #(List(#(Int, Int)), List(Int))) { 58 + todo as "part 2 not implemented" 59 + }