summaryrefslogtreecommitdiff
path: root/2025/ab.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-12-03 22:51:44 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-12-04 09:08:47 +0800
commit4250e02b0f08e3389fdef0500de08ab74ffa2611 (patch)
tree063b75d1c0eca72bf7419b304df1735e8e6a11bc /2025/ab.rs
parentc8780d06a13dd08bccc1ce29e0b7cd60ff65f259 (diff)
refactor: structure of each day
Diffstat (limited to '2025/ab.rs')
-rw-r--r--2025/ab.rs69
1 files changed, 0 insertions, 69 deletions
diff --git a/2025/ab.rs b/2025/ab.rs
deleted file mode 100644
index bafd2ae..0000000
--- a/2025/ab.rs
+++ /dev/null
@@ -1,69 +0,0 @@
-use aoc::fetch::fetch;
-
-#[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 = fetch(1, '\n');
- 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);
-}