2025 day1 part1
This commit is contained in:
parent
e81fba0172
commit
c1700fda5f
2 changed files with 64 additions and 0 deletions
57
aoc2025/day1.rs
Normal file
57
aoc2025/day1.rs
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
use utils::load_string;
|
||||||
|
|
||||||
|
const TEST_INPUT: &str =
|
||||||
|
"L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82";
|
||||||
|
|
||||||
|
const START: u32 = 50;
|
||||||
|
|
||||||
|
enum Rotation {
|
||||||
|
Left(u32),
|
||||||
|
Right(u32),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse(input: &str) -> Vec<Rotation> {
|
||||||
|
input.lines().map(|l| {
|
||||||
|
let (indicator, number) = l.split_at(1);
|
||||||
|
match indicator {
|
||||||
|
"L" => Rotation::Left(number.parse().unwrap()),
|
||||||
|
"R" => Rotation::Right(number.parse().unwrap()),
|
||||||
|
_ => panic!("hey!")
|
||||||
|
}
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn part1() -> u32 {
|
||||||
|
let input = &load_string("inputs/2025/day1.input");
|
||||||
|
//let input = TEST_INPUT;
|
||||||
|
let mut current_rotation = START;
|
||||||
|
let mut result: u32 = 0;
|
||||||
|
for roation in parse(input).iter() {
|
||||||
|
match roation {
|
||||||
|
Rotation::Left(amount) => {
|
||||||
|
// overflows to the left
|
||||||
|
current_rotation = (((current_rotation as i32) - *amount as i32).rem_euclid(100)) as u32;
|
||||||
|
},
|
||||||
|
Rotation::Right(amount) => {
|
||||||
|
// overflows to the right
|
||||||
|
current_rotation = (((current_rotation as i32) + *amount as i32).rem_euclid(100)) as u32;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if current_rotation == 0 {
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
pub fn part2() -> u32 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,10 @@
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
// Yoinked from https://github.com/loafey/advent_of_code/blob/master/utils/lib.rs
|
||||||
|
pub fn load_string<P: AsRef<Path>>(p: P) -> String {
|
||||||
|
std::fs::read_to_string(&p).unwrap_or_else(|_| panic!("failed to load {:?}", p.as_ref()))
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Matrix {
|
pub trait Matrix {
|
||||||
fn transpose(self) -> Self;
|
fn transpose(self) -> Self;
|
||||||
fn reverse_rows(self) -> Self;
|
fn reverse_rows(self) -> Self;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue