2025 day1 par2
This commit is contained in:
parent
1f2d6a2d01
commit
ab95fe9024
1 changed files with 54 additions and 18 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
use utils::load_string;
|
use utils::load_string;
|
||||||
|
|
||||||
const TEST_INPUT: &str =
|
const TEST_INPUT: &str = "L68
|
||||||
"L68
|
|
||||||
L30
|
L30
|
||||||
R48
|
R48
|
||||||
L5
|
L5
|
||||||
|
|
@ -12,7 +11,7 @@ L99
|
||||||
R14
|
R14
|
||||||
L82";
|
L82";
|
||||||
|
|
||||||
const START: u32 = 50;
|
const START: i32 = 50;
|
||||||
|
|
||||||
enum Rotation {
|
enum Rotation {
|
||||||
Left(u32),
|
Left(u32),
|
||||||
|
|
@ -20,41 +19,78 @@ enum Rotation {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(input: &str) -> Vec<Rotation> {
|
fn parse(input: &str) -> Vec<Rotation> {
|
||||||
input.lines().map(|l| {
|
input
|
||||||
|
.lines()
|
||||||
|
.map(|l| {
|
||||||
let (indicator, number) = l.split_at(1);
|
let (indicator, number) = l.split_at(1);
|
||||||
match indicator {
|
match indicator {
|
||||||
"L" => Rotation::Left(number.parse().unwrap()),
|
"L" => Rotation::Left(number.parse().unwrap()),
|
||||||
"R" => Rotation::Right(number.parse().unwrap()),
|
"R" => Rotation::Right(number.parse().unwrap()),
|
||||||
_ => panic!("hey!")
|
_ => panic!("hey!"),
|
||||||
}
|
}
|
||||||
}).collect()
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gaby() -> (u32, u32) {
|
fn gaby() -> (u32, u32) {
|
||||||
|
let input = TEST_INPUT;
|
||||||
let input = &load_string("inputs/2025/day1.input");
|
let input = &load_string("inputs/2025/day1.input");
|
||||||
//let input = TEST_INPUT;
|
|
||||||
let mut current_rotation = START;
|
let mut current_rotation = START;
|
||||||
let mut result_part1: u32 = 0;
|
let mut result_part1: u32 = 0;
|
||||||
let mut result_part2: u32 = 0;
|
let mut result_part2: u32 = 0;
|
||||||
|
|
||||||
for roation in parse(input).iter() {
|
for roation in parse(input).iter() {
|
||||||
match roation {
|
match roation {
|
||||||
Rotation::Left(amount) => {
|
Rotation::Left(amount) => {
|
||||||
// overflows to the left
|
for _ in 0..*amount {
|
||||||
let new = (current_rotation as i32) - *amount as i32;
|
current_rotation -= 1;
|
||||||
current_rotation = new.rem_euclid(100) as u32;
|
if current_rotation < 0 {
|
||||||
result_part2 += ((new.abs() + if new < 0 {100} else {0}) / 100) as u32;
|
current_rotation = 99;
|
||||||
},
|
|
||||||
Rotation::Right(amount) => {
|
|
||||||
// overflows to the right
|
|
||||||
let new = (current_rotation as i32) + *amount as i32;
|
|
||||||
current_rotation = new.rem_euclid(100) as u32;
|
|
||||||
result_part2 += (new / 100) as u32;
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
if current_rotation == 0 {
|
||||||
|
result_part2 += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Rotation::Right(amount) => {
|
||||||
|
for _ in 0..*amount {
|
||||||
|
current_rotation += 1;
|
||||||
|
if current_rotation >= 100 {
|
||||||
|
current_rotation = 0;
|
||||||
|
}
|
||||||
|
if current_rotation == 0 {
|
||||||
|
result_part2 += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if current_rotation == 0 {
|
if current_rotation == 0 {
|
||||||
result_part1 += 1;
|
result_part1 += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//for roation in parse(input).iter() {
|
||||||
|
// match roation {
|
||||||
|
// Rotation::Left(amount) => {
|
||||||
|
// // overflows to the left
|
||||||
|
// let new = (current_rotation as i32) - *amount as i32;
|
||||||
|
// result_part2 += (((new.abs() + if new <= 0 { 100 } else { 0 }) / 100)
|
||||||
|
// + if current_rotation == 0 { -1 } else { 0 })
|
||||||
|
// .max(0) as u32;
|
||||||
|
// current_rotation = new.rem_euclid(100) as u32;
|
||||||
|
// }
|
||||||
|
// Rotation::Right(amount) => {
|
||||||
|
// // overflows to the right
|
||||||
|
// let new = (current_rotation as i32) + *amount as i32;
|
||||||
|
// result_part2 +=
|
||||||
|
// ((new / 100) + if current_rotation == 0 { -1 } else { 0 }).max(0) as u32;
|
||||||
|
// current_rotation = new.rem_euclid(100) as u32;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if current_rotation == 0 {
|
||||||
|
// result_part1 += 1;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
(result_part1, result_part2)
|
(result_part1, result_part2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue