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

day 1 2025 im an idiot

aylac.top 192e424b c56b4780

verified
Changed files
+226 -5
2015
19
2025
+1
.gitignore
···
build
input.txt
input.json
+
input_example.txt
_build
target
+46 -5
2015/19/gleam/src/main.gleam
···
+
import gleam/dict.{type Dict}
import gleam/int
import gleam/io
+
import gleam/list
+
import gleam/result
+
import gleam/set.{type Set}
import gleam/string
import simplifile as file
+
type Results =
+
Set(String)
+
+
type Combinations =
+
Dict(String, Results)
+
pub fn main() {
let assert Ok(input) = file.read(from: "../input.txt")
as "Input file not found"
-
let input = input |> string.trim
-
-
5
-
|> int.to_string
-
|> io.println
+
let input = input |> string.trim |> string.split("\n") |> list.reverse
+
let combinations: Combinations =
+
input
+
|> list.drop(2)
+
|> list.map(fn(v) {
+
case v |> string.split(" ") {
+
[origin, _, result] -> #(origin, result)
+
_ -> #("", "")
+
}
+
})
+
|> list.fold(dict.new(), fn(acc, v) {
+
acc
+
|> dict.get(v.0)
+
|> result.unwrap(set.new())
+
|> set.insert(v.1)
+
|> dict.insert(acc, v.0, _)
+
})
+
let molecule = {
+
let molecule =
+
input
+
|> list.first
+
|> result.unwrap("")
+
|> string.to_graphemes
+
|> list.fold(#(list.new(), ""), fn(acc, letter) {
+
case letter == string.lowercase(letter) {
+
True -> #(acc.0, acc.1 <> letter)
+
False -> #(list.append(acc.0, [acc.1]), letter)
+
}
+
})
+
molecule.0 |> list.drop(1) |> list.append([molecule.1])
+
}
+
let part_1_res = {
+
list.range(1, list.length(molecule)) |> list.fold(set.new(), fn(acc, v) {
+
+
})
+
}
}
+7
2015/19/rust/Cargo.lock
···
+
# This file is automatically @generated by Cargo.
+
# It is not intended for manual editing.
+
version = 4
+
+
[[package]]
+
name = "rust"
+
version = "0.1.0"
+6
2015/19/rust/Cargo.toml
···
+
[package]
+
name = "rust"
+
version = "0.1.0"
+
edition = "2024"
+
+
[dependencies]
+22
2015/19/rust/src/main.rs
···
+
struct Combination {
+
original: String,
+
target: String,
+
}
+
+
fn main() {
+
let input: String = std::fs::read_to_string("../input.txt").expect("invalid input!!");
+
let input: Vec<&str> = input.split("\n").collect();
+
let combinations: Vec<Combination> = &input[..input.len() - 2].iter().map(|v| {
+
let v: Vec<&str> = v.split(" ").collect();
+
match v[..] {
+
[original, _, target] => Combination {
+
original: original.to_string(),
+
target: target.to_string(),
+
},
+
_ => Combination {
+
original: "".to_string(),
+
target: "".to_string(),
+
},
+
}
+
}).
+
}
+20
2025/1/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/1/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" }
+100
2025/1/gleam/src/main.gleam
···
+
import gleam/int
+
import gleam/io
+
import gleam/list
+
import gleam/string
+
import simplifile as file
+
+
pub type Direction {
+
Left
+
Right
+
}
+
+
pub type InputEntry {
+
InputEntry(direction: Direction, turn: Int)
+
}
+
+
pub type RotationState {
+
RotationState(number: Int, zeroes: Int)
+
}
+
+
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")
+
|> list.map(fn(l) {
+
let assert Ok(direction_letter) = string.first(l)
+
let direction = case direction_letter {
+
"R" -> Right
+
"L" -> Left
+
_ -> panic as "bad input"
+
}
+
let assert Ok(turn) = string.drop_start(l, 1) |> int.parse
+
InputEntry(direction, turn)
+
})
+
+
let part1 =
+
input
+
|> list.fold(RotationState(50, 0), fn(acc, v) {
+
let new_number =
+
{
+
acc.number
+
+ case v.direction {
+
Right -> v.turn
+
Left -> -v.turn
+
}
+
}
+
% 100
+
let new_number = case new_number > 0 {
+
True -> new_number
+
False -> 100 + new_number
+
}
+
RotationState(
+
new_number,
+
acc.zeroes
+
+ case new_number {
+
0 -> 1
+
_ -> 0
+
},
+
)
+
})
+
+
part1.zeroes
+
|> int.to_string
+
|> io.println
+
+
let part2 =
+
input
+
|> list.fold(RotationState(50, 0), fn(acc, v) {
+
let raw_new_number = {
+
acc.number
+
+ case v.direction {
+
Right -> v.turn
+
Left -> -v.turn
+
}
+
}
+
// took too long to remember that abs isn't this im so fucking stupid
+
let new_number = raw_new_number % 100
+
let new_number = case new_number > 0 {
+
True -> new_number
+
False -> 100 + new_number
+
}
+
// dumbest fuck in the world??? theres gotta be a mathy way of doing this
+
let times_it_went_zero =
+
list.range(acc.number, raw_new_number)
+
|> list.fold(0, fn(acc2, i) {
+
case i % 100 {
+
0 if i != acc.number -> acc2 + 1
+
_ -> acc2
+
}
+
})
+
echo #(acc.number, raw_new_number, times_it_went_zero)
+
RotationState(new_number, acc.zeroes + times_it_went_zero)
+
})
+
+
part2.zeroes
+
|> int.to_string
+
|> io.println
+
}
+10
2025/1/input_example.txt
···
+
L68
+
L30
+
R48
+
L5
+
R60
+
L55
+
L1
+
L99
+
R14
+
L82