๐ŸŽ„ advent of code 2025

day6 part1 gleam

okkdev 72ccf9c6 dcc80430

Changed files
+36
day6
+36
day6/day6.gleam
··· 1 + import gleam/int 2 + import gleam/io 3 + import gleam/list 4 + import gleam/result 5 + import gleam/string 6 + import simplifile 7 + 8 + pub fn main() { 9 + let assert Ok(raw_input) = simplifile.read("src/day6/test.txt") 10 + 11 + let input = 12 + string.trim(raw_input) 13 + |> string.split("\n") 14 + |> list.map(fn(line) { 15 + string.split(line, " ") |> list.filter(fn(e) { e != "" }) 16 + }) 17 + |> list.transpose 18 + 19 + let part1 = 20 + list.map(input, fn(col) { 21 + case list.reverse(col) { 22 + ["*", ..rest] -> 23 + list.fold(rest, 1, fn(acc, x) { 24 + acc * { int.parse(x) |> result.unwrap(1) } 25 + }) 26 + ["+", ..rest] -> 27 + list.fold(rest, 0, fn(acc, x) { 28 + acc + { int.parse(x) |> result.unwrap(0) } 29 + }) 30 + _ -> panic 31 + } 32 + }) 33 + |> int.sum 34 + 35 + io.println("Part 1: " <> int.to_string(part1)) 36 + }