summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2021-12-24 22:35:20 +0200
committerJustin Wernick <justin@worthe-it.co.za>2021-12-24 22:35:20 +0200
commit152b7cf786f4b567944eaa2ea8e1313a23e200b8 (patch)
treeae99e3e88a865f936d9445242307844c43f35fa1
parent4414ced947994065db36ee5c93346de387e1f2a6 (diff)
Day 24
-rw-r--r--Cargo.lock246
-rw-r--r--Cargo.toml1
-rw-r--r--inputs/day_24.txt252
-rw-r--r--proptest-regressions/bin/day_24.txt11
-rw-r--r--src/bin/day_24.rs588
5 files changed, 1098 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 720bb14..e4c9ba9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9,6 +9,7 @@ dependencies = [
"cached",
"derive_more",
"nom",
+ "proptest",
"thiserror",
]
@@ -33,6 +34,39 @@ dependencies = [
]
[[package]]
+name = "autocfg"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
+
+[[package]]
+name = "bit-set"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
+dependencies = [
+ "bit-vec",
+]
+
+[[package]]
+name = "bit-vec"
+version = "0.6.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
+
+[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "byteorder"
+version = "1.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
+
+[[package]]
name = "cached"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -66,6 +100,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663"
[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
name = "darling"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -213,6 +253,17 @@ dependencies = [
]
[[package]]
+name = "getrandom"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi",
+]
+
+[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -225,6 +276,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
+name = "libc"
+version = "0.2.112"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
+
+[[package]]
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -248,6 +311,15 @@ dependencies = [
]
[[package]]
+name = "num-traits"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
name = "once_cell"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -266,6 +338,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
+name = "ppv-lite86"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba"
+
+[[package]]
name = "proc-macro2"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -275,6 +353,38 @@ dependencies = [
]
[[package]]
+name = "proptest"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e0d9cc07f18492d879586c92b485def06bc850da3118075cd45d50e9c95b0e5"
+dependencies = [
+ "bit-set",
+ "bitflags",
+ "byteorder",
+ "lazy_static",
+ "num-traits",
+ "quick-error 2.0.1",
+ "rand",
+ "rand_chacha",
+ "rand_xorshift",
+ "regex-syntax",
+ "rusty-fork",
+ "tempfile",
+]
+
+[[package]]
+name = "quick-error"
+version = "1.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
+
+[[package]]
+name = "quick-error"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
+
+[[package]]
name = "quote"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -284,6 +394,91 @@ dependencies = [
]
[[package]]
+name = "rand"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
+dependencies = [
+ "libc",
+ "rand_chacha",
+ "rand_core",
+ "rand_hc",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
+dependencies = [
+ "ppv-lite86",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.6.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
+dependencies = [
+ "getrandom",
+]
+
+[[package]]
+name = "rand_hc"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
+dependencies = [
+ "rand_core",
+]
+
+[[package]]
+name = "rand_xorshift"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
+dependencies = [
+ "rand_core",
+]
+
+[[package]]
+name = "redox_syscall"
+version = "0.2.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff"
+dependencies = [
+ "bitflags",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.6.25"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
+
+[[package]]
+name = "remove_dir_all"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "rusty-fork"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f"
+dependencies = [
+ "fnv",
+ "quick-error 1.2.3",
+ "tempfile",
+ "wait-timeout",
+]
+
+[[package]]
name = "slab"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -307,6 +502,20 @@ dependencies = [
]
[[package]]
+name = "tempfile"
+version = "3.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "rand",
+ "redox_syscall",
+ "remove_dir_all",
+ "winapi",
+]
+
+[[package]]
name = "thiserror"
version = "1.0.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -337,3 +546,40 @@ name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
+
+[[package]]
+name = "wait-timeout"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "wasi"
+version = "0.10.2+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/Cargo.toml b/Cargo.toml
index f359858..d5058d2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,7 @@ edition = "2021"
cached = "0.25.0"
derive_more = "0.99.2"
nom = "7.0.0"
+proptest = "1.0.0"
thiserror = "1.0.29"
[profile.release]
diff --git a/inputs/day_24.txt b/inputs/day_24.txt
new file mode 100644
index 0000000..9c0248a
--- /dev/null
+++ b/inputs/day_24.txt
@@ -0,0 +1,252 @@
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 12
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 6
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 10
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 6
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 13
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 3
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -11
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 11
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 13
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 9
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -1
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 3
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 10
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 13
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 11
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 6
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x 0
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 14
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 10
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 10
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -5
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 12
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -16
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 10
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -7
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 11
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -11
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 15
+mul y x
+add z y
diff --git a/proptest-regressions/bin/day_24.txt b/proptest-regressions/bin/day_24.txt
new file mode 100644
index 0000000..c9b9ac2
--- /dev/null
+++ b/proptest-regressions/bin/day_24.txt
@@ -0,0 +1,11 @@
+# Seeds for failure cases proptest has generated in the past. It is
+# automatically read and these particular cases re-run before any
+# novel cases are generated.
+#
+# It is recommended to check this file in to source control so that
+# everyone who runs the test benefits from these saved cases.
+cc 3ff1975a827f0f896df7fad66e81f158bb513003aa57b9392c7be206d91c401e # shrinks to input = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
+cc 34000b524f14fadce85ab48285657651fd5756cb94b8ad9868e068d808705ec5 # shrinks to input = [1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
+cc df520bbe1425f1b68bcd1e837caa8c6cea82fe8ac2fc8f58e3044cace37c5f9e # shrinks to input = [1, 1, 9, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
+cc 2cff9266126660d75f7f6e9c8872fb4a7e91e5225507126c18f4488ebe52d4c4 # shrinks to input = [1, 1, 1, 1, 1, 1, 1, 1, 5, 3, 8, 3, 1, 1]
+cc 113d1afb9c126057c1d0d46b73c603364647fd914104f7c4dd23334d286089c1 # shrinks to input = [1, 1, 1, 1, 1, 1, 1, 2, 8, 2, 7, 6, 1, 1]
diff --git a/src/bin/day_24.rs b/src/bin/day_24.rs
new file mode 100644
index 0000000..2916f57
--- /dev/null
+++ b/src/bin/day_24.rs
@@ -0,0 +1,588 @@
+use nom::{
+ branch::alt,
+ bytes::complete::{is_not, tag},
+ character::complete::{line_ending, space1},
+ combinator::map,
+ multi::separated_list1,
+ sequence::{pair, preceded, separated_pair},
+ IResult,
+};
+use proptest::prelude::*;
+use std::fs;
+
+fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let input = fs::read_to_string("inputs/day_24.txt")?;
+ let program = parse_program(&input).unwrap().1;
+ program.print_oracle();
+
+ // input[2] - 8 == input[3]
+ // input[4] + 8 == input[5]
+ // input[7] + 6 == input[8]
+ // input[9] + 5 == input[10]
+ // input[6] - 3 == input[11]
+ // input[1] - 1 == input[12]
+ // input[0] - 5 == input[13]
+
+ dbg!(refactored([9, 9, 9, 1, 1, 9, 9, 3, 9, 4, 9, 6, 8, 4]).unwrap());
+ dbg!(refactored([6, 2, 9, 1, 1, 9, 4, 1, 7, 1, 6, 1, 1, 1]).unwrap());
+ Ok(())
+}
+
+fn subroutine_1(
+ next_input: i64,
+ running_total: i64,
+ mod_conditional: i64,
+ result_additive: i64,
+) -> i64 {
+ if next_input != (running_total % 26) + mod_conditional {
+ running_total * 26 + next_input + result_additive
+ } else {
+ running_total
+ }
+}
+
+fn subroutine_2(
+ next_input: i64,
+ running_total: i64,
+ mod_conditional: i64,
+ result_additive: i64,
+) -> i64 {
+ if next_input != running_total % 26 + mod_conditional {
+ running_total / 26 * 26 + next_input + result_additive
+ } else {
+ running_total / 26
+ }
+}
+
+fn refactored_one_to_nine_assumption(input: [i64; 14]) -> Result<i64, String> {
+ let mut z = input[0] + 6;
+ // z-stack 1
+ z = z * 26 + input[1] + 6;
+ // z-stack 2
+ z = z * 26 + input[2] + 3;
+ // z-stack 3
+ z = if input[2] - 8 == input[3] {
+ z / 26
+ } else {
+ z / 26 * 26 + input[3] + 11
+ };
+ // z-stack 2
+ z = z * 26 + input[4] + 9;
+ // z-stack 3
+ z = if input[4] + 8 == input[5] {
+ z / 26
+ } else {
+ z / 26 * 26 + input[5] + 3
+ };
+ // z-stack 2
+ z = z * 26 + input[6] + 13;
+ // z-stack 3
+ z = z * 26 + input[7] + 6;
+ // z-stack 4
+ z = if input[7] + 6 == input[8] {
+ z / 26
+ } else {
+ z / 26 * 26 + input[8] + 14
+ };
+ // z-stack 3
+ z = z * 26 + input[9] + 10;
+ // z-stack 4
+ z = if input[9] + 5 == input[10] {
+ z / 26
+ } else {
+ z / 26 * 26 + input[10] + 12
+ };
+ // z-stack 3
+ z = if input[9] + 5 == input[10] {
+ if input[7] + 6 == input[8] {
+ if input[6] + 13 - 16 == input[11] {
+ z / 26
+ } else {
+ z / 26 * 26 + input[11] + 10
+ }
+ } else {
+ if input[8] + 14 - 16 == input[11] {
+ z / 26
+ } else {
+ z / 26 * 26 + input[11] + 10
+ }
+ }
+ } else {
+ if input[10] + 12 - 16 == input[11] {
+ z / 26
+ } else {
+ z / 26 * 26 + input[11] + 10
+ }
+ };
+ // z-stack 2
+ z = subroutine_2(input[12], z, -7, 11);
+ // z-stack 1
+ z = subroutine_2(input[13], z, -11, 15);
+ // z-stack 0
+
+ Ok(z)
+}
+
+fn refactored(input: [i64; 14]) -> Result<i64, String> {
+ let mut z: i64 = 0;
+
+ z = subroutine_1(input[0], z, 12, 6);
+ z = subroutine_1(input[1], z, 10, 6);
+ z = subroutine_1(input[2], z, 13, 3);
+ z = subroutine_2(input[3], z, -11, 11);
+ z = subroutine_1(input[4], z, 13, 9);
+ z = subroutine_2(input[5], z, -1, 3);
+ z = subroutine_1(input[6], z, 10, 13);
+ z = subroutine_1(input[7], z, 11, 6);
+ z = subroutine_2(input[8], z, 0, 14);
+ z = subroutine_1(input[9], z, 10, 10);
+ z = subroutine_2(input[10], z, -5, 12);
+ z = subroutine_2(input[11], z, -16, 10);
+ z = subroutine_2(input[12], z, -7, 11);
+ z = subroutine_2(input[13], z, -11, 15);
+
+ Ok(z)
+}
+
+#[derive(Debug)]
+struct Program(Vec<Instruction>);
+impl Program {
+ fn print_oracle(&self) {
+ println!("fn oracle(input: [i64; 14]) -> Result<i64, String> {{");
+ println!("let mut w: i64 = 0;");
+ println!("let mut x: i64 = 0;");
+ println!("let mut y: i64 = 0;");
+ println!("let mut z: i64 = 0;");
+
+ let mut input_index = 0;
+ for instruction in &self.0 {
+ match instruction {
+ Instruction::Inp(a) => {
+ println!("{} = input[{}];", a, input_index);
+ input_index += 1;
+ }
+ Instruction::Add(a, b) => {
+ println!("{0} = {0} + {1};", a, b);
+ }
+ Instruction::Mul(a, b) => {
+ println!("{0} = {0} * {1};", a, b);
+ }
+ Instruction::Div(a, b) => {
+ println!("if {0} == 0 {{ return Err(\"Div by 0\".into()); }}", b);
+ println!("{0} = {0} / {1};", a, b);
+ }
+ Instruction::Mod(a, b) => {
+ println!("if {0} == 0 {{ return Err(\"Mod by 0\".into()); }}", b);
+ println!("{0} = {0} % {1};", a, b);
+ }
+ Instruction::Eql(a, b) => {
+ println!("{0} = if {0} == {1} {{ 1 }} else {{ 0 }};", a, b);
+ }
+ }
+ }
+ println!("Ok(z)");
+ println!("}}");
+ }
+}
+
+#[derive(Debug)]
+enum Instruction {
+ Inp(String),
+ Add(String, String),
+ Mul(String, String),
+ Div(String, String),
+ Mod(String, String),
+ Eql(String, String),
+}
+
+fn parse_program(input: &str) -> IResult<&str, Program> {
+ map(separated_list1(line_ending, parse_instruction), Program)(input)
+}
+
+fn parse_instruction(input: &str) -> IResult<&str, Instruction> {
+ alt((
+ map(preceded(pair(tag("inp"), space1), word), |a| {
+ Instruction::Inp(a)
+ }),
+ map(
+ preceded(pair(tag("add"), space1), separated_pair(word, space1, word)),
+ |(a, b)| Instruction::Add(a, b),
+ ),
+ map(
+ preceded(pair(tag("mul"), space1), separated_pair(word, space1, word)),
+ |(a, b)| Instruction::Mul(a, b),
+ ),
+ map(
+ preceded(pair(tag("div"), space1), separated_pair(word, space1, word)),
+ |(a, b)| Instruction::Div(a, b),
+ ),
+ map(
+ preceded(pair(tag("mod"), space1), separated_pair(word, space1, word)),
+ |(a, b)| Instruction::Mod(a, b),
+ ),
+ map(
+ preceded(pair(tag("eql"), space1), separated_pair(word, space1, word)),
+ |(a, b)| Instruction::Eql(a, b),
+ ),
+ ))(input)
+}
+
+fn word(input: &str) -> IResult<&str, String> {
+ map(is_not(" \t\r\n"), |s: &str| s.to_string())(input)
+}
+
+#[allow(unused_assignments)]
+fn oracle(input: [i64; 14]) -> Result<i64, String> {
+ let mut w: i64 = 0;
+ let mut x: i64 = 0;
+ let mut y: i64 = 0;
+ let mut z: i64 = 0;
+ w = input[0];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 1 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 1;
+ x = x + 12;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 6;
+ y = y * x;
+ z = z + y;
+ w = input[1];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 1 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 1;
+ x = x + 10;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 6;
+ y = y * x;
+ z = z + y;
+ w = input[2];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 1 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 1;
+ x = x + 13;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 3;
+ y = y * x;
+ z = z + y;
+ w = input[3];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 26 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 26;
+ x = x + -11;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 11;
+ y = y * x;
+ z = z + y;
+ w = input[4];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 1 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 1;
+ x = x + 13;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 9;
+ y = y * x;
+ z = z + y;
+ w = input[5];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 26 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 26;
+ x = x + -1;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 3;
+ y = y * x;
+ z = z + y;
+ w = input[6];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 1 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 1;
+ x = x + 10;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 13;
+ y = y * x;
+ z = z + y;
+ w = input[7];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 1 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 1;
+ x = x + 11;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 6;
+ y = y * x;
+ z = z + y;
+ w = input[8];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 26 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 26;
+ x = x + 0;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 14;
+ y = y * x;
+ z = z + y;
+ w = input[9];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 1 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 1;
+ x = x + 10;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 10;
+ y = y * x;
+ z = z + y;
+ w = input[10];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 26 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 26;
+ x = x + -5;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 12;
+ y = y * x;
+ z = z + y;
+ w = input[11];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 26 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 26;
+ x = x + -16;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 10;
+ y = y * x;
+ z = z + y;
+ w = input[12];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 26 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 26;
+ x = x + -7;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 11;
+ y = y * x;
+ z = z + y;
+ w = input[13];
+ x = x * 0;
+ x = x + z;
+ if 26 == 0 {
+ return Err("Mod by 0".into());
+ }
+ x = x % 26;
+ if 26 == 0 {
+ return Err("Div by 0".into());
+ }
+ z = z / 26;
+ x = x + -11;
+ x = if x == w { 1 } else { 0 };
+ x = if x == 0 { 1 } else { 0 };
+ y = y * 0;
+ y = y + 25;
+ y = y * x;
+ y = y + 1;
+ z = z * y;
+ y = y * 0;
+ y = y + w;
+ y = y + 15;
+ y = y * x;
+ z = z + y;
+ Ok(z)
+}
+
+proptest! {
+ #[test]
+ fn oracle_matches_refactored(input in proptest::array::uniform14(1i64..10)) {
+ let oracle_result = oracle(input.clone());
+ let refactored_result = refactored(input.clone());
+ let refactored_one_to_nine_assumption_result = refactored_one_to_nine_assumption(input);
+ assert_eq!(oracle_result, refactored_result);
+ assert_eq!(oracle_result, refactored_one_to_nine_assumption_result);
+ }
+}