๐ŸŽ„ advent of code 2025
1
fork

Configure Feed

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

day2 part2 gleam

okk.moe f443f7ed 1f8770c0

verified
+27 -8
-1
day1/day1.gleam
··· 1 - import gleam/bit_array 2 1 import gleam/int 3 2 import gleam/io 4 3 import gleam/list
+5 -5
day1/day1.js
··· 1 1 const input = (await Bun.file("input.txt").text()).trim().split("\n") 2 2 3 3 const result = input.reduce( 4 - ([pos, part1, part2], x) => { 4 + ([pos, p1, p2], x) => { 5 5 const dir = x[0] === "L" ? -1 : 1 6 6 const amount = +x.slice(1) 7 7 const new_pos = (((dir * amount + pos) % 100) + 100) % 100 8 - const new_part1 = part1 + (new_pos === 0) 9 - const new_part2 = 10 - part2 + 8 + const new_p1 = p1 + (new_pos === 0) 9 + const new_p2 = 10 + p2 + 11 11 parseInt((dir === -1 ? ((100 - pos) % 100) + amount : pos + amount) / 100) 12 - return [new_pos, new_part1, new_part2] 12 + return [new_pos, new_p1, new_p2] 13 13 }, 14 14 [50, 0, 0], 15 15 )
+22 -2
day2/day2.gleam
··· 1 - import gleam/bit_array 1 + import gleam/bool 2 2 import gleam/int 3 3 import gleam/io 4 4 import gleam/list 5 - import gleam/result 6 5 import gleam/string 7 6 import simplifile 8 7 ··· 33 32 |> int.sum 34 33 35 34 io.println("Part 1: " <> int.to_string(part1)) 35 + 36 + let part2 = 37 + list.flat_map(input, fn(x) { 38 + list.filter(x, fn(y) { 39 + use <- bool.guard(y < 10, False) 40 + let y = 41 + int.to_string(y) 42 + |> string.to_graphemes 43 + let length = list.length(y) 44 + list.range(1, length / 2) 45 + |> list.any(fn(w) { 46 + case list.sized_chunk(y, w) |> list.unique { 47 + [_] -> True 48 + _ -> False 49 + } 50 + }) 51 + }) 52 + }) 53 + |> int.sum 54 + 55 + io.println("Part 2: " <> int.to_string(part2)) 36 56 }