feat: day1
This commit is contained in:
1
Day1/P1/.gitignore
vendored
Normal file
1
Day1/P1/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
7
Day1/P1/Cargo.lock
generated
Normal file
7
Day1/P1/Cargo.lock
generated
Normal 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/P1/Cargo.toml
Normal file
6
Day1/P1/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "P1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
10
Day1/P1/example
Normal file
10
Day1/P1/example
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
31
Day1/P1/src/main.rs
Normal file
31
Day1/P1/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
use std::fs;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Day 1P1");
|
||||||
|
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 mut left = true;
|
||||||
|
match line_iter.next().unwrap() {
|
||||||
|
'R' => {
|
||||||
|
left = false;
|
||||||
|
}
|
||||||
|
'L' => {}
|
||||||
|
_ => 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,
|
||||||
|
};
|
||||||
|
value = (value + turns * dir) % 100;
|
||||||
|
if value == 0 {
|
||||||
|
hits += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("Yipee {hits}")
|
||||||
|
}
|
||||||
4753
Day1/P1/test
Normal file
4753
Day1/P1/test
Normal file
File diff suppressed because it is too large
Load Diff
1
Day1/P2/.gitignore
vendored
Normal file
1
Day1/P2/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
7
Day1/P2/Cargo.lock
generated
Normal file
7
Day1/P2/Cargo.lock
generated
Normal 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
6
Day1/P2/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "P1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
10
Day1/P2/example
Normal file
10
Day1/P2/example
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
37
Day1/P2/src/main.rs
Normal file
37
Day1/P2/src/main.rs
Normal 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
4753
Day1/P2/test
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user