summaryrefslogtreecommitdiff
path: root/src/bin/day_2.rs
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2019-12-14 20:59:58 +0200
committerJustin Wernick <justin@worthe-it.co.za>2019-12-14 20:59:58 +0200
commit5c60610b768b98113ca8ca5e8f833fa42d5aa4cf (patch)
tree9c4573be2e1d6a626152880e568085d62d3340aa /src/bin/day_2.rs
parent754a9a4e220b039770b12cb0803b0b0ad3133555 (diff)
Intcode computer to use bigints and unlimited memory space!
Also started a more complete error reporting scheme.
Diffstat (limited to 'src/bin/day_2.rs')
-rw-r--r--src/bin/day_2.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/bin/day_2.rs b/src/bin/day_2.rs
index ce8fcaa..ba9e189 100644
--- a/src/bin/day_2.rs
+++ b/src/bin/day_2.rs
@@ -41,7 +41,9 @@ fn main() {
match (opt.noun, opt.verb, opt.output) {
(Some(noun), Some(verb), _) => {
let result = exit_on_failed_assertion(
- program.with_noun_verb_input(noun, verb).execute(),
+ program
+ .with_noun_verb_input(noun, verb)
+ .execute_returning_memory_0(),
"Program errored",
);
println!("{}", result);
@@ -52,7 +54,8 @@ fn main() {
println!("({}, {})", noun, verb);
}
(None, None, None) => {
- let result = exit_on_failed_assertion(program.execute(), "Program errored");
+ let result =
+ exit_on_failed_assertion(program.execute_returning_memory_0(), "Program errored");
println!("{}", result);
}
_ => {
@@ -77,17 +80,17 @@ fn find_input(
output: Intcode,
) -> Result<(Intcode, Intcode), IntcodeProgramError> {
(0..99)
- .flat_map(|noun| (0..99).map(move |verb| (noun, verb)))
+ .flat_map(|noun| (0..99).map(move |verb| (Intcode::from(noun), Intcode::from(verb))))
.map(|(noun, verb)| {
(
- noun,
- verb,
+ noun.clone(),
+ verb.clone(),
program
.with_noun_verb_input(noun, verb)
.execute_returning_memory_0(),
)
})
- .find(|(_noun, _verb, out)| *out == Ok(Some(output)))
+ .find(|(_noun, _verb, out)| *out == Ok(output.clone()))
.map(|(noun, verb, _out)| Ok((noun, verb)))
- .unwrap_or(Err(IntcodeProgramError))
+ .unwrap_or(Err(IntcodeProgramError::Unknown))
}