summaryrefslogtreecommitdiff
path: root/2025/aa.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-12-01 20:07:41 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-12-01 20:07:41 +0800
commitb55ea16baba3f387a1eece3b60adcbd4db98f6be (patch)
tree5809aa9bfd92b64fb51429ba3258c2996d9a7970 /2025/aa.rs
parent8128b4edcaca761585f6ab81c7c4a9aaff763532 (diff)
init: 2025
Diffstat (limited to '2025/aa.rs')
-rw-r--r--2025/aa.rs75
1 files changed, 75 insertions, 0 deletions
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
+ );
+}