From b55ea16baba3f387a1eece3b60adcbd4db98f6be Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 1 Dec 2025 20:07:41 +0800 Subject: init: 2025 --- 2025/aa.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 2025/aa.rs (limited to '2025/aa.rs') diff --git a/2025/aa.rs b/2025/aa.rs new file mode 100644 index 0000000..1982912 --- /dev/null +++ b/2025/aa.rs @@ -0,0 +1,75 @@ +use aoc::read::read; + +#[derive(Debug)] +struct Ring { + inner: usize, + counter: usize, +} + +impl Ring { + fn new() -> Self { + Self { + inner: 50, // start in 50 + counter: Default::default(), + } + } + + const MAX: usize = 99; + // minus + fn left(&mut self, num: usize) { + for _ in 0..num { + if self.inner == 0 { + self.inner = Self::MAX; + } else { + self.inner -= 1; + } + } + self.counter(); + } + + // plus + fn right(&mut self, num: usize) { + for _ in 0..num { + if self.inner == Self::MAX { + self.inner = 0; + } else { + self.inner += 1; + } + } + self.counter(); + } + + fn counter(&mut self) { + if self.inner == 0 { + self.counter += 1; + } + } +} + +pub fn main() { + let mut ring = Ring::new(); + let input = read("a"); + for i in input { + let dir = i + .chars() + .next() + .unwrap(); + let num = i[1..] + .parse() + .unwrap(); + + match dir { + 'L' => ring.left(num), + 'R' => ring.right(num), + _ => {} + } + println!( + "{}: {:#?}", + num, ring + ) + } + println!( + "Result: {}", + ring.counter + ); +} -- cgit v1.2.3