Compare commits
4 Commits
experiment
...
55a53e14f7
| Author | SHA1 | Date | |
|---|---|---|---|
| 55a53e14f7 | |||
| 1b1fe127c3 | |||
| 9684b28a65 | |||
| 4a8c5580ff |
143
Cargo.lock
generated
143
Cargo.lock
generated
@@ -5,9 +5,7 @@ name = "advent-of-code-2020-rust"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"rayon",
|
|
||||||
"regex",
|
"regex",
|
||||||
"usize_cast",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -19,147 +17,18 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "const_fn"
|
|
||||||
version = "0.4.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-channel"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"crossbeam-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-deque"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"crossbeam-epoch",
|
|
||||||
"crossbeam-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-epoch"
|
|
||||||
version = "0.9.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"const_fn",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"lazy_static",
|
|
||||||
"memoffset",
|
|
||||||
"scopeguard",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-utils"
|
|
||||||
version = "0.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"cfg-if",
|
|
||||||
"lazy_static",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hermit-abi"
|
|
||||||
version = "0.1.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.81"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.3.4"
|
version = "2.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memoffset"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num_cpus"
|
|
||||||
version = "1.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon"
|
|
||||||
version = "1.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"crossbeam-deque",
|
|
||||||
"either",
|
|
||||||
"rayon-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon-core"
|
|
||||||
version = "1.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-channel",
|
|
||||||
"crossbeam-deque",
|
|
||||||
"crossbeam-utils",
|
|
||||||
"lazy_static",
|
|
||||||
"num_cpus",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.4.2"
|
version = "1.4.2"
|
||||||
@@ -178,12 +47,6 @@ version = "0.6.21"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
|
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "scopeguard"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thread_local"
|
name = "thread_local"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -192,9 +55,3 @@ checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "usize_cast"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "810f3a98a85147e3ad2a1331aa6dac66490e802d65fa0ab283c383058e3f9751"
|
|
||||||
|
|||||||
@@ -9,5 +9,3 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "1"
|
regex = "1"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
usize_cast = "1.0.0"
|
|
||||||
rayon = "1.5.0"
|
|
||||||
795
input/day12.txt
Normal file
795
input/day12.txt
Normal file
@@ -0,0 +1,795 @@
|
|||||||
|
N5
|
||||||
|
W1
|
||||||
|
F61
|
||||||
|
W2
|
||||||
|
R90
|
||||||
|
F50
|
||||||
|
N2
|
||||||
|
F40
|
||||||
|
E4
|
||||||
|
F48
|
||||||
|
R180
|
||||||
|
F17
|
||||||
|
W4
|
||||||
|
N5
|
||||||
|
F3
|
||||||
|
W3
|
||||||
|
F1
|
||||||
|
R90
|
||||||
|
S2
|
||||||
|
F23
|
||||||
|
L90
|
||||||
|
S3
|
||||||
|
W3
|
||||||
|
S4
|
||||||
|
E4
|
||||||
|
L90
|
||||||
|
W3
|
||||||
|
S3
|
||||||
|
E4
|
||||||
|
N2
|
||||||
|
F28
|
||||||
|
S2
|
||||||
|
W2
|
||||||
|
L180
|
||||||
|
E3
|
||||||
|
R90
|
||||||
|
E3
|
||||||
|
F83
|
||||||
|
W5
|
||||||
|
S4
|
||||||
|
W3
|
||||||
|
N2
|
||||||
|
W5
|
||||||
|
F90
|
||||||
|
N2
|
||||||
|
F82
|
||||||
|
N2
|
||||||
|
F2
|
||||||
|
S4
|
||||||
|
L90
|
||||||
|
N3
|
||||||
|
L90
|
||||||
|
S2
|
||||||
|
F12
|
||||||
|
S3
|
||||||
|
F40
|
||||||
|
L90
|
||||||
|
F56
|
||||||
|
N1
|
||||||
|
F29
|
||||||
|
W2
|
||||||
|
S2
|
||||||
|
R270
|
||||||
|
S4
|
||||||
|
F14
|
||||||
|
E4
|
||||||
|
R90
|
||||||
|
E2
|
||||||
|
S2
|
||||||
|
E2
|
||||||
|
F82
|
||||||
|
L90
|
||||||
|
N3
|
||||||
|
R180
|
||||||
|
R90
|
||||||
|
S1
|
||||||
|
W1
|
||||||
|
L90
|
||||||
|
S2
|
||||||
|
F78
|
||||||
|
W2
|
||||||
|
F52
|
||||||
|
N4
|
||||||
|
W5
|
||||||
|
F38
|
||||||
|
L90
|
||||||
|
W2
|
||||||
|
S2
|
||||||
|
L90
|
||||||
|
F66
|
||||||
|
R90
|
||||||
|
F62
|
||||||
|
E3
|
||||||
|
S5
|
||||||
|
L90
|
||||||
|
F99
|
||||||
|
F2
|
||||||
|
E4
|
||||||
|
R90
|
||||||
|
N3
|
||||||
|
W4
|
||||||
|
N1
|
||||||
|
F71
|
||||||
|
E2
|
||||||
|
N3
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
E2
|
||||||
|
F66
|
||||||
|
S4
|
||||||
|
R90
|
||||||
|
E5
|
||||||
|
F29
|
||||||
|
E5
|
||||||
|
L90
|
||||||
|
W2
|
||||||
|
N2
|
||||||
|
E3
|
||||||
|
F18
|
||||||
|
L180
|
||||||
|
F17
|
||||||
|
W1
|
||||||
|
R90
|
||||||
|
W3
|
||||||
|
S5
|
||||||
|
R90
|
||||||
|
S3
|
||||||
|
R180
|
||||||
|
N5
|
||||||
|
F69
|
||||||
|
W1
|
||||||
|
W3
|
||||||
|
L180
|
||||||
|
F72
|
||||||
|
W5
|
||||||
|
N1
|
||||||
|
R180
|
||||||
|
W3
|
||||||
|
W4
|
||||||
|
F85
|
||||||
|
W4
|
||||||
|
L90
|
||||||
|
E4
|
||||||
|
N5
|
||||||
|
F73
|
||||||
|
R90
|
||||||
|
F70
|
||||||
|
E4
|
||||||
|
F79
|
||||||
|
S5
|
||||||
|
R180
|
||||||
|
E2
|
||||||
|
F35
|
||||||
|
E4
|
||||||
|
L270
|
||||||
|
W2
|
||||||
|
L90
|
||||||
|
N5
|
||||||
|
R90
|
||||||
|
N4
|
||||||
|
F64
|
||||||
|
W2
|
||||||
|
R270
|
||||||
|
F33
|
||||||
|
N5
|
||||||
|
E4
|
||||||
|
F94
|
||||||
|
W1
|
||||||
|
N1
|
||||||
|
R90
|
||||||
|
F79
|
||||||
|
F46
|
||||||
|
E1
|
||||||
|
R180
|
||||||
|
S3
|
||||||
|
W3
|
||||||
|
F72
|
||||||
|
E1
|
||||||
|
W4
|
||||||
|
F95
|
||||||
|
W2
|
||||||
|
L90
|
||||||
|
N3
|
||||||
|
L90
|
||||||
|
F85
|
||||||
|
W3
|
||||||
|
W1
|
||||||
|
F54
|
||||||
|
N3
|
||||||
|
E1
|
||||||
|
N4
|
||||||
|
E5
|
||||||
|
L90
|
||||||
|
F61
|
||||||
|
W2
|
||||||
|
F7
|
||||||
|
L180
|
||||||
|
F87
|
||||||
|
N4
|
||||||
|
W1
|
||||||
|
F87
|
||||||
|
F3
|
||||||
|
E3
|
||||||
|
F63
|
||||||
|
R90
|
||||||
|
S4
|
||||||
|
R180
|
||||||
|
S4
|
||||||
|
R180
|
||||||
|
R90
|
||||||
|
R90
|
||||||
|
E5
|
||||||
|
N4
|
||||||
|
E2
|
||||||
|
F86
|
||||||
|
S3
|
||||||
|
F98
|
||||||
|
N4
|
||||||
|
F70
|
||||||
|
L90
|
||||||
|
E4
|
||||||
|
F26
|
||||||
|
W4
|
||||||
|
F19
|
||||||
|
L90
|
||||||
|
S4
|
||||||
|
W4
|
||||||
|
F84
|
||||||
|
N1
|
||||||
|
E4
|
||||||
|
L180
|
||||||
|
S2
|
||||||
|
F74
|
||||||
|
S1
|
||||||
|
F86
|
||||||
|
R90
|
||||||
|
S2
|
||||||
|
F78
|
||||||
|
N4
|
||||||
|
S2
|
||||||
|
W1
|
||||||
|
N5
|
||||||
|
E2
|
||||||
|
F38
|
||||||
|
W4
|
||||||
|
N1
|
||||||
|
F75
|
||||||
|
S1
|
||||||
|
E1
|
||||||
|
N3
|
||||||
|
S1
|
||||||
|
F54
|
||||||
|
N3
|
||||||
|
F88
|
||||||
|
N5
|
||||||
|
L180
|
||||||
|
F15
|
||||||
|
S2
|
||||||
|
S2
|
||||||
|
E2
|
||||||
|
N3
|
||||||
|
F97
|
||||||
|
S3
|
||||||
|
N3
|
||||||
|
E3
|
||||||
|
N5
|
||||||
|
E3
|
||||||
|
R90
|
||||||
|
F87
|
||||||
|
L90
|
||||||
|
F15
|
||||||
|
L90
|
||||||
|
E5
|
||||||
|
R90
|
||||||
|
F70
|
||||||
|
N3
|
||||||
|
W2
|
||||||
|
F47
|
||||||
|
W2
|
||||||
|
W3
|
||||||
|
F17
|
||||||
|
R90
|
||||||
|
F95
|
||||||
|
E4
|
||||||
|
F28
|
||||||
|
W4
|
||||||
|
R90
|
||||||
|
E2
|
||||||
|
R180
|
||||||
|
N4
|
||||||
|
R180
|
||||||
|
W4
|
||||||
|
R270
|
||||||
|
F73
|
||||||
|
W1
|
||||||
|
N2
|
||||||
|
L90
|
||||||
|
S1
|
||||||
|
F65
|
||||||
|
E1
|
||||||
|
F42
|
||||||
|
N2
|
||||||
|
F74
|
||||||
|
R90
|
||||||
|
F21
|
||||||
|
W5
|
||||||
|
S1
|
||||||
|
N5
|
||||||
|
R90
|
||||||
|
E4
|
||||||
|
N5
|
||||||
|
S5
|
||||||
|
F99
|
||||||
|
W4
|
||||||
|
L180
|
||||||
|
W1
|
||||||
|
F83
|
||||||
|
N2
|
||||||
|
W2
|
||||||
|
F87
|
||||||
|
E2
|
||||||
|
S3
|
||||||
|
W1
|
||||||
|
L180
|
||||||
|
F89
|
||||||
|
S1
|
||||||
|
W2
|
||||||
|
E2
|
||||||
|
L90
|
||||||
|
S2
|
||||||
|
W1
|
||||||
|
S5
|
||||||
|
R180
|
||||||
|
E5
|
||||||
|
N1
|
||||||
|
F82
|
||||||
|
S3
|
||||||
|
F7
|
||||||
|
L90
|
||||||
|
F31
|
||||||
|
L90
|
||||||
|
N3
|
||||||
|
F84
|
||||||
|
W3
|
||||||
|
N4
|
||||||
|
F100
|
||||||
|
N1
|
||||||
|
E2
|
||||||
|
R90
|
||||||
|
F90
|
||||||
|
N3
|
||||||
|
F43
|
||||||
|
R90
|
||||||
|
F2
|
||||||
|
W4
|
||||||
|
L90
|
||||||
|
F87
|
||||||
|
L90
|
||||||
|
E3
|
||||||
|
F71
|
||||||
|
L180
|
||||||
|
N1
|
||||||
|
L90
|
||||||
|
E4
|
||||||
|
N3
|
||||||
|
F31
|
||||||
|
W1
|
||||||
|
F80
|
||||||
|
R270
|
||||||
|
N1
|
||||||
|
E4
|
||||||
|
N1
|
||||||
|
F22
|
||||||
|
N4
|
||||||
|
E1
|
||||||
|
F57
|
||||||
|
R90
|
||||||
|
N3
|
||||||
|
W2
|
||||||
|
L180
|
||||||
|
N3
|
||||||
|
L180
|
||||||
|
W4
|
||||||
|
F59
|
||||||
|
S4
|
||||||
|
F10
|
||||||
|
N5
|
||||||
|
L90
|
||||||
|
S3
|
||||||
|
L90
|
||||||
|
E1
|
||||||
|
F96
|
||||||
|
E4
|
||||||
|
N3
|
||||||
|
F54
|
||||||
|
L180
|
||||||
|
F47
|
||||||
|
W1
|
||||||
|
N4
|
||||||
|
E1
|
||||||
|
S4
|
||||||
|
R180
|
||||||
|
L90
|
||||||
|
N1
|
||||||
|
R90
|
||||||
|
N3
|
||||||
|
R90
|
||||||
|
N4
|
||||||
|
R90
|
||||||
|
S3
|
||||||
|
F59
|
||||||
|
N5
|
||||||
|
L90
|
||||||
|
E4
|
||||||
|
F72
|
||||||
|
W4
|
||||||
|
F76
|
||||||
|
R90
|
||||||
|
E3
|
||||||
|
F70
|
||||||
|
L180
|
||||||
|
N3
|
||||||
|
W2
|
||||||
|
R90
|
||||||
|
F65
|
||||||
|
L90
|
||||||
|
F71
|
||||||
|
S3
|
||||||
|
F43
|
||||||
|
R90
|
||||||
|
W2
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
W1
|
||||||
|
R90
|
||||||
|
S4
|
||||||
|
R180
|
||||||
|
S1
|
||||||
|
E3
|
||||||
|
F72
|
||||||
|
L90
|
||||||
|
F61
|
||||||
|
L90
|
||||||
|
F75
|
||||||
|
S1
|
||||||
|
S5
|
||||||
|
F15
|
||||||
|
R90
|
||||||
|
E3
|
||||||
|
N2
|
||||||
|
L270
|
||||||
|
F48
|
||||||
|
N1
|
||||||
|
R180
|
||||||
|
W2
|
||||||
|
F69
|
||||||
|
E4
|
||||||
|
R90
|
||||||
|
R90
|
||||||
|
W1
|
||||||
|
S5
|
||||||
|
W5
|
||||||
|
R90
|
||||||
|
S4
|
||||||
|
S3
|
||||||
|
F51
|
||||||
|
F43
|
||||||
|
E2
|
||||||
|
N5
|
||||||
|
L180
|
||||||
|
F89
|
||||||
|
W1
|
||||||
|
R90
|
||||||
|
F59
|
||||||
|
R90
|
||||||
|
E2
|
||||||
|
F51
|
||||||
|
R90
|
||||||
|
F91
|
||||||
|
W4
|
||||||
|
S5
|
||||||
|
E4
|
||||||
|
L90
|
||||||
|
S5
|
||||||
|
R90
|
||||||
|
F44
|
||||||
|
F47
|
||||||
|
E4
|
||||||
|
W1
|
||||||
|
F77
|
||||||
|
S5
|
||||||
|
R90
|
||||||
|
N2
|
||||||
|
F87
|
||||||
|
N4
|
||||||
|
R90
|
||||||
|
W5
|
||||||
|
R90
|
||||||
|
W5
|
||||||
|
F89
|
||||||
|
L90
|
||||||
|
F61
|
||||||
|
E2
|
||||||
|
F29
|
||||||
|
N4
|
||||||
|
R90
|
||||||
|
F31
|
||||||
|
S1
|
||||||
|
L90
|
||||||
|
E5
|
||||||
|
N2
|
||||||
|
F7
|
||||||
|
L180
|
||||||
|
S4
|
||||||
|
F63
|
||||||
|
W4
|
||||||
|
N5
|
||||||
|
S2
|
||||||
|
N1
|
||||||
|
E5
|
||||||
|
F87
|
||||||
|
S5
|
||||||
|
R180
|
||||||
|
F14
|
||||||
|
W4
|
||||||
|
R180
|
||||||
|
E1
|
||||||
|
L90
|
||||||
|
F67
|
||||||
|
E2
|
||||||
|
L90
|
||||||
|
E5
|
||||||
|
S2
|
||||||
|
L90
|
||||||
|
W2
|
||||||
|
R90
|
||||||
|
F94
|
||||||
|
W4
|
||||||
|
R90
|
||||||
|
W3
|
||||||
|
S3
|
||||||
|
R90
|
||||||
|
N5
|
||||||
|
F55
|
||||||
|
L90
|
||||||
|
F43
|
||||||
|
L90
|
||||||
|
N5
|
||||||
|
F16
|
||||||
|
E4
|
||||||
|
N2
|
||||||
|
L270
|
||||||
|
W3
|
||||||
|
E1
|
||||||
|
N2
|
||||||
|
R180
|
||||||
|
F51
|
||||||
|
N5
|
||||||
|
N1
|
||||||
|
F36
|
||||||
|
W4
|
||||||
|
F38
|
||||||
|
N5
|
||||||
|
W1
|
||||||
|
F29
|
||||||
|
R180
|
||||||
|
L90
|
||||||
|
N1
|
||||||
|
W3
|
||||||
|
E1
|
||||||
|
F78
|
||||||
|
E1
|
||||||
|
N1
|
||||||
|
E2
|
||||||
|
F57
|
||||||
|
E4
|
||||||
|
F83
|
||||||
|
W5
|
||||||
|
F32
|
||||||
|
N3
|
||||||
|
W4
|
||||||
|
F36
|
||||||
|
N2
|
||||||
|
E3
|
||||||
|
F74
|
||||||
|
N4
|
||||||
|
F54
|
||||||
|
W5
|
||||||
|
L90
|
||||||
|
S1
|
||||||
|
F42
|
||||||
|
W4
|
||||||
|
S5
|
||||||
|
E3
|
||||||
|
F64
|
||||||
|
W2
|
||||||
|
R180
|
||||||
|
S2
|
||||||
|
E1
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
W3
|
||||||
|
F36
|
||||||
|
N3
|
||||||
|
R90
|
||||||
|
S2
|
||||||
|
F53
|
||||||
|
W2
|
||||||
|
F85
|
||||||
|
E5
|
||||||
|
N2
|
||||||
|
F9
|
||||||
|
E1
|
||||||
|
F83
|
||||||
|
L90
|
||||||
|
E5
|
||||||
|
F44
|
||||||
|
L90
|
||||||
|
F92
|
||||||
|
W5
|
||||||
|
R270
|
||||||
|
E4
|
||||||
|
S1
|
||||||
|
F6
|
||||||
|
L90
|
||||||
|
F96
|
||||||
|
R90
|
||||||
|
N1
|
||||||
|
E4
|
||||||
|
N1
|
||||||
|
W3
|
||||||
|
S2
|
||||||
|
S4
|
||||||
|
F39
|
||||||
|
E1
|
||||||
|
S1
|
||||||
|
F82
|
||||||
|
S3
|
||||||
|
F78
|
||||||
|
L90
|
||||||
|
N4
|
||||||
|
E1
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
F63
|
||||||
|
S3
|
||||||
|
L180
|
||||||
|
F52
|
||||||
|
W2
|
||||||
|
F49
|
||||||
|
W2
|
||||||
|
L270
|
||||||
|
N1
|
||||||
|
R180
|
||||||
|
E3
|
||||||
|
F79
|
||||||
|
F73
|
||||||
|
N1
|
||||||
|
R90
|
||||||
|
N3
|
||||||
|
R180
|
||||||
|
S2
|
||||||
|
F35
|
||||||
|
S1
|
||||||
|
F43
|
||||||
|
S1
|
||||||
|
R90
|
||||||
|
S4
|
||||||
|
W4
|
||||||
|
F12
|
||||||
|
S1
|
||||||
|
F2
|
||||||
|
N3
|
||||||
|
E4
|
||||||
|
L90
|
||||||
|
F51
|
||||||
|
R90
|
||||||
|
N4
|
||||||
|
F90
|
||||||
|
R90
|
||||||
|
F99
|
||||||
|
E3
|
||||||
|
N1
|
||||||
|
R90
|
||||||
|
S3
|
||||||
|
L270
|
||||||
|
W5
|
||||||
|
L90
|
||||||
|
R270
|
||||||
|
F50
|
||||||
|
N5
|
||||||
|
F33
|
||||||
|
S3
|
||||||
|
F18
|
||||||
|
L90
|
||||||
|
E4
|
||||||
|
L180
|
||||||
|
W4
|
||||||
|
R90
|
||||||
|
F21
|
||||||
|
W4
|
||||||
|
F24
|
||||||
|
W2
|
||||||
|
E5
|
||||||
|
N3
|
||||||
|
W1
|
||||||
|
R90
|
||||||
|
W3
|
||||||
|
S3
|
||||||
|
F82
|
||||||
|
W1
|
||||||
|
S1
|
||||||
|
F12
|
||||||
|
N3
|
||||||
|
L90
|
||||||
|
F37
|
||||||
|
R180
|
||||||
|
F36
|
||||||
|
F27
|
||||||
|
E3
|
||||||
|
S3
|
||||||
|
F36
|
||||||
|
W4
|
||||||
|
S1
|
||||||
|
F6
|
||||||
|
R90
|
||||||
|
F59
|
||||||
|
S1
|
||||||
|
E1
|
||||||
|
R180
|
||||||
|
S2
|
||||||
|
W3
|
||||||
|
L90
|
||||||
|
F45
|
||||||
|
R90
|
||||||
|
E1
|
||||||
|
F29
|
||||||
|
S5
|
||||||
|
W3
|
||||||
|
S5
|
||||||
|
W4
|
||||||
|
L270
|
||||||
|
S2
|
||||||
|
F13
|
||||||
|
E4
|
||||||
|
F28
|
||||||
|
R90
|
||||||
|
F80
|
||||||
|
S4
|
||||||
|
E1
|
||||||
|
S2
|
||||||
|
F62
|
||||||
|
R90
|
||||||
|
F26
|
||||||
|
L180
|
||||||
|
F19
|
||||||
|
W2
|
||||||
|
L180
|
||||||
|
W5
|
||||||
|
F15
|
||||||
|
N1
|
||||||
|
F68
|
||||||
|
E4
|
||||||
|
F75
|
||||||
|
S2
|
||||||
|
F58
|
||||||
|
S4
|
||||||
|
R180
|
||||||
|
E3
|
||||||
|
N1
|
||||||
|
L90
|
||||||
|
S2
|
||||||
|
F12
|
||||||
|
R90
|
||||||
|
E5
|
||||||
|
S5
|
||||||
|
W4
|
||||||
|
N5
|
||||||
|
W1
|
||||||
|
R180
|
||||||
|
S1
|
||||||
|
F70
|
||||||
|
R90
|
||||||
|
F97
|
||||||
|
L90
|
||||||
|
E3
|
||||||
|
S3
|
||||||
|
L270
|
||||||
|
E1
|
||||||
|
F51
|
||||||
|
N4
|
||||||
|
L180
|
||||||
|
N1
|
||||||
|
R90
|
||||||
|
F42
|
||||||
5
input/day12_example.txt
Normal file
5
input/day12_example.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
F10
|
||||||
|
N3
|
||||||
|
F7
|
||||||
|
R90
|
||||||
|
F11
|
||||||
2
input/day13.txt
Normal file
2
input/day13.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
1006605
|
||||||
|
19,x,x,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,883,x,x,x,x,x,x,x,23,x,x,x,x,13,x,x,x,17,x,x,x,x,x,x,x,x,x,x,x,x,x,797,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,29
|
||||||
7
input/day13_example.txt
Normal file
7
input/day13_example.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
939
|
||||||
|
3,7919
|
||||||
|
7,31
|
||||||
|
67,7,x,59,61
|
||||||
|
1789,37,47,1889
|
||||||
|
7,13,x,x,59,x,31,19
|
||||||
|
67,x,7,59,61
|
||||||
96
src/day11.rs
96
src/day11.rs
@@ -2,27 +2,19 @@ use super::util;
|
|||||||
use crate::day11::GridState::Floor;
|
use crate::day11::GridState::Floor;
|
||||||
use crate::day11::GridState::FilledSeat;
|
use crate::day11::GridState::FilledSeat;
|
||||||
use crate::day11::GridState::EmptySeat;
|
use crate::day11::GridState::EmptySeat;
|
||||||
use rayon::prelude::*;
|
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
pub fn solve() {
|
pub fn solve() {
|
||||||
let lines = util::read_file("input/day11.txt");
|
let lines = util::read_file("input/day11.txt");
|
||||||
|
|
||||||
let seats = Seats::parse(&lines);
|
let seats = Seats::parse(&lines, 1);
|
||||||
|
|
||||||
let now = Instant::now();
|
|
||||||
|
|
||||||
let part1 = solve_part1(&seats);
|
let part1 = solve_part1(&seats);
|
||||||
|
|
||||||
println!("Part 1 took: {} μs", now.elapsed().as_micros());
|
|
||||||
println!("Day 11 Part 1: {}", part1);
|
println!("Day 11 Part 1: {}", part1);
|
||||||
|
|
||||||
let now2 = Instant::now();
|
|
||||||
|
|
||||||
let visible_chairs = seats.calculate_all_visible_chairs();
|
let visible_chairs = seats.calculate_all_visible_chairs();
|
||||||
let part2 = solve_part2(&seats, &visible_chairs);
|
let part2 = solve_part2(&seats, &visible_chairs);
|
||||||
|
|
||||||
println!("Part 2 took: {} μs", now2.elapsed().as_micros());
|
|
||||||
println!("Day 11 Part 2: {}", part2);
|
println!("Day 11 Part 2: {}", part2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,38 +23,27 @@ fn solve_part1(seats: &Seats) -> usize {
|
|||||||
let mut last_seats = seats.clone();
|
let mut last_seats = seats.clone();
|
||||||
let mut next_seats = seats.clone();
|
let mut next_seats = seats.clone();
|
||||||
|
|
||||||
let mut seat_idxs = Vec::new();
|
|
||||||
for y in 0..seats.height {
|
|
||||||
for x in 0..seats.width {
|
|
||||||
let seat = seats.get(&x, &y);
|
|
||||||
if seat != &Floor {
|
|
||||||
seat_idxs.push((x, y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loop {
|
loop {
|
||||||
let changes: Vec<(usize, usize, &GridState)> = seat_idxs.par_iter().map(|pos| {
|
let mut changes = false;
|
||||||
let x = &pos.0;
|
for y in 1..seats.height-1 {
|
||||||
let y = &pos.1;
|
for x in 1..seats.width-1 {
|
||||||
let seat = last_seats.get(x, y);
|
let seat = last_seats.get(&x, &y);
|
||||||
let occupied = last_seats.count_occupied_neighbors(x, y);
|
if seat != &Floor {
|
||||||
if seat == &EmptySeat && occupied == 0 {
|
let occupied = last_seats.count_occupied_neighbors(&x, &y);
|
||||||
return Option::from((pos.0, pos.1, &FilledSeat));
|
if seat == &EmptySeat && occupied == 0 {
|
||||||
} else if seat == &FilledSeat && occupied >= 4 {
|
changes = true;
|
||||||
return Option::from((pos.0, pos.1, &EmptySeat));
|
next_seats.set(&x, &y, FilledSeat);
|
||||||
} else {
|
} else if seat == &FilledSeat && occupied >= 4 {
|
||||||
return Option::None;
|
next_seats.set(&x, &y, EmptySeat);
|
||||||
|
changes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).filter(|o| o.is_some()).map(|o| o.unwrap()).collect::<Vec<_>>();
|
|
||||||
|
|
||||||
if changes.is_empty() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for change in changes {
|
|
||||||
next_seats.set(&change.0, &change.1, *change.2);
|
|
||||||
}
|
}
|
||||||
// next_seats.print();
|
// next_seats.print();
|
||||||
|
if !changes {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
last_seats = next_seats.clone();
|
last_seats = next_seats.clone();
|
||||||
}
|
}
|
||||||
@@ -74,11 +55,7 @@ fn solve_part2(seats: &Seats, visible_chairs: &Vec<Option<Vec<(usize, usize)>>>)
|
|||||||
let mut last_seats = seats.clone();
|
let mut last_seats = seats.clone();
|
||||||
let mut next_seats = seats.clone();
|
let mut next_seats = seats.clone();
|
||||||
|
|
||||||
let mut calc_times = Vec::new();
|
|
||||||
let mut copy_times = Vec::new();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let calc_start = Instant::now();
|
|
||||||
let mut changes = false;
|
let mut changes = false;
|
||||||
for y in 0..seats.height {
|
for y in 0..seats.height {
|
||||||
for x in 0..seats.width {
|
for x in 0..seats.width {
|
||||||
@@ -89,8 +66,8 @@ fn solve_part2(seats: &Seats, visible_chairs: &Vec<Option<Vec<(usize, usize)>>>)
|
|||||||
changes = true;
|
changes = true;
|
||||||
next_seats.set(&x, &y, FilledSeat);
|
next_seats.set(&x, &y, FilledSeat);
|
||||||
} else if seat == &FilledSeat && occupied >= 5 {
|
} else if seat == &FilledSeat && occupied >= 5 {
|
||||||
next_seats.set(&x, &y, EmptySeat);
|
|
||||||
changes = true;
|
changes = true;
|
||||||
|
next_seats.set(&x, &y, EmptySeat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,15 +76,9 @@ fn solve_part2(seats: &Seats, visible_chairs: &Vec<Option<Vec<(usize, usize)>>>)
|
|||||||
if !changes {
|
if !changes {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
calc_times.push(calc_start.elapsed().as_micros());
|
|
||||||
|
|
||||||
let now = Instant::now();
|
|
||||||
last_seats = next_seats.clone();
|
last_seats = next_seats.clone();
|
||||||
copy_times.push(now.elapsed().as_micros());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Avg calc time: {} μs", calc_times.iter().sum::<u128>() / (calc_times.len() as u128));
|
|
||||||
println!("Avg copy time: {} μs", copy_times.iter().sum::<u128>() / (copy_times.len() as u128));
|
|
||||||
return last_seats.grid.iter().filter(|s| s == &&FilledSeat).count();
|
return last_seats.grid.iter().filter(|s| s == &&FilledSeat).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,16 +94,16 @@ impl Seats {
|
|||||||
|
|
||||||
const DIRECTIONS: [(i32, i32); 8] = [(-1, 1), (-1, 0), (-1, -1), (0, -1), (0, 1), (1, 1), (1, 0), (1, -1)];
|
const DIRECTIONS: [(i32, i32); 8] = [(-1, 1), (-1, 0), (-1, -1), (0, -1), (0, 1), (1, 1), (1, 0), (1, -1)];
|
||||||
|
|
||||||
fn parse(lines: &Vec<String>) -> Seats {
|
fn parse(lines: &Vec<String>, padding: usize) -> Seats {
|
||||||
|
|
||||||
let height = lines.len();
|
let height = lines.len() + padding * 2;
|
||||||
let width = lines[0].len();
|
let width = lines[0].len() + padding * 2;
|
||||||
let mut grid = vec!(GridState::Floor; width * height);
|
let mut grid = vec!(GridState::Floor; width * height);
|
||||||
for y in 0..lines.len() {
|
for y in 0..lines.len() {
|
||||||
let line = &lines[y];
|
let line = &lines[y];
|
||||||
let mut line_chars = line.chars();
|
let mut line_chars = line.chars();
|
||||||
for x in 0..lines[0].len() {
|
for x in 0..lines[0].len() {
|
||||||
grid[x + y * width] = GridState::parse(&line_chars.next().unwrap())
|
grid[(x + padding) + (y + padding) * width] = GridState::parse(&line_chars.next().unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,20 +170,15 @@ impl Seats {
|
|||||||
|
|
||||||
fn count_occupied_neighbors(&self, x: &usize, y: &usize) -> u8 {
|
fn count_occupied_neighbors(&self, x: &usize, y: &usize) -> u8 {
|
||||||
|
|
||||||
let x_upper = x == &(self.width - &ONE);
|
|
||||||
let x_lower = x == &0;
|
|
||||||
let y_upper = y == &(self.height - &ONE);
|
|
||||||
let y_lower = y == &0;
|
|
||||||
|
|
||||||
return
|
return
|
||||||
if !x_lower && !y_lower && self.is_occupied(&(x - &ONE), &(y - &ONE)) { 1 } else { 0 } +
|
if self.is_occupied(&(x - &ONE), &(y - &ONE)) { 1 } else { 0 } +
|
||||||
if !x_lower && self.is_occupied(&(x - &ONE), &y) { 1 } else { 0 } +
|
if self.is_occupied(&(x - &ONE), &y) { 1 } else { 0 } +
|
||||||
if !x_lower && !y_upper && self.is_occupied(&(x - &ONE), &(y + ONE)) { 1 } else { 0 } +
|
if self.is_occupied(&(x - &ONE), &(y + ONE)) { 1 } else { 0 } +
|
||||||
if !y_lower && self.is_occupied(&x, &(y - ONE)) { 1 } else { 0 } +
|
if self.is_occupied(&x, &(y - ONE)) { 1 } else { 0 } +
|
||||||
if !y_upper && self.is_occupied(&x, &(y + ONE)) { 1 } else { 0 } +
|
if self.is_occupied(&x, &(y + ONE)) { 1 } else { 0 } +
|
||||||
if !x_upper && !y_lower && self.is_occupied(&(x + ONE), &(y - ONE)) { 1 } else { 0 } +
|
if self.is_occupied(&(x + ONE), &(y - ONE)) { 1 } else { 0 } +
|
||||||
if !x_upper && self.is_occupied(&(x + ONE), &y) { 1 } else { 0 } +
|
if self.is_occupied(&(x + ONE), &y) { 1 } else { 0 } +
|
||||||
if !x_upper && !y_upper && self.is_occupied(&(x + ONE), &(y + ONE)) { 1 } else { 0 }
|
if self.is_occupied(&(x + ONE), &(y + ONE)) { 1 } else { 0 }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
174
src/day12.rs
Normal file
174
src/day12.rs
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
use super::util;
|
||||||
|
use crate::day12::Heading::{North, East, South, West};
|
||||||
|
use std::mem::swap;
|
||||||
|
|
||||||
|
pub fn solve()
|
||||||
|
{
|
||||||
|
let lines = util::read_file("input/day12.txt");
|
||||||
|
let instructions = lines.iter().map(|s| Instruction::parse(s)).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let ship_state = execute(&instructions);
|
||||||
|
let part1 = ship_state.manhattan_distance();
|
||||||
|
println!("Day 12 Part 1: {}", part1);
|
||||||
|
|
||||||
|
let ship_state2 = execute_with_waypoint(&instructions);
|
||||||
|
let part2 = ship_state2.manhattan_distance();
|
||||||
|
println!("Day 12 Part 2: {}", part2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute(instructions: &Vec<Instruction>) -> ShipState {
|
||||||
|
|
||||||
|
let mut res = ShipState { position_n: 0, position_e: 0, heading: East };
|
||||||
|
|
||||||
|
for instruction in instructions {
|
||||||
|
res.apply(&instruction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute_with_waypoint(instructions: &Vec<Instruction>) -> ShipState {
|
||||||
|
|
||||||
|
let mut ship = ShipState { position_n: 0, position_e: 0, heading: East };
|
||||||
|
let mut waypoint = WaypointState { position_n: 1, position_e: 10 };
|
||||||
|
|
||||||
|
for instruction in instructions {
|
||||||
|
// println!("Instruction: {}{}", instruction.action, instruction.amount);
|
||||||
|
|
||||||
|
if instruction.action == 'F' {
|
||||||
|
ship.position_n += waypoint.position_n * instruction.amount as i32;
|
||||||
|
ship.position_e += waypoint.position_e * instruction.amount as i32;
|
||||||
|
} else {
|
||||||
|
waypoint.apply(instruction);
|
||||||
|
}
|
||||||
|
// println!("Ship: {:?}, Waypoint: {:?}", ship, waypoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ship;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct ShipState {
|
||||||
|
position_n: i32,
|
||||||
|
position_e: i32,
|
||||||
|
heading: Heading,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShipState {
|
||||||
|
fn manhattan_distance(&self) -> i32 {
|
||||||
|
return self.position_n.abs() + self.position_e.abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply(&mut self, instruction: &Instruction) {
|
||||||
|
|
||||||
|
match instruction.action {
|
||||||
|
'N'=> self.position_n += instruction.amount as i32,
|
||||||
|
'S' => self.position_n -= instruction.amount as i32,
|
||||||
|
'E' => self.position_e += instruction.amount as i32,
|
||||||
|
'W' => self.position_e -= instruction.amount as i32,
|
||||||
|
'L' => self.turn_left(instruction.amount),
|
||||||
|
'R' => self.turn_left(360 - (instruction.amount % 360)),
|
||||||
|
'F' => self.move_forward(instruction.amount),
|
||||||
|
_ => panic!("Unknown instruction: {}", instruction.action)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn move_forward(&mut self, amount: u32) {
|
||||||
|
match self.heading {
|
||||||
|
North => self.position_n += amount as i32,
|
||||||
|
East => self.position_e += amount as i32,
|
||||||
|
South => self.position_n -= amount as i32,
|
||||||
|
West => self.position_e -= amount as i32,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn turn_left(&mut self, amount: u32) {
|
||||||
|
|
||||||
|
assert_eq!(amount % 90, 0, "Only rotations of (multiples of) 90 degrees are supported");
|
||||||
|
|
||||||
|
let count = amount / 90;
|
||||||
|
for _ in 0..count {
|
||||||
|
self.heading = self.heading.turn_left();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct WaypointState {
|
||||||
|
position_n: i32,
|
||||||
|
position_e: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WaypointState {
|
||||||
|
|
||||||
|
fn apply(&mut self, instruction: &Instruction) {
|
||||||
|
|
||||||
|
match instruction.action {
|
||||||
|
'N'=> self.position_n += instruction.amount as i32,
|
||||||
|
'S' => self.position_n -= instruction.amount as i32,
|
||||||
|
'E' => self.position_e += instruction.amount as i32,
|
||||||
|
'W' => self.position_e -= instruction.amount as i32,
|
||||||
|
'L' => self.rotate_left_around_origin(instruction.amount),
|
||||||
|
'R' => self.rotate_left_around_origin(360 - instruction.amount),
|
||||||
|
_ => panic!("Unknown instruction: {}", instruction.action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rotate_left_around_origin(&mut self , amount: u32) {
|
||||||
|
assert_eq!(amount % 90, 0, "Only rotations of (multiples of) 90 degrees are supported");
|
||||||
|
|
||||||
|
if amount % 360 == 0 { return; }
|
||||||
|
|
||||||
|
match amount % 360 {
|
||||||
|
90 => {
|
||||||
|
swap(&mut self.position_n, &mut self.position_e);
|
||||||
|
self.position_e *= -1;
|
||||||
|
}
|
||||||
|
180 => {
|
||||||
|
self.position_n *= -1;
|
||||||
|
self.position_e *= -1;
|
||||||
|
}
|
||||||
|
270 => {
|
||||||
|
swap(&mut self.position_n, &mut self.position_e);
|
||||||
|
self.position_n *= -1;
|
||||||
|
}
|
||||||
|
_ => panic!("Unsupported amount of degrees")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Instruction {
|
||||||
|
action: char,
|
||||||
|
amount: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Heading {
|
||||||
|
North, East, South, West
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Heading {
|
||||||
|
|
||||||
|
fn turn_left(&self) -> Heading {
|
||||||
|
return match self {
|
||||||
|
North => West,
|
||||||
|
West => South,
|
||||||
|
South => East,
|
||||||
|
East => North
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Instruction {
|
||||||
|
|
||||||
|
fn parse(line: &String) -> Instruction {
|
||||||
|
|
||||||
|
return Instruction {
|
||||||
|
action: line.chars().next().unwrap(),
|
||||||
|
amount: line[1..].parse::<u32>().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
73
src/day13.rs
Normal file
73
src/day13.rs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
use super::util;
|
||||||
|
|
||||||
|
pub fn solve() {
|
||||||
|
let lines = util::read_file("input/day13.txt");
|
||||||
|
|
||||||
|
let target_time = lines[0].parse::<u32>().unwrap();
|
||||||
|
let part1 = lines[1].split(",").filter(|s| s != &"x")
|
||||||
|
.map(|s| s.parse::<u32>().unwrap())
|
||||||
|
.map(|t| (t, t - (target_time % t)))
|
||||||
|
.min_by_key(|t| t.1)
|
||||||
|
.map(|bt| bt.0 * bt.1)
|
||||||
|
.unwrap();
|
||||||
|
println!("Day 13 Part 1: {}", part1);
|
||||||
|
|
||||||
|
|
||||||
|
let schedule_parts = lines[1].split(",").collect::<Vec<_>>();
|
||||||
|
let mut schedules = Vec::new();
|
||||||
|
// print!("[");
|
||||||
|
for i in 0..schedule_parts.len() {
|
||||||
|
let s = schedule_parts[i];
|
||||||
|
if s == "x" { continue; }
|
||||||
|
let bus_id = s.parse::<u64>().unwrap();
|
||||||
|
let mut offset = i as u64;
|
||||||
|
if offset > bus_id { offset = offset % bus_id; }
|
||||||
|
// print!("(x + {}) mod {} = 0, ", offset, bus_id );
|
||||||
|
schedules.push(Schedule {
|
||||||
|
bus_id, offset
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// println!("]");
|
||||||
|
|
||||||
|
schedules.sort_by_key(|s| u64::max_value() - s.bus_id);
|
||||||
|
let part2 = find_fitting(&schedules);
|
||||||
|
|
||||||
|
println!("Day 13 Part 2: {}", part2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_fitting(schedules: &Vec<Schedule>) -> u64 {
|
||||||
|
|
||||||
|
let mut root_schedule = find_fitting_match(&schedules[0], &schedules[1]);
|
||||||
|
for schedule in schedules.iter().skip(2) {
|
||||||
|
root_schedule = find_fitting_match(schedule, &root_schedule)
|
||||||
|
}
|
||||||
|
return root_schedule.bus_id - root_schedule.offset;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn find_fitting_match(s1: &Schedule, s2: &Schedule) -> Schedule {
|
||||||
|
|
||||||
|
// We know that the pattern repeats every s1.bus_id * s2.bus_id (and at no other times, since all bus_ids are at least co-prime).
|
||||||
|
// So all we need to do is find out what offset works:
|
||||||
|
let match_bus_id = s1.bus_id * s2.bus_id;
|
||||||
|
for mult in 0..s1.bus_id {
|
||||||
|
let offset = mult * s2.bus_id + s2.offset;
|
||||||
|
assert!(offset < match_bus_id, "Offset must not be bigger than the bus_id");
|
||||||
|
let solution = match_bus_id - offset;
|
||||||
|
if (solution + s1.offset) % s1.bus_id == 0 {
|
||||||
|
return Schedule {
|
||||||
|
bus_id: match_bus_id,
|
||||||
|
offset,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic!("Couldn't find match!!!");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Schedule {
|
||||||
|
bus_id: u64,
|
||||||
|
offset: u64,
|
||||||
|
}
|
||||||
@@ -2,4 +2,12 @@ use super::util;
|
|||||||
|
|
||||||
pub fn solve() {
|
pub fn solve() {
|
||||||
let lines = util::read_file("input/dayX.txt");
|
let lines = util::read_file("input/dayX.txt");
|
||||||
|
|
||||||
|
|
||||||
|
let part1 = 0;
|
||||||
|
println!("Day X Part 1: {}", part1);
|
||||||
|
|
||||||
|
|
||||||
|
let part2 = 0;
|
||||||
|
println!("Day X Part 2: {}", part2);
|
||||||
}
|
}
|
||||||
25
src/main.rs
25
src/main.rs
@@ -13,9 +13,11 @@ mod day8;
|
|||||||
mod day9;
|
mod day9;
|
||||||
mod day10;
|
mod day10;
|
||||||
mod day11;
|
mod day11;
|
||||||
|
mod day12;
|
||||||
|
mod day13;
|
||||||
|
|
||||||
const MAX_DAY: u8 = 11;
|
const MAX_DAY: u8 = 13;
|
||||||
const BENCHMARK_AMOUNT: u32 = 100;
|
const BENCHMARK_AMOUNT: u32 = 1000;
|
||||||
|
|
||||||
fn solve(day: u8) {
|
fn solve(day: u8) {
|
||||||
match day {
|
match day {
|
||||||
@@ -30,13 +32,14 @@ fn solve(day: u8) {
|
|||||||
9 => day9::solve(),
|
9 => day9::solve(),
|
||||||
10 => day10::solve(),
|
10 => day10::solve(),
|
||||||
11 => day11::solve(),
|
11 => day11::solve(),
|
||||||
|
12 => day12::solve(),
|
||||||
|
13 => day13::solve(),
|
||||||
_ => println!("This day is not yet implemented")
|
_ => println!("This day is not yet implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
|
||||||
let day_arg_idx = args.iter().position(|a| a == "-d");
|
let day_arg_idx = args.iter().position(|a| a == "-d");
|
||||||
@@ -49,8 +52,11 @@ fn main() {
|
|||||||
|
|
||||||
// This is essentially the warmup for the benchmark:
|
// This is essentially the warmup for the benchmark:
|
||||||
run_once(single_day, day, &mut bench_results);
|
run_once(single_day, day, &mut bench_results);
|
||||||
|
let first_run_time = bench_results[0];
|
||||||
|
|
||||||
if benchmark {
|
if benchmark {
|
||||||
|
// Ignore the warmup run in the rest of the benchmark:
|
||||||
|
bench_results.clear();
|
||||||
for _ in 0..BENCHMARK_AMOUNT {
|
for _ in 0..BENCHMARK_AMOUNT {
|
||||||
run_once(single_day, day, &mut bench_results);
|
run_once(single_day, day, &mut bench_results);
|
||||||
}
|
}
|
||||||
@@ -59,6 +65,19 @@ fn main() {
|
|||||||
let avg_runtime: u128 = bench_results.iter().sum::<u128>() / (bench_results.len() as u128);
|
let avg_runtime: u128 = bench_results.iter().sum::<u128>() / (bench_results.len() as u128);
|
||||||
|
|
||||||
println!("Execution took {} μs {}", avg_runtime, if benchmark { "on average" } else { "" });
|
println!("Execution took {} μs {}", avg_runtime, if benchmark { "on average" } else { "" });
|
||||||
|
if benchmark {
|
||||||
|
bench_results.sort();
|
||||||
|
println!("Min: {} μs, Max: {} μs, Median: {} μs",
|
||||||
|
bench_results[0],
|
||||||
|
bench_results[bench_results.len() - 1],
|
||||||
|
bench_results[bench_results.len() / 2]
|
||||||
|
);
|
||||||
|
println!("First time took {} μs", first_run_time);
|
||||||
|
|
||||||
|
for res in bench_results {
|
||||||
|
println!("{}", res);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(single_day: bool, day: u8, bench_results: &mut Vec<u128>) {
|
fn run_once(single_day: bool, day: u8, bench_results: &mut Vec<u128>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user