Skip to content

Commit

Permalink
2019: Elide passing arguments Intcode already has access to
Browse files Browse the repository at this point in the history
Now that `fetch_instruction` is an associated function, Intcode has
access to the program's memory.
  • Loading branch information
ericvw committed Mar 14, 2024
1 parent aef2c38 commit db6a729
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions 2019/src/intcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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];
Expand Down

0 comments on commit db6a729

Please sign in to comment.