Add solution for "Day 1: Secret Entrance", part 1
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
#[macro_use]
|
||||
extern crate scan_fmt;
|
||||
|
||||
mod common;
|
||||
pub mod solvers;
|
||||
|
||||
+4
-1
@@ -2,7 +2,7 @@ use advent_of_code_2025::solvers;
|
||||
|
||||
fn main() {
|
||||
println!("### Advent of Code 2025 ###\n");
|
||||
// SecretEntrance
|
||||
solvers::run(solvers::secret_entrance::SecretEntrance {});
|
||||
// GiftShop
|
||||
// Lobby
|
||||
solvers::run(solvers::printing_department::PrintingDepartment {});
|
||||
@@ -11,4 +11,7 @@ fn main() {
|
||||
// Laboratories
|
||||
solvers::run(solvers::playground::Playground::new(None));
|
||||
solvers::run(solvers::movie_theater::MovieTheater {});
|
||||
// Factory
|
||||
// Reactor
|
||||
// ChristmasTreeFarm
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ pub mod cafeteria;
|
||||
pub mod movie_theater;
|
||||
pub mod playground;
|
||||
pub mod printing_department;
|
||||
pub mod secret_entrance;
|
||||
pub mod trash_compactor;
|
||||
|
||||
pub trait Solver {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
use crate::solvers::Solver;
|
||||
use std::io::BufRead;
|
||||
|
||||
pub struct SecretEntrance {}
|
||||
|
||||
impl SecretEntrance {
|
||||
const START_POSITION: i32 = 50;
|
||||
const DIAL_SIZE: i32 = 100;
|
||||
const COUNT_POSITION: i32 = 0;
|
||||
const POSITIVE_SIGN_CHAR: char = 'R';
|
||||
const NEGATIVE_SIGN_CHAR: char = 'L';
|
||||
}
|
||||
|
||||
impl Solver for SecretEntrance {
|
||||
const PUZZLE_INDEX: u8 = 1;
|
||||
const PUZZLE_NAME: &'static str = "Secret Entrance";
|
||||
|
||||
fn process_data<R: BufRead>(&self, reader: R) -> (u64, u64) {
|
||||
let mut position = Self::START_POSITION;
|
||||
let mut count = 0;
|
||||
let format = format!(
|
||||
"{{[{}{}]}}{{d}}",
|
||||
Self::POSITIVE_SIGN_CHAR,
|
||||
Self::NEGATIVE_SIGN_CHAR
|
||||
);
|
||||
for line in reader.lines().map_while(Result::ok) {
|
||||
if let Ok((sign, distance)) = scan_fmt!(&line, &format, char, i32) {
|
||||
position = (position
|
||||
+ if sign == Self::POSITIVE_SIGN_CHAR {
|
||||
distance
|
||||
} else {
|
||||
-distance
|
||||
})
|
||||
.rem_euclid(Self::DIAL_SIZE);
|
||||
}
|
||||
if position == Self::COUNT_POSITION {
|
||||
count = count + 1;
|
||||
}
|
||||
}
|
||||
(count, 0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user