day 16 solution
parent
d707a1412c
commit
ed5cb25a6d
|
@ -0,0 +1,278 @@
|
|||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "day16"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pretty_env_logger 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.5.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "pretty_env_logger"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "redox_termios"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termion"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ucd-util"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "utf8-ranges"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "wincolor"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9a933f4e58658d7b12defcf96dc5c720f20832deebe3e0a19efd3b6aaeeb9e"
|
||||
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
|
||||
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
|
||||
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
|
||||
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
|
||||
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
|
||||
"checksum libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)" = "023a4cd09b2ff695f9734c1934145a315594b7986398496841c7031a5a1bbdbd"
|
||||
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
|
||||
"checksum memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db4c41318937f6e76648f42826b1d9ade5c09cafb5aef7e351240a70f39206e9"
|
||||
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
|
||||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||
"checksum pretty_env_logger 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8d1e63042e889b85228620629b51c011d380eed2c7e0015f8a644def280c28"
|
||||
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
|
||||
"checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2"
|
||||
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||
"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f"
|
||||
"checksum regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4e47a2ed29da7a9e1960e1639e7a982e6edc6d49be308a3b02daf511504a16d1"
|
||||
"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
|
||||
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c"
|
||||
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
|
||||
"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
|
||||
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
|
||||
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba"
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "day16"
|
||||
version = "0.1.0"
|
||||
authors = ["Andrew Coleman <penguincoder@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.2"
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,850 @@
|
|||
1 0 0 1
|
||||
4 1 1 1
|
||||
14 0 0 3
|
||||
14 3 2 2
|
||||
12 3 2 1
|
||||
1 1 2 1
|
||||
11 1 0 0
|
||||
3 0 2 1
|
||||
14 2 2 0
|
||||
9 0 2 0
|
||||
1 0 2 0
|
||||
11 0 1 1
|
||||
3 1 2 3
|
||||
1 1 0 0
|
||||
4 0 1 0
|
||||
14 1 1 1
|
||||
14 2 0 2
|
||||
3 0 2 2
|
||||
1 2 1 2
|
||||
11 2 3 3
|
||||
3 3 2 0
|
||||
14 1 3 3
|
||||
14 3 1 1
|
||||
14 3 0 2
|
||||
4 3 1 3
|
||||
1 3 3 3
|
||||
11 3 0 0
|
||||
14 2 0 2
|
||||
14 0 0 3
|
||||
7 3 2 3
|
||||
1 3 2 3
|
||||
11 3 0 0
|
||||
3 0 3 3
|
||||
14 2 3 0
|
||||
14 3 0 2
|
||||
14 0 1 1
|
||||
14 2 1 1
|
||||
1 1 3 1
|
||||
1 1 2 1
|
||||
11 1 3 3
|
||||
3 3 2 1
|
||||
1 3 0 2
|
||||
4 2 0 2
|
||||
14 2 2 3
|
||||
5 0 3 3
|
||||
1 3 3 3
|
||||
11 3 1 1
|
||||
3 1 0 0
|
||||
14 2 1 2
|
||||
14 3 2 1
|
||||
14 2 0 3
|
||||
0 1 3 3
|
||||
1 3 2 3
|
||||
11 0 3 0
|
||||
3 0 0 2
|
||||
14 1 3 3
|
||||
14 3 3 0
|
||||
4 3 1 0
|
||||
1 0 2 0
|
||||
1 0 2 0
|
||||
11 2 0 2
|
||||
14 0 1 0
|
||||
1 0 0 1
|
||||
4 1 1 1
|
||||
1 1 0 3
|
||||
4 3 2 3
|
||||
13 1 3 3
|
||||
1 3 2 3
|
||||
11 2 3 2
|
||||
14 3 3 1
|
||||
1 1 0 3
|
||||
4 3 2 3
|
||||
14 2 1 0
|
||||
14 3 0 1
|
||||
1 1 3 1
|
||||
11 1 2 2
|
||||
3 2 2 0
|
||||
14 3 3 2
|
||||
14 2 3 1
|
||||
14 1 0 3
|
||||
1 3 2 1
|
||||
1 1 1 1
|
||||
11 0 1 0
|
||||
14 2 3 2
|
||||
14 2 3 3
|
||||
14 0 3 1
|
||||
2 2 3 2
|
||||
1 2 1 2
|
||||
1 2 1 2
|
||||
11 0 2 0
|
||||
3 0 1 1
|
||||
1 2 0 2
|
||||
4 2 0 2
|
||||
14 2 3 0
|
||||
14 3 2 3
|
||||
0 3 0 2
|
||||
1 2 1 2
|
||||
11 2 1 1
|
||||
3 1 1 0
|
||||
14 0 1 1
|
||||
14 3 3 2
|
||||
1 1 0 3
|
||||
4 3 1 3
|
||||
4 3 1 1
|
||||
1 1 1 1
|
||||
11 1 0 0
|
||||
3 0 3 1
|
||||
14 2 0 3
|
||||
14 0 1 2
|
||||
14 2 2 0
|
||||
5 0 3 0
|
||||
1 0 2 0
|
||||
11 0 1 1
|
||||
3 1 0 3
|
||||
14 2 1 0
|
||||
14 3 2 2
|
||||
1 1 0 1
|
||||
4 1 2 1
|
||||
9 0 2 0
|
||||
1 0 1 0
|
||||
1 0 2 0
|
||||
11 0 3 3
|
||||
3 3 0 1
|
||||
14 2 1 3
|
||||
14 0 2 2
|
||||
1 3 0 0
|
||||
4 0 2 0
|
||||
12 2 3 2
|
||||
1 2 2 2
|
||||
11 2 1 1
|
||||
14 3 2 2
|
||||
14 0 0 3
|
||||
9 0 2 3
|
||||
1 3 3 3
|
||||
1 3 2 3
|
||||
11 1 3 1
|
||||
3 1 1 2
|
||||
14 1 2 3
|
||||
14 2 1 1
|
||||
14 3 0 0
|
||||
0 0 1 3
|
||||
1 3 1 3
|
||||
11 3 2 2
|
||||
14 1 3 3
|
||||
14 2 0 0
|
||||
15 0 3 1
|
||||
1 1 3 1
|
||||
11 1 2 2
|
||||
1 0 0 1
|
||||
4 1 3 1
|
||||
14 2 2 3
|
||||
6 0 1 1
|
||||
1 1 3 1
|
||||
11 2 1 2
|
||||
3 2 0 1
|
||||
14 2 0 2
|
||||
14 1 3 0
|
||||
2 2 3 3
|
||||
1 3 3 3
|
||||
11 3 1 1
|
||||
14 1 3 3
|
||||
14 2 1 0
|
||||
1 1 0 2
|
||||
4 2 3 2
|
||||
15 0 3 0
|
||||
1 0 3 0
|
||||
1 0 2 0
|
||||
11 0 1 1
|
||||
14 3 0 0
|
||||
1 3 0 3
|
||||
4 3 0 3
|
||||
12 3 2 3
|
||||
1 3 3 3
|
||||
1 3 2 3
|
||||
11 3 1 1
|
||||
14 2 1 0
|
||||
1 1 0 3
|
||||
4 3 3 3
|
||||
1 2 0 2
|
||||
4 2 1 2
|
||||
0 3 0 0
|
||||
1 0 3 0
|
||||
11 0 1 1
|
||||
14 2 1 0
|
||||
14 2 1 3
|
||||
5 0 3 3
|
||||
1 3 3 3
|
||||
1 3 3 3
|
||||
11 1 3 1
|
||||
14 2 3 3
|
||||
14 0 0 2
|
||||
14 3 0 0
|
||||
12 2 3 0
|
||||
1 0 3 0
|
||||
11 0 1 1
|
||||
3 1 2 2
|
||||
14 3 1 3
|
||||
14 3 1 1
|
||||
1 1 0 0
|
||||
4 0 2 0
|
||||
6 0 1 1
|
||||
1 1 2 1
|
||||
11 1 2 2
|
||||
3 2 0 1
|
||||
14 2 0 3
|
||||
1 3 0 0
|
||||
4 0 1 0
|
||||
14 0 2 2
|
||||
11 0 0 3
|
||||
1 3 1 3
|
||||
11 3 1 1
|
||||
3 1 1 2
|
||||
1 1 0 0
|
||||
4 0 2 0
|
||||
14 3 0 3
|
||||
14 0 2 1
|
||||
14 1 3 1
|
||||
1 1 2 1
|
||||
1 1 2 1
|
||||
11 1 2 2
|
||||
3 2 3 0
|
||||
14 3 0 2
|
||||
14 1 2 1
|
||||
14 1 2 3
|
||||
11 3 3 2
|
||||
1 2 3 2
|
||||
11 0 2 0
|
||||
3 0 0 1
|
||||
14 1 1 2
|
||||
14 2 0 0
|
||||
13 3 0 3
|
||||
1 3 3 3
|
||||
11 3 1 1
|
||||
3 1 0 3
|
||||
14 3 2 1
|
||||
14 1 2 0
|
||||
14 3 3 2
|
||||
4 0 1 1
|
||||
1 1 2 1
|
||||
11 3 1 3
|
||||
3 3 0 1
|
||||
14 2 0 0
|
||||
14 0 3 3
|
||||
8 0 2 0
|
||||
1 0 1 0
|
||||
11 1 0 1
|
||||
3 1 2 2
|
||||
14 3 0 3
|
||||
14 2 1 1
|
||||
14 2 2 0
|
||||
0 3 0 0
|
||||
1 0 3 0
|
||||
11 0 2 2
|
||||
3 2 2 3
|
||||
14 3 3 0
|
||||
14 2 0 2
|
||||
6 2 0 2
|
||||
1 2 1 2
|
||||
11 2 3 3
|
||||
3 3 0 0
|
||||
14 0 2 2
|
||||
1 1 0 3
|
||||
4 3 0 3
|
||||
14 3 2 1
|
||||
10 1 2 2
|
||||
1 2 1 2
|
||||
11 2 0 0
|
||||
3 0 2 2
|
||||
1 3 0 1
|
||||
4 1 1 1
|
||||
14 2 0 0
|
||||
1 2 0 3
|
||||
4 3 1 3
|
||||
15 0 3 0
|
||||
1 0 1 0
|
||||
11 2 0 2
|
||||
3 2 0 1
|
||||
14 2 0 2
|
||||
14 3 1 0
|
||||
6 2 0 3
|
||||
1 3 1 3
|
||||
11 1 3 1
|
||||
3 1 3 2
|
||||
14 2 0 3
|
||||
14 0 0 1
|
||||
0 0 3 1
|
||||
1 1 3 1
|
||||
11 2 1 2
|
||||
3 2 2 1
|
||||
14 2 2 0
|
||||
14 3 3 2
|
||||
5 0 3 3
|
||||
1 3 3 3
|
||||
1 3 3 3
|
||||
11 3 1 1
|
||||
14 3 3 3
|
||||
14 1 0 0
|
||||
1 0 2 0
|
||||
1 0 2 0
|
||||
11 1 0 1
|
||||
14 2 3 3
|
||||
14 0 3 2
|
||||
14 3 1 0
|
||||
9 2 0 3
|
||||
1 3 1 3
|
||||
11 1 3 1
|
||||
1 0 0 2
|
||||
4 2 3 2
|
||||
14 0 0 3
|
||||
12 3 2 0
|
||||
1 0 2 0
|
||||
11 1 0 1
|
||||
14 1 3 0
|
||||
14 2 3 2
|
||||
14 3 2 3
|
||||
3 0 2 0
|
||||
1 0 1 0
|
||||
11 0 1 1
|
||||
3 1 0 0
|
||||
14 1 2 1
|
||||
14 1 3 3
|
||||
14 3 0 2
|
||||
1 3 2 1
|
||||
1 1 3 1
|
||||
11 1 0 0
|
||||
3 0 3 2
|
||||
1 2 0 1
|
||||
4 1 2 1
|
||||
14 0 0 3
|
||||
1 3 0 0
|
||||
4 0 3 0
|
||||
2 1 3 1
|
||||
1 1 3 1
|
||||
11 2 1 2
|
||||
3 2 0 1
|
||||
14 2 2 0
|
||||
14 2 2 3
|
||||
1 3 0 2
|
||||
4 2 3 2
|
||||
5 0 3 0
|
||||
1 0 1 0
|
||||
11 1 0 1
|
||||
3 1 0 3
|
||||
1 3 0 2
|
||||
4 2 2 2
|
||||
14 3 2 0
|
||||
1 2 0 1
|
||||
4 1 0 1
|
||||
6 2 0 1
|
||||
1 1 1 1
|
||||
1 1 1 1
|
||||
11 3 1 3
|
||||
3 3 3 1
|
||||
14 0 3 0
|
||||
14 0 1 2
|
||||
14 2 3 3
|
||||
12 2 3 3
|
||||
1 3 2 3
|
||||
11 1 3 1
|
||||
3 1 3 0
|
||||
14 3 3 3
|
||||
14 3 2 1
|
||||
10 3 2 1
|
||||
1 1 3 1
|
||||
1 1 3 1
|
||||
11 0 1 0
|
||||
3 0 3 2
|
||||
14 0 2 1
|
||||
14 2 0 0
|
||||
14 1 3 3
|
||||
15 0 3 0
|
||||
1 0 3 0
|
||||
11 0 2 2
|
||||
3 2 3 0
|
||||
14 2 0 2
|
||||
14 2 3 3
|
||||
14 2 0 1
|
||||
2 2 3 2
|
||||
1 2 1 2
|
||||
11 0 2 0
|
||||
3 0 3 1
|
||||
14 2 2 2
|
||||
14 3 2 0
|
||||
2 2 3 3
|
||||
1 3 2 3
|
||||
11 1 3 1
|
||||
14 2 2 0
|
||||
14 1 3 3
|
||||
14 3 2 2
|
||||
9 0 2 0
|
||||
1 0 2 0
|
||||
11 0 1 1
|
||||
14 2 1 0
|
||||
9 0 2 3
|
||||
1 3 1 3
|
||||
11 1 3 1
|
||||
14 1 2 3
|
||||
1 1 0 0
|
||||
4 0 1 0
|
||||
1 3 2 3
|
||||
1 3 1 3
|
||||
11 1 3 1
|
||||
3 1 3 0
|
||||
1 2 0 1
|
||||
4 1 1 1
|
||||
14 2 2 2
|
||||
14 0 3 3
|
||||
7 3 2 3
|
||||
1 3 1 3
|
||||
11 3 0 0
|
||||
3 0 2 2
|
||||
14 2 0 1
|
||||
14 0 3 3
|
||||
14 3 1 0
|
||||
8 1 0 3
|
||||
1 3 2 3
|
||||
11 3 2 2
|
||||
3 2 1 1
|
||||
14 2 1 3
|
||||
14 0 0 2
|
||||
14 0 0 0
|
||||
12 2 3 0
|
||||
1 0 2 0
|
||||
11 0 1 1
|
||||
3 1 0 0
|
||||
14 2 2 2
|
||||
1 1 0 3
|
||||
4 3 0 3
|
||||
14 0 1 1
|
||||
7 3 2 1
|
||||
1 1 1 1
|
||||
11 1 0 0
|
||||
3 0 1 1
|
||||
14 2 2 3
|
||||
14 3 0 2
|
||||
14 2 2 0
|
||||
9 0 2 3
|
||||
1 3 2 3
|
||||
1 3 3 3
|
||||
11 3 1 1
|
||||
3 1 0 0
|
||||
14 1 0 3
|
||||
1 1 0 1
|
||||
4 1 3 1
|
||||
14 1 3 2
|
||||
10 1 2 1
|
||||
1 1 2 1
|
||||
11 1 0 0
|
||||
3 0 0 1
|
||||
1 3 0 3
|
||||
4 3 0 3
|
||||
14 0 2 0
|
||||
14 3 2 0
|
||||
1 0 3 0
|
||||
11 0 1 1
|
||||
3 1 2 0
|
||||
14 1 2 3
|
||||
14 0 0 1
|
||||
11 3 3 1
|
||||
1 1 2 1
|
||||
1 1 3 1
|
||||
11 0 1 0
|
||||
3 0 0 3
|
||||
14 2 3 0
|
||||
1 1 0 1
|
||||
4 1 2 1
|
||||
14 3 3 2
|
||||
9 0 2 2
|
||||
1 2 1 2
|
||||
11 2 3 3
|
||||
3 3 0 1
|
||||
14 0 2 3
|
||||
14 0 0 0
|
||||
1 2 0 2
|
||||
4 2 2 2
|
||||
7 3 2 2
|
||||
1 2 2 2
|
||||
11 2 1 1
|
||||
3 1 0 2
|
||||
14 3 0 1
|
||||
14 3 2 0
|
||||
14 2 2 3
|
||||
0 0 3 0
|
||||
1 0 3 0
|
||||
11 0 2 2
|
||||
3 2 2 1
|
||||
14 1 0 3
|
||||
14 2 1 0
|
||||
14 0 3 2
|
||||
15 0 3 2
|
||||
1 2 1 2
|
||||
11 1 2 1
|
||||
1 1 0 2
|
||||
4 2 0 2
|
||||
15 0 3 0
|
||||
1 0 1 0
|
||||
11 1 0 1
|
||||
14 3 3 0
|
||||
14 0 1 3
|
||||
14 2 2 2
|
||||
7 3 2 0
|
||||
1 0 2 0
|
||||
11 1 0 1
|
||||
3 1 0 3
|
||||
1 1 0 2
|
||||
4 2 0 2
|
||||
14 3 0 0
|
||||
14 1 1 1
|
||||
1 1 2 2
|
||||
1 2 3 2
|
||||
11 2 3 3
|
||||
3 3 1 1
|
||||
14 2 0 0
|
||||
14 0 1 3
|
||||
14 2 1 2
|
||||
7 3 2 0
|
||||
1 0 3 0
|
||||
11 0 1 1
|
||||
3 1 2 3
|
||||
14 0 0 1
|
||||
14 1 1 0
|
||||
3 0 2 0
|
||||
1 0 2 0
|
||||
1 0 2 0
|
||||
11 3 0 3
|
||||
3 3 0 2
|
||||
14 1 0 1
|
||||
14 2 3 3
|
||||
14 2 2 0
|
||||
5 0 3 1
|
||||
1 1 1 1
|
||||
11 2 1 2
|
||||
3 2 0 1
|
||||
14 3 0 2
|
||||
9 0 2 0
|
||||
1 0 2 0
|
||||
11 1 0 1
|
||||
3 1 3 3
|
||||
14 2 1 0
|
||||
1 3 0 2
|
||||
4 2 2 2
|
||||
14 3 2 1
|
||||
6 2 1 1
|
||||
1 1 2 1
|
||||
11 1 3 3
|
||||
3 3 0 1
|
||||
1 2 0 3
|
||||
4 3 0 3
|
||||
14 1 3 0
|
||||
3 0 2 2
|
||||
1 2 3 2
|
||||
1 2 1 2
|
||||
11 2 1 1
|
||||
3 1 1 2
|
||||
14 2 2 3
|
||||
14 3 3 1
|
||||
1 0 0 0
|
||||
4 0 3 0
|
||||
0 1 3 0
|
||||
1 0 1 0
|
||||
11 0 2 2
|
||||
3 2 3 1
|
||||
14 0 1 2
|
||||
14 3 1 0
|
||||
14 1 3 3
|
||||
1 3 2 0
|
||||
1 0 1 0
|
||||
11 1 0 1
|
||||
14 2 0 3
|
||||
14 3 2 2
|
||||
14 2 3 0
|
||||
5 0 3 2
|
||||
1 2 2 2
|
||||
11 2 1 1
|
||||
3 1 2 0
|
||||
14 3 3 1
|
||||
14 0 3 2
|
||||
12 2 3 3
|
||||
1 3 1 3
|
||||
1 3 3 3
|
||||
11 3 0 0
|
||||
3 0 2 2
|
||||
14 0 0 1
|
||||
14 2 3 0
|
||||
14 1 2 3
|
||||
15 0 3 3
|
||||
1 3 3 3
|
||||
11 2 3 2
|
||||
3 2 0 1
|
||||
14 2 0 3
|
||||
14 1 3 2
|
||||
5 0 3 2
|
||||
1 2 2 2
|
||||
11 1 2 1
|
||||
3 1 3 3
|
||||
1 3 0 0
|
||||
4 0 1 0
|
||||
14 0 3 1
|
||||
14 1 0 2
|
||||
4 0 1 2
|
||||
1 2 1 2
|
||||
11 3 2 3
|
||||
3 3 1 0
|
||||
14 0 1 3
|
||||
1 1 0 2
|
||||
4 2 3 2
|
||||
14 2 2 1
|
||||
12 3 2 2
|
||||
1 2 3 2
|
||||
11 2 0 0
|
||||
3 0 2 1
|
||||
14 3 2 0
|
||||
1 1 0 2
|
||||
4 2 0 2
|
||||
14 2 3 3
|
||||
12 2 3 3
|
||||
1 3 1 3
|
||||
1 3 1 3
|
||||
11 3 1 1
|
||||
3 1 0 3
|
||||
14 2 0 1
|
||||
9 2 0 2
|
||||
1 2 2 2
|
||||
11 3 2 3
|
||||
3 3 1 2
|
||||
14 2 2 0
|
||||
14 1 3 3
|
||||
14 0 3 1
|
||||
15 0 3 1
|
||||
1 1 1 1
|
||||
11 1 2 2
|
||||
3 2 3 0
|
||||
14 2 1 2
|
||||
14 0 0 1
|
||||
14 0 1 3
|
||||
7 3 2 3
|
||||
1 3 2 3
|
||||
11 3 0 0
|
||||
3 0 2 3
|
||||
14 2 1 1
|
||||
14 3 0 0
|
||||
0 0 1 0
|
||||
1 0 1 0
|
||||
11 0 3 3
|
||||
3 3 3 0
|
||||
1 2 0 3
|
||||
4 3 0 3
|
||||
14 1 2 1
|
||||
7 3 2 2
|
||||
1 2 1 2
|
||||
11 2 0 0
|
||||
3 0 1 1
|
||||
14 3 0 2
|
||||
14 1 0 3
|
||||
14 2 0 0
|
||||
15 0 3 2
|
||||
1 2 3 2
|
||||
11 2 1 1
|
||||
14 3 1 0
|
||||
14 0 2 3
|
||||
14 2 0 2
|
||||
7 3 2 2
|
||||
1 2 2 2
|
||||
11 1 2 1
|
||||
14 1 0 0
|
||||
14 2 2 2
|
||||
3 0 2 3
|
||||
1 3 2 3
|
||||
1 3 3 3
|
||||
11 1 3 1
|
||||
3 1 0 0
|
||||
14 2 2 1
|
||||
14 0 3 3
|
||||
14 3 1 1
|
||||
1 1 2 1
|
||||
11 1 0 0
|
||||
3 0 1 1
|
||||
14 1 0 0
|
||||
11 0 0 0
|
||||
1 0 1 0
|
||||
1 0 1 0
|
||||
11 1 0 1
|
||||
3 1 2 2
|
||||
14 2 1 1
|
||||
14 3 2 0
|
||||
14 3 1 3
|
||||
8 1 0 0
|
||||
1 0 3 0
|
||||
1 0 1 0
|
||||
11 2 0 2
|
||||
3 2 1 0
|
||||
14 1 3 3
|
||||
14 0 3 1
|
||||
14 2 3 2
|
||||
4 3 1 3
|
||||
1 3 2 3
|
||||
11 3 0 0
|
||||
3 0 0 3
|
||||
14 3 1 0
|
||||
14 1 0 1
|
||||
8 2 0 2
|
||||
1 2 3 2
|
||||
1 2 1 2
|
||||
11 3 2 3
|
||||
14 1 1 0
|
||||
14 3 3 1
|
||||
14 0 3 2
|
||||
11 0 0 0
|
||||
1 0 2 0
|
||||
11 0 3 3
|
||||
3 3 0 2
|
||||
1 3 0 0
|
||||
4 0 2 0
|
||||
1 2 0 3
|
||||
4 3 1 3
|
||||
15 0 3 0
|
||||
1 0 3 0
|
||||
11 0 2 2
|
||||
14 1 3 0
|
||||
14 1 0 1
|
||||
14 2 0 3
|
||||
11 0 0 3
|
||||
1 3 1 3
|
||||
1 3 1 3
|
||||
11 3 2 2
|
||||
3 2 0 1
|
||||
14 0 0 3
|
||||
14 2 0 2
|
||||
7 3 2 0
|
||||
1 0 3 0
|
||||
11 0 1 1
|
||||
3 1 2 0
|
||||
14 1 3 3
|
||||
14 1 0 1
|
||||
14 0 2 2
|
||||
1 1 2 1
|
||||
1 1 3 1
|
||||
11 1 0 0
|
||||
3 0 3 2
|
||||
14 2 2 0
|
||||
1 2 0 1
|
||||
4 1 1 1
|
||||
13 1 0 0
|
||||
1 0 1 0
|
||||
1 0 2 0
|
||||
11 2 0 2
|
||||
3 2 1 1
|
||||
1 3 0 0
|
||||
4 0 3 0
|
||||
14 0 3 2
|
||||
14 2 0 3
|
||||
9 2 0 2
|
||||
1 2 3 2
|
||||
11 1 2 1
|
||||
14 0 2 2
|
||||
14 1 3 3
|
||||
9 2 0 0
|
||||
1 0 1 0
|
||||
11 0 1 1
|
||||
3 1 2 3
|
||||
14 2 1 0
|
||||
14 3 0 2
|
||||
14 1 1 1
|
||||
14 2 1 0
|
||||
1 0 1 0
|
||||
11 0 3 3
|
||||
14 3 2 0
|
||||
14 0 1 2
|
||||
14 2 3 1
|
||||
10 0 2 0
|
||||
1 0 2 0
|
||||
11 3 0 3
|
||||
3 3 3 2
|
||||
14 3 1 0
|
||||
1 0 0 3
|
||||
4 3 2 3
|
||||
14 1 1 1
|
||||
13 1 3 1
|
||||
1 1 1 1
|
||||
11 1 2 2
|
||||
14 1 1 1
|
||||
14 1 3 3
|
||||
14 2 3 0
|
||||
15 0 3 3
|
||||
1 3 2 3
|
||||
11 2 3 2
|
||||
3 2 1 1
|
||||
14 1 2 0
|
||||
14 0 3 3
|
||||
14 2 1 2
|
||||
7 3 2 2
|
||||
1 2 2 2
|
||||
11 2 1 1
|
||||
14 1 0 2
|
||||
14 1 3 3
|
||||
14 2 1 0
|
||||
15 0 3 3
|
||||
1 3 2 3
|
||||
11 1 3 1
|
||||
14 1 2 3
|
||||
1 2 0 0
|
||||
4 0 1 0
|
||||
14 2 0 2
|
||||
3 0 2 3
|
||||
1 3 3 3
|
||||
11 3 1 1
|
||||
14 2 3 3
|
||||
14 2 3 0
|
||||
5 0 3 3
|
||||
1 3 1 3
|
||||
1 3 2 3
|
||||
11 1 3 1
|
||||
3 1 3 3
|
||||
14 1 2 0
|
||||
1 3 0 1
|
||||
4 1 1 1
|
||||
14 3 1 2
|
||||
1 0 2 0
|
||||
1 0 2 0
|
||||
11 0 3 3
|
||||
14 2 0 2
|
||||
1 1 0 0
|
||||
4 0 1 0
|
||||
14 3 0 1
|
||||
4 0 1 1
|
||||
1 1 1 1
|
||||
1 1 2 1
|
||||
11 1 3 3
|
||||
3 3 3 0
|
||||
14 0 3 3
|
||||
14 3 0 1
|
||||
7 3 2 1
|
||||
1 1 2 1
|
||||
1 1 2 1
|
||||
11 0 1 0
|
||||
3 0 2 1
|
||||
14 1 3 2
|
||||
14 2 1 0
|
||||
14 1 1 3
|
||||
13 3 0 2
|
||||
1 2 3 2
|
||||
11 2 1 1
|
||||
3 1 1 3
|
||||
14 2 2 2
|
||||
14 2 2 1
|
||||
14 1 3 0
|
||||
3 0 2 1
|
||||
1 1 2 1
|
||||
11 3 1 3
|
||||
3 3 2 0
|
|
@ -0,0 +1,371 @@
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate pretty_env_logger;
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
|
||||
type Registers = [u64; 4];
|
||||
type Instruction = [u64; 4];
|
||||
type DecodeTable = HashMap<u64, String>;
|
||||
|
||||
struct OpSample {
|
||||
before: Registers,
|
||||
instruction: Instruction,
|
||||
after: Registers,
|
||||
}
|
||||
|
||||
fn extract_values_from_line(line: String) -> Registers {
|
||||
let reg_chars = line.as_str();
|
||||
let (_, second) = reg_chars.split_at(9);
|
||||
let third = second.replace(",", "").replace("]", "");
|
||||
iter_to_registers(third.split_whitespace())
|
||||
}
|
||||
|
||||
fn iter_to_registers(iter: std::str::SplitWhitespace) -> Registers {
|
||||
let mut results: Registers = [0u64; 4];
|
||||
for (index, r) in iter.enumerate() {
|
||||
results[index] = r.parse::<u64>().unwrap();
|
||||
}
|
||||
results
|
||||
}
|
||||
|
||||
fn read_samples_from_file(filename: &str) -> Vec<OpSample> {
|
||||
let mut lines: Vec<String> = BufReader::new(File::open(filename).unwrap())
|
||||
.lines()
|
||||
.map(|line| line.unwrap())
|
||||
.collect();
|
||||
let mut samples: Vec<OpSample> = vec![];
|
||||
while !lines.is_empty() {
|
||||
let before = extract_values_from_line(lines.remove(0));
|
||||
let instruction = iter_to_registers(lines.remove(0).split_whitespace());
|
||||
let after = extract_values_from_line(lines.remove(0));
|
||||
lines.remove(0);
|
||||
samples.push(OpSample {
|
||||
before,
|
||||
instruction,
|
||||
after
|
||||
});
|
||||
}
|
||||
samples
|
||||
}
|
||||
|
||||
fn read_instructions_from_file(filename: &str) -> Vec<Instruction> {
|
||||
let lines: Vec<Instruction> = BufReader::new(File::open(filename).unwrap())
|
||||
.lines()
|
||||
.map(|line| iter_to_registers(line.unwrap().split_whitespace()))
|
||||
.collect();
|
||||
lines
|
||||
}
|
||||
|
||||
fn addr(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] + input_registers[instruction[2] as usize];
|
||||
debug!("addr: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn addi(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] + instruction[2];
|
||||
debug!("addi: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn mulr(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] * input_registers[instruction[2] as usize];
|
||||
debug!("mulr: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn muli(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] * instruction[2];
|
||||
debug!("muli: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn banr(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] & input_registers[instruction[2] as usize];
|
||||
debug!("banr: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn bani(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] & instruction[2];
|
||||
debug!("bani: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn borr(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] | input_registers[instruction[2] as usize];
|
||||
debug!("borr: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn bori(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize] | instruction[2];
|
||||
debug!("bori: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn setr(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = input_registers[instruction[1] as usize];
|
||||
debug!("setr: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn seti(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
output_registers[instruction[3] as usize] = instruction[1];
|
||||
debug!("seti: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn gtir(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
if instruction[1] > input_registers[instruction[2] as usize] {
|
||||
output_registers[instruction[3] as usize] = 1;
|
||||
} else {
|
||||
output_registers[instruction[3] as usize] = 0;
|
||||
}
|
||||
debug!("gtir: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn gtri(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
if input_registers[instruction[1] as usize] > instruction[2] {
|
||||
output_registers[instruction[3] as usize] = 1;
|
||||
} else {
|
||||
output_registers[instruction[3] as usize] = 0;
|
||||
}
|
||||
debug!("gtri: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn gtrr(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
if input_registers[instruction[1] as usize] > input_registers[instruction[2] as usize] {
|
||||
output_registers[instruction[3] as usize] = 1;
|
||||
} else {
|
||||
output_registers[instruction[3] as usize] = 0;
|
||||
}
|
||||
debug!("gtrr: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn eqir(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
if instruction[1] == input_registers[instruction[2] as usize] {
|
||||
output_registers[instruction[3] as usize] = 1;
|
||||
} else {
|
||||
output_registers[instruction[3] as usize] = 0;
|
||||
}
|
||||
debug!("eqir: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn eqri(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
if input_registers[instruction[1] as usize] == instruction[2] {
|
||||
output_registers[instruction[3] as usize] = 1;
|
||||
} else {
|
||||
output_registers[instruction[3] as usize] = 0;
|
||||
}
|
||||
debug!("eqri: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn eqrr(input_registers: Registers, instruction: Instruction) -> Registers {
|
||||
let mut output_registers = input_registers.clone();
|
||||
if input_registers[instruction[1] as usize] == input_registers[instruction[2] as usize] {
|
||||
output_registers[instruction[3] as usize] = 1;
|
||||
} else {
|
||||
output_registers[instruction[3] as usize] = 0;
|
||||
}
|
||||
debug!("eqrr: input {:?} output {:?}", input_registers, output_registers);
|
||||
output_registers
|
||||
}
|
||||
|
||||
fn matching_opcodes(i: &OpSample) -> Vec<&str> {
|
||||
let mut m: Vec<&str> = Vec::with_capacity(16);
|
||||
if addr(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches addr", i.instruction);
|
||||
m.push("addr");
|
||||
}
|
||||
if addi(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches addi", i.instruction);
|
||||
m.push("addi");
|
||||
}
|
||||
if mulr(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches mulr", i.instruction);
|
||||
m.push("mulr");
|
||||
}
|
||||
if muli(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches muli", i.instruction);
|
||||
m.push("muli");
|
||||
}
|
||||
if banr(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches banr", i.instruction);
|
||||
m.push("banr");
|
||||
}
|
||||
if bani(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches bani", i.instruction);
|
||||
m.push("bani");
|
||||
}
|
||||
if borr(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches borr", i.instruction);
|
||||
m.push("borr");
|
||||
}
|
||||
if bori(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches bori", i.instruction);
|
||||
m.push("bori");
|
||||
}
|
||||
if setr(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches setr", i.instruction);
|
||||
m.push("setr");
|
||||
}
|
||||
if seti(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches seti", i.instruction);
|
||||
m.push("seti");
|
||||
}
|
||||
if gtir(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches gtir", i.instruction);
|
||||
m.push("gtir");
|
||||
}
|
||||
if gtri(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches gtri", i.instruction);
|
||||
m.push("gtri");
|
||||
}
|
||||
if gtrr(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches gtrr", i.instruction);
|
||||
m.push("gtrr");
|
||||
}
|
||||
if eqir(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches eqir", i.instruction);
|
||||
m.push("eqir");
|
||||
}
|
||||
if eqri(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches eqri", i.instruction);
|
||||
m.push("eqri");
|
||||
}
|
||||
if eqrr(i.before, i.instruction) == i.after {
|
||||
debug!("{:?} matches eqrr", i.instruction);
|
||||
m.push("eqrr");
|
||||
}
|
||||
m
|
||||
}
|
||||
|
||||
fn reduce_decode_map(map: &mut HashMap<u64, HashSet<&str>>) -> DecodeTable {
|
||||
let mut results: DecodeTable = HashMap::new();
|
||||
let mut removed_one = true;
|
||||
while !map.is_empty() && removed_one {
|
||||
removed_one = false;
|
||||
let mut this_pass_found_opcodes: HashSet<u64> = HashSet::new();
|
||||
let mut this_pass_found_instr: HashSet<&str> = HashSet::new();
|
||||
for (confirmed_op, confirmed_instructions) in map.iter() {
|
||||
if confirmed_instructions.len() > 1 {
|
||||
continue;
|
||||
}
|
||||
removed_one = true;
|
||||
let confirmed_instruction = confirmed_instructions.iter().nth(0).unwrap();
|
||||
results.entry(*confirmed_op).or_insert(confirmed_instruction.to_string());
|
||||
this_pass_found_opcodes.insert(*confirmed_op);
|
||||
this_pass_found_instr.insert(*confirmed_instruction);
|
||||
}
|
||||
for op in this_pass_found_opcodes.iter() {
|
||||
map.retain(|k,_| k != op);
|
||||
}
|
||||
for instr in this_pass_found_instr.iter() {
|
||||
for (_k,v) in map.iter_mut() {
|
||||
v.retain(|i| i != instr);
|
||||
}
|
||||
}
|
||||
}
|
||||
results
|
||||
}
|
||||
|
||||
fn opcodes_part_one(samples: &Vec<OpSample>) -> (u16, DecodeTable) {
|
||||
let mut i: u16 = 0;
|
||||
let mut decode_map: HashMap<u64, HashSet<&str>> = HashMap::new();
|
||||
for sample in samples.iter() {
|
||||
let matched_ops = matching_opcodes(&sample);
|
||||
if matched_ops.len() >= 3 {
|
||||
i += 1;
|
||||
}
|
||||
debug!("{:?} matches {} opcodes", sample.instruction, matched_ops.len());
|
||||
let instruction = sample.instruction[0];
|
||||
for op in matched_ops.iter() {
|
||||
decode_map.entry(instruction).and_modify(|m| {
|
||||
m.insert(op);
|
||||
}).or_insert(HashSet::<&str>::new());
|
||||
}
|
||||
}
|
||||
let final_decode_map = reduce_decode_map(&mut decode_map);
|
||||
for (op, instr) in final_decode_map.iter() {
|
||||
debug!("final decode of {} into {}", op, instr);
|
||||
}
|
||||
(i, final_decode_map)
|
||||
}
|
||||
|
||||
fn execute_program(decode_table: &DecodeTable, instructions: &Vec<Instruction>) -> Registers {
|
||||
let mut registers: Registers = [0u64; 4];
|
||||
for instruction in instructions.iter() {
|
||||
debug!("{:?}", instruction);
|
||||
registers = match decode_table.get(&instruction[0]) {
|
||||
Some(x) => {
|
||||
match x.as_str() {
|
||||
"addr" => addr(registers, *instruction),
|
||||
"addi" => addi(registers, *instruction),
|
||||
"mulr" => mulr(registers, *instruction),
|
||||
"muli" => muli(registers, *instruction),
|
||||
"banr" => banr(registers, *instruction),
|
||||
"bani" => bani(registers, *instruction),
|
||||
"borr" => borr(registers, *instruction),
|
||||
"bori" => bori(registers, *instruction),
|
||||
"setr" => setr(registers, *instruction),
|
||||
"seti" => seti(registers, *instruction),
|
||||
"gtir" => gtir(registers, *instruction),
|
||||
"gtri" => gtri(registers, *instruction),
|
||||
"gtrr" => gtrr(registers, *instruction),
|
||||
"eqir" => eqir(registers, *instruction),
|
||||
"eqri" => eqri(registers, *instruction),
|
||||
"eqrr" => eqrr(registers, *instruction),
|
||||
_ => panic!("No decoded instruction available for {}", x),
|
||||
}
|
||||
},
|
||||
None => panic!("Unmapped instruction!"),
|
||||
}
|
||||
}
|
||||
registers
|
||||
}
|
||||
|
||||
fn main() {
|
||||
pretty_env_logger::init();
|
||||
let samples = read_samples_from_file("input-part-1");
|
||||
debug!("samples len is {}", samples.len());
|
||||
let (part1, decode_table) = opcodes_part_one(&samples);
|
||||
println!("samples matching 3 or more opcodes: {}", part1);
|
||||
let program = read_instructions_from_file("input-part-2");
|
||||
let registers: Registers = execute_program(&decode_table, &program);
|
||||
println!("final registers: {:?}", registers);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_sample_one() {
|
||||
let samples = read_samples_from_file("test-input");
|
||||
assert_eq!(matching_opcodes(&samples[0]), 3);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
Before: [3, 2, 1, 1]
|
||||
9 2 1 2
|
||||
After: [3, 2, 2, 1]
|
||||
|
Loading…
Reference in New Issue