feat: day1

This commit is contained in:
2025-12-06 14:23:03 +00:00
parent c906d26046
commit d6a3b812eb
12 changed files with 9622 additions and 0 deletions

1
Day1/P2/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

7
Day1/P2/Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "P1"
version = "0.1.0"

6
Day1/P2/Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "P1"
version = "0.1.0"
edition = "2024"
[dependencies]

10
Day1/P2/example Normal file
View File

@@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

37
Day1/P2/src/main.rs Normal file
View File

@@ -0,0 +1,37 @@
use std::fs;
fn main() {
println!("Day 1P2");
let contents = fs::read_to_string("test").expect("input not found");
let mut value = 50;
let mut hits = 0;
for line in contents.strip_suffix("\n").unwrap().split("\n") {
let mut line_iter = line.chars();
let left = match line_iter.next().unwrap() {
'R' => false,
'L' => true,
_ => panic!("What the actual fuck"),
};
let turns_str = line_iter.as_str();
let turns: i64 = turns_str.parse().unwrap();
// There's probably a rust way to not mess with the types here
let dir = match left {
true => -1,
false => 1,
};
hits += turns / 100;
let bonus = match value {
0 => 0,
_ => 1,
};
value += dir * (turns % 100);
if !(0..=99).contains(&value) {
hits += bonus;
}
if value == 0 {
hits += 1;
}
value = value.rem_euclid(100);
}
println!("Yipee {hits}")
}

4753
Day1/P2/test Normal file

File diff suppressed because it is too large Load Diff