my solutions to advent of code
aoc advent-of-code

part 1

aylac.top 7c0cfdee b70ab71c

verified
Changed files
+100
2025
+20
2025/7/gleam/gleam.toml
···
+
name = "main"
+
version = "1.0.0"
+
+
# Fill out these fields if you intend to generate HTML documentation or publish
+
# your project to the Hex package manager.
+
#
+
# description = ""
+
# licences = ["Apache-2.0"]
+
# repository = { type = "github", user = "", repo = "" }
+
# links = [{ title = "Website", href = "" }]
+
#
+
# For a full reference of all the available options, you can have a look at
+
# https://gleam.run/writing-gleam/gleam-toml/.
+
+
[dependencies]
+
gleam_stdlib = ">= 0.44.0 and < 2.0.0"
+
simplifile = ">= 2.3.0 and < 3.0.0"
+
+
[dev-dependencies]
+
gleeunit = ">= 1.0.0 and < 2.0.0"
+14
2025/7/gleam/manifest.toml
···
+
# This file was generated by Gleam
+
# You typically do not need to edit this file
+
+
packages = [
+
{ name = "filepath", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "B06A9AF0BF10E51401D64B98E4B627F1D2E48C154967DA7AF4D0914780A6D40A" },
+
{ name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" },
+
{ name = "gleeunit", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "CD701726CBCE5588B375D157B4391CFD0F2F134CD12D9B6998A395484DE05C58" },
+
{ name = "simplifile", version = "2.3.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0A868DAC6063D9E983477981839810DC2E553285AB4588B87E3E9C96A7FB4CB4" },
+
]
+
+
[requirements]
+
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
+
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+
simplifile = { version = ">= 2.3.0 and < 3.0.0" }
+66
2025/7/gleam/src/main.gleam
···
+
import gleam/dict
+
import gleam/int
+
import gleam/io
+
import gleam/list
+
import gleam/result
+
import gleam/set
+
import gleam/string
+
import simplifile as file
+
+
pub fn main() {
+
let assert Ok(input) = file.read(from: "../input.txt")
+
as "Input file not found"
+
let input = input |> string.trim |> string.split("\n")
+
let assert Ok(start) = input |> list.first
+
let start =
+
start
+
|> string.to_graphemes
+
|> list.index_fold(0, fn(acc, v, i) {
+
case v {
+
"S" -> i
+
_ -> acc
+
}
+
})
+
let splitters =
+
input
+
|> list.drop(1)
+
|> list.index_map(fn(line, i) {
+
case i % 2 {
+
0 -> ""
+
_ -> line
+
}
+
})
+
|> list.filter(fn(line) { line != "" })
+
|> list.map(fn(line) {
+
line
+
|> string.to_graphemes
+
|> list.index_fold(set.new(), fn(d, char, i) {
+
case char {
+
"^" -> set.insert(d, i)
+
_ -> d
+
}
+
})
+
})
+
let #(beams, times) =
+
echo splitters
+
|> list.fold(#(set.new() |> set.insert(start), 0), fn(acc, splitters) {
+
let #(beams, times) = acc
+
beams
+
|> set.fold(#(beams, times), fn(acc, beam) {
+
let #(beams, times) = acc
+
case splitters |> set.contains(beam) {
+
False -> acc
+
True -> {
+
#(
+
beams
+
|> set.delete(beam)
+
|> set.insert(beam - 1)
+
|> set.insert(beam + 1),
+
times + 1,
+
)
+
}
+
}
+
})
+
})
+
echo set.size(beams)
+
}