SHA256
feat: day1
This commit is contained in:
12 files changed
+9622
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
Generated
+7
@@ -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"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "P1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
@@ -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
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
Generated
+7
@@ -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"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "P1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
@@ -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
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user