Compare commits
1 Commits
9684b28a65
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f1500accd |
143
Cargo.lock
generated
143
Cargo.lock
generated
@@ -5,7 +5,9 @@ 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]]
|
||||||
@@ -17,18 +19,147 @@ 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"
|
||||||
@@ -47,6 +178,12 @@ 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"
|
||||||
@@ -55,3 +192,9 @@ 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,3 +9,5 @@ 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
795
input/day12.txt
@@ -1,795 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
F10
|
|
||||||
N3
|
|
||||||
F7
|
|
||||||
R90
|
|
||||||
F11
|
|
||||||
96
src/day11.rs
96
src/day11.rs
@@ -2,19 +2,27 @@ 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, 1);
|
let seats = Seats::parse(&lines);
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,28 +31,39 @@ 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();
|
||||||
|
|
||||||
loop {
|
let mut seat_idxs = Vec::new();
|
||||||
let mut changes = false;
|
for y in 0..seats.height {
|
||||||
for y in 1..seats.height-1 {
|
for x in 0..seats.width {
|
||||||
for x in 1..seats.width-1 {
|
let seat = seats.get(&x, &y);
|
||||||
let seat = last_seats.get(&x, &y);
|
if seat != &Floor {
|
||||||
if seat != &Floor {
|
seat_idxs.push((x, y));
|
||||||
let occupied = last_seats.count_occupied_neighbors(&x, &y);
|
|
||||||
if seat == &EmptySeat && occupied == 0 {
|
|
||||||
changes = true;
|
|
||||||
next_seats.set(&x, &y, FilledSeat);
|
|
||||||
} else if seat == &FilledSeat && occupied >= 4 {
|
|
||||||
next_seats.set(&x, &y, EmptySeat);
|
|
||||||
changes = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// next_seats.print();
|
}
|
||||||
if !changes {
|
loop {
|
||||||
|
let changes: Vec<(usize, usize, &GridState)> = seat_idxs.par_iter().map(|pos| {
|
||||||
|
let x = &pos.0;
|
||||||
|
let y = &pos.1;
|
||||||
|
let seat = last_seats.get(x, y);
|
||||||
|
let occupied = last_seats.count_occupied_neighbors(x, y);
|
||||||
|
if seat == &EmptySeat && occupied == 0 {
|
||||||
|
return Option::from((pos.0, pos.1, &FilledSeat));
|
||||||
|
} else if seat == &FilledSeat && occupied >= 4 {
|
||||||
|
return Option::from((pos.0, pos.1, &EmptySeat));
|
||||||
|
} else {
|
||||||
|
return Option::None;
|
||||||
|
}
|
||||||
|
}).filter(|o| o.is_some()).map(|o| o.unwrap()).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
if changes.is_empty() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for change in changes {
|
||||||
|
next_seats.set(&change.0, &change.1, *change.2);
|
||||||
|
}
|
||||||
|
// next_seats.print();
|
||||||
|
|
||||||
last_seats = next_seats.clone();
|
last_seats = next_seats.clone();
|
||||||
}
|
}
|
||||||
return last_seats.grid.iter().filter(|s| s == &&FilledSeat).count();
|
return last_seats.grid.iter().filter(|s| s == &&FilledSeat).count();
|
||||||
@@ -55,7 +74,11 @@ 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 {
|
||||||
@@ -66,8 +89,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 {
|
||||||
changes = true;
|
|
||||||
next_seats.set(&x, &y, EmptySeat);
|
next_seats.set(&x, &y, EmptySeat);
|
||||||
|
changes = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,9 +99,15 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,16 +123,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>, padding: usize) -> Seats {
|
fn parse(lines: &Vec<String>) -> Seats {
|
||||||
|
|
||||||
let height = lines.len() + padding * 2;
|
let height = lines.len();
|
||||||
let width = lines[0].len() + padding * 2;
|
let width = lines[0].len();
|
||||||
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 + padding) + (y + padding) * width] = GridState::parse(&line_chars.next().unwrap())
|
grid[x + y * width] = GridState::parse(&line_chars.next().unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,15 +199,20 @@ 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 self.is_occupied(&(x - &ONE), &(y - &ONE)) { 1 } else { 0 } +
|
if !x_lower && !y_lower && self.is_occupied(&(x - &ONE), &(y - &ONE)) { 1 } else { 0 } +
|
||||||
if self.is_occupied(&(x - &ONE), &y) { 1 } else { 0 } +
|
if !x_lower && self.is_occupied(&(x - &ONE), &y) { 1 } else { 0 } +
|
||||||
if self.is_occupied(&(x - &ONE), &(y + ONE)) { 1 } else { 0 } +
|
if !x_lower && !y_upper && self.is_occupied(&(x - &ONE), &(y + ONE)) { 1 } else { 0 } +
|
||||||
if self.is_occupied(&x, &(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 + ONE), &(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) { 1 } else { 0 } +
|
if !x_upper && self.is_occupied(&(x + ONE), &y) { 1 } else { 0 } +
|
||||||
if self.is_occupied(&(x + ONE), &(y + ONE)) { 1 } else { 0 }
|
if !x_upper && !y_upper && self.is_occupied(&(x + ONE), &(y + ONE)) { 1 } else { 0 }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
174
src/day12.rs
174
src/day12.rs
@@ -1,174 +0,0 @@
|
|||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,4 @@ 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);
|
|
||||||
}
|
}
|
||||||
@@ -13,9 +13,8 @@ mod day8;
|
|||||||
mod day9;
|
mod day9;
|
||||||
mod day10;
|
mod day10;
|
||||||
mod day11;
|
mod day11;
|
||||||
mod day12;
|
|
||||||
|
|
||||||
const MAX_DAY: u8 = 12;
|
const MAX_DAY: u8 = 11;
|
||||||
const BENCHMARK_AMOUNT: u32 = 100;
|
const BENCHMARK_AMOUNT: u32 = 100;
|
||||||
|
|
||||||
fn solve(day: u8) {
|
fn solve(day: u8) {
|
||||||
@@ -31,7 +30,6 @@ 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(),
|
|
||||||
_ => println!("This day is not yet implemented")
|
_ => println!("This day is not yet implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user