2019: intcode: rename method to get last output
This commit is contained in:
parent
83fa28b21d
commit
d02364731d
|
@ -21,7 +21,7 @@ fn part1(input: &str) -> Result<i64> {
|
|||
intcode.add_input(1);
|
||||
intcode.run()?;
|
||||
intcode
|
||||
.get_day05_output()
|
||||
.get_last_output()
|
||||
.ok_or_else(|| err!("intcode gave no output"))
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ fn part2(input: &str) -> Result<i64> {
|
|||
intcode.add_input(5);
|
||||
intcode.run()?;
|
||||
intcode
|
||||
.get_day05_output()
|
||||
.get_last_output()
|
||||
.ok_or_else(|| err!("intcode gave no output"))
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ fn part1(input: &str) -> Result<i64> {
|
|||
intcode.run()?;
|
||||
|
||||
output = intcode
|
||||
.get_day05_output()
|
||||
.get_last_output()
|
||||
.ok_or_else(|| err!("no output at end of pipeline!"))?;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ fn part1(memory: Vec<i64>) -> Result<i64> {
|
|||
intcode.add_input(1);
|
||||
intcode.run()?;
|
||||
intcode
|
||||
.get_day05_output()
|
||||
.get_last_output()
|
||||
.ok_or_else(|| err!("intcode output was empty!"))
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ fn part2(memory: Vec<i64>) -> Result<i64> {
|
|||
intcode.add_input(2);
|
||||
intcode.run()?;
|
||||
intcode
|
||||
.get_day05_output()
|
||||
.get_last_output()
|
||||
.ok_or_else(|| err!("intcode output was empty!"))
|
||||
}
|
||||
|
||||
|
|
|
@ -263,15 +263,7 @@ impl Intcode {
|
|||
self.memory.get(0).copied()
|
||||
}
|
||||
|
||||
pub fn get_day05_output(&self) -> Option<i64> {
|
||||
for (i, out) in self.output.iter().enumerate() {
|
||||
if i < self.output.len() - 1 {
|
||||
assert_eq!(*out, 0);
|
||||
} else {
|
||||
return Some(*out);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
pub fn get_last_output(&self) -> Option<i64> {
|
||||
self.output.last().copied()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue