Advent of Code 2025
0
fork

Configure Feed

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

day 7 part 1

+78 -1
+1 -1
README.md
··· 16 16 | 04 | ⭐ | ⭐ | 17 17 | 05 | ⭐ | ⭐ | 18 18 | 06 | ⭐ | ⭐ | 19 - | 07 | | | 19 + | 07 | ⭐ | | 20 20 | 08 | | | 21 21 | 09 | | | 22 22 | 10 | | |
+77
src/aoc_2025/day_7.gleam
··· 1 + import gleam/list 2 + import gleam/option.{None, Some} 3 + import gleam/pair 4 + import gleam/set 5 + import gleam/string 6 + 7 + pub type Input { 8 + Input(start_index: Int, splitters: List(List(Int))) 9 + } 10 + 11 + pub fn parse(input: String) -> Input { 12 + let assert [first, ..rest] = 13 + input 14 + |> string.split("\n") 15 + 16 + let start_index = { 17 + let assert Ok(s_codepoint) = string.utf_codepoint(83) 18 + 19 + let assert Some(s) = 20 + first 21 + |> string.to_utf_codepoints 22 + |> list.index_fold(None, fn(acc, c, idx) { 23 + case c == s_codepoint { 24 + True -> Some(idx) 25 + _ -> acc 26 + } 27 + }) 28 + 29 + s 30 + } 31 + 32 + let splitters = { 33 + let assert Ok(c_codepoint) = string.utf_codepoint(94) 34 + rest 35 + |> list.map(fn(line) { 36 + line 37 + |> string.to_utf_codepoints 38 + |> list.index_fold([], fn(acc, c, idx) { 39 + case c == c_codepoint { 40 + True -> [idx, ..acc] 41 + False -> acc 42 + } 43 + }) 44 + }) 45 + } 46 + 47 + Input(start_index:, splitters:) 48 + } 49 + 50 + pub fn pt_1(input: Input) -> Int { 51 + let Input(start_index:, splitters:) = input 52 + 53 + splitters 54 + |> list.fold(#(set.from_list([start_index]), 0), fn(acc, row) { 55 + list.fold(row, acc, fn(acc, splitter) { 56 + let #(rays, split_count) = acc 57 + 58 + case set.contains(rays, splitter) { 59 + True -> { 60 + let new_rays = 61 + rays 62 + |> set.delete(splitter) 63 + |> set.insert(splitter + 1) 64 + |> set.insert(splitter - 1) 65 + 66 + #(new_rays, split_count + 1) 67 + } 68 + False -> acc 69 + } 70 + }) 71 + }) 72 + |> pair.second 73 + } 74 + 75 + pub fn pt_2(input: Input) { 76 + todo as "part 2 not implemented" 77 + }