summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2019-12-31 21:04:18 +0200
committerJustin Wernick <justin@worthe-it.co.za>2019-12-31 21:04:18 +0200
commitd93d20427b7a15dd07dbb13a4203b8168ee03f6c (patch)
treefb9125ebb9ba02612e6e987c43e0e9a65d805ac3 /src/bin
parent832190583eacad6d0166cbacb71f79fa93aef1d6 (diff)
Springbot walking, running, and jumping!
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/day_21.rs55
1 files changed, 51 insertions, 4 deletions
diff --git a/src/bin/day_21.rs b/src/bin/day_21.rs
index 106ce82..7fa781c 100644
--- a/src/bin/day_21.rs
+++ b/src/bin/day_21.rs
@@ -23,9 +23,17 @@ fn main() {
.map(|x| exit_on_failed_assertion(x.trim().parse::<Intcode>(), "Invalid number"))
.collect::<IntcodeProgram>();
- let result = exit_on_failed_assertion(
+ let walk_result = exit_on_failed_assertion(
{
- let input = vec!["NOT A J\n", "WALK\n"];
+ let input = vec![
+ "NOT T T\n",
+ "AND A T\n",
+ "AND B T\n",
+ "AND C T\n",
+ "NOT T J\n",
+ "AND D J\n",
+ "WALK\n",
+ ];
program
.with_input(
input
@@ -40,7 +48,7 @@ fn main() {
println!(
"{}",
- result
+ walk_result
.drop_last()
.unwrap()
.iter()
@@ -48,7 +56,46 @@ fn main() {
.map(|c| c as char)
.collect::<String>()
);
- println!("{}", result.last().unwrap());
+ println!("{}", walk_result.last().unwrap());
+
+ let run_result = exit_on_failed_assertion(
+ {
+ // (!A || !B || !C) && D && (E || H)
+ let input = vec![
+ "OR E J\n",
+ "OR H J\n",
+ "AND D J\n",
+ "NOT T T\n",
+ "AND A T\n",
+ "AND B T\n",
+ "AND C T\n",
+ "NOT T T\n",
+ "AND T J\n",
+ "RUN\n",
+ ];
+ program
+ .with_input(
+ input
+ .iter()
+ .flat_map(|line| line.chars().map(|c| Intcode::from(c as u8)))
+ .collect(),
+ )
+ .execute()
+ },
+ "Program failed",
+ );
+
+ println!(
+ "{}",
+ run_result
+ .drop_last()
+ .unwrap()
+ .iter()
+ .flat_map(|c| c.to_signed_bytes_be())
+ .map(|c| c as char)
+ .collect::<String>()
+ );
+ println!("{}", run_result.last().unwrap());
}
fn exit_on_failed_assertion<A, E: std::error::Error>(data: Result<A, E>, message: &str) -> A {