From 9cc9b5d0dca515123e9b388f194cf3011a44813a Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Tue, 12 Dec 2023 22:40:05 +0100 Subject: [PATCH] fix subtraction --- src/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index ae86212..41b3570 100644 --- a/src/main.rs +++ b/src/main.rs @@ -159,20 +159,19 @@ impl SandWormInterpreter { self.worm_in.push(instruction - 48); dont_push_instruction = true; } - // b'0'..=b'9' => self.grow(instruction - 48), b'+' => { let a = self.shrink(); self.worm_out.push(instruction); let b = self.shrink(); dont_push_instruction = true; - self.worm_in.push(a + b); + self.worm_in.push(a.wrapping_add(b)); } b'-' => { let a = self.shrink(); self.worm_out.push(instruction); dont_push_instruction = true; let b = self.shrink(); - self.worm_in.push(a + b); + self.worm_in.push(a.wrapping_sub(b)); } b'v' => self.direction = Direction::Down, b'^' => self.direction = Direction::Up,