day1 part1

This commit is contained in:
2025-12-02 02:55:56 +01:00
commit 43be07c4f4
6 changed files with 205 additions and 0 deletions

32
src/day1.rs Normal file
View File

@@ -0,0 +1,32 @@
#[aoc(day1, part1)]
pub fn part1(input: &str) -> i32 {
let mut dial_counter = DialCounter {
position: 50,
zero_count: 0,
};
for line in input.lines() {
dial_counter.rotate(line)
}
dial_counter.zero_count
}
struct DialCounter {
position: i32,
zero_count: i32,
}
impl DialCounter {
fn rotate(&mut self, operation: &str) {
self.position = match operation.chars().nth(0).unwrap() {
'L' => (self.position - operation[1..].parse::<i32>().unwrap()) % 100,
'R' => (self.position + operation[1..].parse::<i32>().unwrap()) % 100,
_ => panic!("Unexpected input!"),
};
if self.position == 0 {
self.zero_count = self.zero_count + 1;
}
}
}
#[cfg(test)]
mod tests {}