From db6a729799adc0c820307ea40e71a2e08b4d65fd Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Wed, 13 Mar 2024 16:23:04 +0000 Subject: [PATCH] 2019: Elide passing arguments Intcode already has access to Now that `fetch_instruction` is an associated function, Intcode has access to the program's memory. --- 2019/src/intcode.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/2019/src/intcode.rs b/2019/src/intcode.rs index bd8e0b8..d71afe9 100644 --- a/2019/src/intcode.rs +++ b/2019/src/intcode.rs @@ -30,7 +30,8 @@ impl Computer { } } - fn fetch_instruction(&self, memory: &[i32]) -> Instruction { + fn fetch_instruction(&self) -> Instruction { + let memory = &self.memory[self.ip..]; let opcode = memory[0]; match opcode { 1 => Instruction::Add( @@ -50,7 +51,7 @@ impl Computer { pub fn run(&mut self) { loop { - let instruction = self.fetch_instruction(&self.memory[self.ip..]); + let instruction = self.fetch_instruction(); match instruction { Instruction::Add(addr1, addr2, dst) => { self.memory[dst] = self.memory[addr1] + self.memory[addr2];