Compare commits
7 Commits
8069595c2e
...
d7e478ca15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7e478ca15 | ||
|
|
79719bbb10 | ||
|
|
737572af89 | ||
|
|
067cc9c888 | ||
|
|
a6dc0b166d | ||
|
|
748aaaf82b | ||
|
|
64a7833fd9 |
193
.vscode/launch.json
vendored
Normal file
193
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'part01'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=part01",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part01",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug unit tests in executable 'part01'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--no-run",
|
||||||
|
"--bin=part01",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part01",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'part02'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=part02",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part02",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug unit tests in executable 'part02'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--no-run",
|
||||||
|
"--bin=part02",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part02",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'part03'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=part03",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part03",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug unit tests in executable 'part03'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--no-run",
|
||||||
|
"--bin=part03",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part03",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'part04'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=part04",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part04",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug unit tests in executable 'part04'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"test",
|
||||||
|
"--no-run",
|
||||||
|
"--bin=part04",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part04",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'part05'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=part05",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part05",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug executable 'part06'",
|
||||||
|
"cargo": {
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"--bin=part06",
|
||||||
|
"--package=advent-of-code-2023"
|
||||||
|
],
|
||||||
|
"filter": {
|
||||||
|
"name": "part06",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
363
Cargo.lock
generated
Normal file
363
Cargo.lock
generated
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "advent-of-code-2023"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cached",
|
||||||
|
"rayon",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ahash"
|
||||||
|
version = "0.8.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"once_cell",
|
||||||
|
"version_check",
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "allocator-api2"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cached"
|
||||||
|
version = "0.46.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c7c8c50262271cdf5abc979a5f76515c234e764fa025d1ba4862c0f0bcda0e95"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"cached_proc_macro",
|
||||||
|
"cached_proc_macro_types",
|
||||||
|
"hashbrown",
|
||||||
|
"instant",
|
||||||
|
"once_cell",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cached_proc_macro"
|
||||||
|
version = "0.18.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c878c71c2821aa2058722038a59a67583a4240524687c6028571c9b395ded61f"
|
||||||
|
dependencies = [
|
||||||
|
"darling",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cached_proc_macro_types"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-deque"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-epoch",
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-epoch"
|
||||||
|
version = "0.9.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"cfg-if",
|
||||||
|
"crossbeam-utils",
|
||||||
|
"memoffset",
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling"
|
||||||
|
version = "0.14.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core",
|
||||||
|
"darling_macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_core"
|
||||||
|
version = "0.14.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
|
||||||
|
dependencies = [
|
||||||
|
"fnv",
|
||||||
|
"ident_case",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"strsim",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "darling_macro"
|
||||||
|
version = "0.14.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
|
||||||
|
dependencies = [
|
||||||
|
"darling_core",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.14.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"allocator-api2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ident_case"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "instant"
|
||||||
|
version = "0.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.70"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rayon"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"rayon-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rayon-core"
|
||||||
|
version = "1.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-deque",
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.39"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.50"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.50"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.7.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d075cf85bbb114e933343e087b92f2146bac0d55b534cbb8188becf0039948e"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.7.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "86cd5ca076997b97ef09d3ad65efe811fa68c9e874cb636ccb211223a813b0c2"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.39",
|
||||||
|
]
|
||||||
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "advent-of-code-2023"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
cached = "0.46.1"
|
||||||
|
rayon = "1.8.0"
|
||||||
|
regex = "1.10.2"
|
||||||
57
src/bin/part01.rs
Normal file
57
src/bin/part01.rs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
fn main() {
|
||||||
|
let lines = std::fs::read_to_string("src/bin/part01.txt")
|
||||||
|
.expect("Could not read file")
|
||||||
|
.lines()
|
||||||
|
.map(|line| line.parse::<String>().unwrap())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let mut sum = 0;
|
||||||
|
|
||||||
|
for i in 0..lines.len() {
|
||||||
|
let mut first_digit: Option<u32> = None;
|
||||||
|
let mut last_digit: Option<u32> = None;
|
||||||
|
let line = replace_string_numbers(lines[i].clone());
|
||||||
|
|
||||||
|
for c in line.chars() {
|
||||||
|
if c.is_digit(10) {
|
||||||
|
if first_digit.is_none() {
|
||||||
|
first_digit = c.to_digit(10);
|
||||||
|
} else {
|
||||||
|
last_digit = c.to_digit(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if last_digit.is_none() {
|
||||||
|
last_digit = first_digit;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum += first_digit.unwrap() * 10 + last_digit.unwrap();
|
||||||
|
|
||||||
|
//println!("{}: {}{} -> {}", lines[i], first_digit.unwrap(), last_digit.unwrap(), sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("\nTotal sum: {}", sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn replace_string_numbers(s: String) -> String {
|
||||||
|
let mut s = String::from(s);
|
||||||
|
s = s.replace("twone", "21");
|
||||||
|
s = s.replace("threeight", "38");
|
||||||
|
s = s.replace("nineight", "98");
|
||||||
|
s = s.replace("eightwo", "82");
|
||||||
|
s = s.replace("fiveight", "58");
|
||||||
|
s = s.replace("sevenine", "79");
|
||||||
|
s = s.replace("eighthree", "83");
|
||||||
|
s = s.replace("oneight", "18");
|
||||||
|
s = s.replace("one", "1");
|
||||||
|
s = s.replace("two", "2");
|
||||||
|
s = s.replace("three", "3");
|
||||||
|
s = s.replace("four", "4");
|
||||||
|
s = s.replace("five", "5");
|
||||||
|
s = s.replace("six", "6");
|
||||||
|
s = s.replace("seven", "7");
|
||||||
|
s = s.replace("eight", "8");
|
||||||
|
s = s.replace("nine", "9");
|
||||||
|
|
||||||
|
s
|
||||||
|
}
|
||||||
1000
src/bin/part01.txt
Normal file
1000
src/bin/part01.txt
Normal file
File diff suppressed because it is too large
Load Diff
97
src/bin/part02.rs
Normal file
97
src/bin/part02.rs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
struct Game {
|
||||||
|
id: u8,
|
||||||
|
draws: Vec<Draw>,
|
||||||
|
minimal_set: Draw
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Game {
|
||||||
|
fn is_valid(&self) -> bool {
|
||||||
|
self.draws.iter().any(|draw| !draw.is_valid()) == false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_invalid_draws(&self) -> Vec<&Draw> {
|
||||||
|
self.draws.iter().filter(|draw| !draw.is_valid()).collect::<Vec<_>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_power(&self) -> u32 {
|
||||||
|
self.minimal_set.red as u32 * self.minimal_set.green as u32 * self.minimal_set.blue as u32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Draw {
|
||||||
|
red: u8,
|
||||||
|
green: u8,
|
||||||
|
blue: u8
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Draw {
|
||||||
|
fn is_valid(&self) -> bool {
|
||||||
|
self.red <= MAX_RED && self.green <= MAX_GREEN && self.blue <= MAX_BLUE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_RED: u8 = 12;
|
||||||
|
const MAX_GREEN: u8 = 13;
|
||||||
|
const MAX_BLUE: u8 = 14;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let games = load_input();
|
||||||
|
|
||||||
|
let valid_games = games.iter().filter(|game| {
|
||||||
|
let is_valid = game.is_valid();
|
||||||
|
println!("Game {} is valid: {} | Power: {}", game.id, is_valid, game.get_power());
|
||||||
|
if !is_valid {
|
||||||
|
println!("\tInvalid draws: {:?}", game.get_invalid_draws());
|
||||||
|
}
|
||||||
|
is_valid
|
||||||
|
}).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
println!("Valid games: {}, Sum of IDs: {}, Sum of powers: {}",
|
||||||
|
valid_games.len(),
|
||||||
|
valid_games.iter().map(|g| g.id as u32).sum::<u32>(),
|
||||||
|
games.iter().map(|g| g.get_power()).sum::<u32>());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_input() -> Vec<Game> {
|
||||||
|
let re = Regex::new(r"(?:(?P<green>\d+) green|(?P<blue>\d+) blue|(?P<red>\d+) red)+").unwrap();
|
||||||
|
|
||||||
|
let games = std::fs::read_to_string("src/bin/part02.txt")
|
||||||
|
.expect("Could not read file")
|
||||||
|
.lines()
|
||||||
|
.map(|line| {
|
||||||
|
let mut line = line.split(": ");
|
||||||
|
let id = line.next().unwrap().strip_prefix("Game ").unwrap().parse::<u8>().unwrap();
|
||||||
|
let raw_draws = line.next().unwrap().split("; ");
|
||||||
|
let draws = raw_draws.map(|draw| {
|
||||||
|
let mut red: u8 = 0;
|
||||||
|
let mut green: u8 = 0;
|
||||||
|
let mut blue: u8 = 0;
|
||||||
|
for res in re.captures_iter(draw) {
|
||||||
|
if let Some(m) = res.name("red") {
|
||||||
|
red = m.as_str().parse::<u8>().unwrap();
|
||||||
|
}
|
||||||
|
if let Some(m) = res.name("green") {
|
||||||
|
green = m.as_str().parse::<u8>().unwrap();
|
||||||
|
}
|
||||||
|
if let Some(m) = res.name("blue") {
|
||||||
|
blue = m.as_str().parse::<u8>().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Draw { red, green, blue }
|
||||||
|
}).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let minimal_set = Draw {
|
||||||
|
red: draws.iter().map(|draw| draw.red).max().unwrap(),
|
||||||
|
green: draws.iter().map(|draw| draw.green).max().unwrap(),
|
||||||
|
blue: draws.iter().map(|draw| draw.blue).max().unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
Game { id, draws, minimal_set }
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
games
|
||||||
|
}
|
||||||
100
src/bin/part02.txt
Normal file
100
src/bin/part02.txt
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
Game 1: 4 red, 8 green; 8 green, 6 red; 13 red, 8 green; 2 blue, 4 red, 4 green
|
||||||
|
Game 2: 5 blue; 1 red, 3 blue; 1 red, 7 blue, 1 green; 1 red, 8 blue; 7 blue, 1 red; 4 blue, 1 green, 1 red
|
||||||
|
Game 3: 8 blue, 5 green, 15 red; 6 red, 6 blue, 3 green; 8 red, 2 green; 10 blue, 10 red, 6 green; 8 red, 6 blue; 15 red, 5 green, 2 blue
|
||||||
|
Game 4: 10 green, 12 red, 14 blue; 5 green, 9 red, 7 blue; 14 blue, 12 red; 8 blue, 7 green, 11 red
|
||||||
|
Game 5: 13 blue, 10 red, 7 green; 3 green, 8 red, 4 blue; 16 red, 5 green, 5 blue; 2 blue, 9 red, 7 green; 5 red, 14 blue, 3 green; 2 red, 11 blue, 2 green
|
||||||
|
Game 6: 3 blue, 1 green; 10 green, 12 red, 6 blue; 3 green, 2 red, 5 blue; 2 blue, 11 green, 2 red; 1 red, 5 blue, 9 green
|
||||||
|
Game 7: 2 blue, 10 green; 3 red, 10 blue; 3 green, 8 blue, 5 red; 8 green, 10 blue, 2 red
|
||||||
|
Game 8: 15 red, 12 blue, 5 green; 10 red, 12 blue, 5 green; 10 red, 7 green
|
||||||
|
Game 9: 18 blue, 14 red; 3 green, 9 blue; 1 blue, 11 red; 5 red, 7 blue, 3 green; 8 red, 4 green, 1 blue
|
||||||
|
Game 10: 2 blue; 10 green, 4 blue, 3 red; 5 green, 4 red, 4 blue; 1 red, 3 blue, 4 green; 2 blue, 5 red, 3 green; 3 green, 2 red, 2 blue
|
||||||
|
Game 11: 4 blue, 19 green; 19 blue, 12 green, 17 red; 11 red, 10 blue, 17 green; 9 green, 18 blue; 14 green, 9 red, 18 blue; 15 blue, 6 green, 19 red
|
||||||
|
Game 12: 1 green, 6 blue, 2 red; 6 blue, 2 red, 8 green; 2 green, 2 red, 7 blue; 1 red, 3 blue, 6 green
|
||||||
|
Game 13: 2 red, 11 blue, 4 green; 2 red, 7 blue; 9 green, 1 red, 12 blue; 13 blue, 8 green; 11 blue, 8 green, 1 red; 1 red, 2 blue
|
||||||
|
Game 14: 1 green, 4 blue, 11 red; 11 green, 6 blue, 7 red; 7 green, 6 blue, 4 red; 12 blue, 10 red, 11 green
|
||||||
|
Game 15: 1 green, 19 red, 3 blue; 11 red, 3 blue; 20 red, 4 blue
|
||||||
|
Game 16: 3 red, 1 green, 7 blue; 3 blue, 4 red, 1 green; 6 blue, 7 red, 3 green
|
||||||
|
Game 17: 7 blue, 4 red, 19 green; 7 green, 4 red; 8 green, 2 red, 4 blue
|
||||||
|
Game 18: 1 red, 1 blue, 6 green; 2 red, 6 green, 1 blue; 4 green, 1 red, 1 blue
|
||||||
|
Game 19: 4 blue, 8 green, 6 red; 2 red, 9 green, 4 blue; 9 green, 8 red, 6 blue; 3 red, 6 blue, 9 green; 8 red, 4 blue, 7 green
|
||||||
|
Game 20: 3 blue, 7 green, 13 red; 13 blue; 12 red, 14 blue; 3 red, 6 green, 8 blue
|
||||||
|
Game 21: 5 green, 2 red, 10 blue; 2 red, 2 green, 6 blue; 1 blue, 1 red, 7 green; 4 blue, 1 red, 2 green
|
||||||
|
Game 22: 2 red; 1 green, 7 red; 3 red, 1 green, 1 blue; 4 red, 5 green, 3 blue; 1 blue, 2 green
|
||||||
|
Game 23: 15 red, 1 blue, 3 green; 6 blue, 3 green, 2 red; 6 green, 4 red, 1 blue
|
||||||
|
Game 24: 17 green; 1 red, 2 blue, 3 green; 10 blue, 1 green; 1 green; 1 red, 2 blue, 1 green
|
||||||
|
Game 25: 2 green, 8 blue, 1 red; 1 blue, 1 red, 9 green; 1 blue, 2 green, 2 red; 3 red, 6 blue
|
||||||
|
Game 26: 12 red, 19 green, 4 blue; 2 red, 10 blue, 15 green; 14 blue, 17 red, 3 green; 1 green, 15 red, 3 blue
|
||||||
|
Game 27: 11 green, 1 red, 9 blue; 3 green, 10 blue; 9 green, 10 blue, 1 red; 4 green, 3 blue, 1 red; 2 blue, 5 green, 2 red; 17 blue, 2 red, 5 green
|
||||||
|
Game 28: 10 green, 10 red, 5 blue; 5 red, 4 blue, 8 green; 3 green, 10 red, 3 blue; 2 blue, 8 green, 1 red; 6 red, 1 green, 4 blue
|
||||||
|
Game 29: 3 blue, 11 red, 1 green; 5 blue, 3 green, 6 red; 8 red, 12 blue, 10 green; 1 blue, 4 red, 1 green
|
||||||
|
Game 30: 10 blue, 1 red, 2 green; 1 red, 8 blue, 2 green; 4 blue, 3 green; 5 green, 1 red, 3 blue; 3 green, 14 blue
|
||||||
|
Game 31: 3 red, 7 green, 6 blue; 11 red, 4 green, 2 blue; 1 green, 11 red, 8 blue; 6 green, 5 blue, 5 red; 4 green, 3 blue, 15 red
|
||||||
|
Game 32: 9 green, 1 blue, 10 red; 13 red, 7 green; 12 red, 6 green, 1 blue
|
||||||
|
Game 33: 9 green, 4 red, 6 blue; 2 red, 4 blue, 1 green; 2 blue, 11 red, 9 green
|
||||||
|
Game 34: 8 green, 6 red; 4 blue, 3 green; 6 red, 1 blue, 9 green; 10 green, 1 red; 2 red, 2 blue, 2 green; 2 blue
|
||||||
|
Game 35: 4 blue, 8 green, 8 red; 1 blue, 10 green; 5 green, 8 red; 4 green; 6 red, 1 blue, 6 green
|
||||||
|
Game 36: 4 red, 10 blue, 16 green; 18 blue, 5 red, 5 green; 16 green, 11 blue, 1 red; 6 green, 10 blue; 4 red, 9 green, 17 blue; 1 red, 9 blue, 14 green
|
||||||
|
Game 37: 1 red, 13 green, 5 blue; 2 red, 12 green, 12 blue; 5 red, 11 blue, 5 green; 9 green, 4 blue
|
||||||
|
Game 38: 1 green, 12 blue, 1 red; 11 blue, 3 red, 1 green; 17 red, 11 blue; 8 red, 2 blue
|
||||||
|
Game 39: 11 blue, 12 red, 1 green; 1 blue, 1 green, 4 red; 3 green, 6 blue, 3 red
|
||||||
|
Game 40: 1 blue, 1 red; 9 green, 2 red, 2 blue; 9 green, 3 red; 8 green, 4 blue, 4 red; 3 green, 3 red
|
||||||
|
Game 41: 7 blue, 8 red, 3 green; 4 red, 7 green, 1 blue; 5 blue, 6 red, 5 green; 4 blue, 9 red; 2 green, 9 blue, 5 red
|
||||||
|
Game 42: 8 blue, 17 green, 7 red; 6 red, 11 green, 13 blue; 7 red, 3 blue, 14 green; 2 red, 12 blue, 2 green; 18 green, 8 red; 10 green, 5 blue
|
||||||
|
Game 43: 5 green, 9 red, 3 blue; 3 red, 5 green; 6 green, 1 blue, 10 red; 8 blue, 1 green, 2 red
|
||||||
|
Game 44: 1 red, 5 blue; 4 green, 6 red, 2 blue; 12 green, 8 red; 4 blue, 2 red, 9 green; 1 blue, 5 green, 3 red
|
||||||
|
Game 45: 9 blue, 5 red, 6 green; 10 blue, 7 green, 8 red; 1 red, 1 green, 10 blue; 2 red, 1 green, 11 blue; 11 red
|
||||||
|
Game 46: 14 blue, 8 green, 2 red; 10 green, 8 blue; 7 blue, 12 green; 14 green, 10 blue, 2 red
|
||||||
|
Game 47: 5 blue, 7 green, 1 red; 5 blue, 5 green, 3 red; 2 red, 8 green, 3 blue; 2 red, 2 green
|
||||||
|
Game 48: 2 red, 2 blue, 1 green; 1 green, 1 blue, 3 red; 1 blue, 1 red; 3 green, 8 blue
|
||||||
|
Game 49: 7 red, 2 blue, 8 green; 8 red, 4 green; 2 blue, 4 red, 8 green
|
||||||
|
Game 50: 9 red, 4 blue, 10 green; 11 red, 7 green, 4 blue; 4 green, 16 red, 2 blue; 13 red, 9 blue, 3 green; 1 red, 6 blue
|
||||||
|
Game 51: 8 blue, 2 red, 3 green; 2 blue, 2 red; 4 blue, 1 green; 1 red, 2 blue, 2 green; 5 green, 6 blue, 1 red
|
||||||
|
Game 52: 12 blue, 8 red; 11 green, 9 red, 11 blue; 8 blue, 5 green, 8 red; 3 red, 11 blue, 11 green; 12 blue, 6 green, 5 red; 10 red, 8 green
|
||||||
|
Game 53: 9 green, 6 red, 3 blue; 4 blue, 5 green, 3 red; 11 green, 5 blue, 2 red; 4 red, 9 green
|
||||||
|
Game 54: 13 blue, 8 green; 15 blue, 3 red, 7 green; 8 green, 1 blue; 8 blue, 3 red, 6 green; 3 red, 1 green, 12 blue; 9 green, 3 red, 2 blue
|
||||||
|
Game 55: 2 red, 1 blue, 2 green; 4 blue, 3 green, 1 red; 4 red, 7 green, 4 blue; 7 green, 3 red, 1 blue; 2 blue, 4 green, 1 red; 5 blue, 1 red, 4 green
|
||||||
|
Game 56: 14 green, 1 blue, 4 red; 3 red, 1 blue; 10 red, 8 blue; 8 red, 7 blue, 3 green; 3 green, 12 blue, 4 red; 7 red, 2 green
|
||||||
|
Game 57: 7 blue, 8 green, 6 red; 7 green, 5 blue, 3 red; 2 red, 8 blue, 9 green
|
||||||
|
Game 58: 7 green, 8 red, 3 blue; 7 red, 5 blue, 9 green; 4 blue, 3 red, 9 green; 1 green; 5 green, 2 blue; 5 blue, 7 green, 2 red
|
||||||
|
Game 59: 2 blue, 10 green; 8 blue, 10 red, 1 green; 1 red, 10 blue, 7 green; 2 red, 7 blue, 1 green; 5 green, 3 blue
|
||||||
|
Game 60: 1 green, 2 blue; 5 red, 2 green, 2 blue; 2 green, 3 red
|
||||||
|
Game 61: 3 green, 2 red; 10 green, 7 red, 2 blue; 8 green, 2 blue; 5 green, 3 red, 1 blue; 12 green, 1 red; 1 blue, 13 green, 6 red
|
||||||
|
Game 62: 11 green, 2 red; 3 blue, 3 red; 2 blue, 1 red, 10 green; 11 green, 3 blue
|
||||||
|
Game 63: 7 blue; 7 red, 1 green, 8 blue; 5 red, 14 blue, 1 green
|
||||||
|
Game 64: 2 green, 12 blue, 1 red; 18 blue, 10 red; 9 blue, 2 green, 13 red; 1 red, 1 green, 15 blue
|
||||||
|
Game 65: 6 blue, 8 red, 8 green; 2 green, 9 red, 9 blue; 3 green, 9 red, 1 blue; 10 red, 4 blue, 2 green; 7 blue, 5 red, 5 green
|
||||||
|
Game 66: 14 red, 3 green, 9 blue; 3 blue, 7 green, 12 red; 5 red, 8 green, 1 blue; 12 red, 5 green, 4 blue; 5 green, 14 blue
|
||||||
|
Game 67: 1 blue, 9 red, 7 green; 12 red, 9 green, 1 blue; 13 red, 4 green, 2 blue; 1 red, 1 blue, 5 green; 10 red, 2 blue
|
||||||
|
Game 68: 12 green, 2 red; 1 red, 4 green, 7 blue; 3 red, 4 blue, 14 green; 6 blue, 6 green; 7 blue, 4 green, 3 red
|
||||||
|
Game 69: 2 green, 17 blue, 9 red; 6 blue, 3 green, 4 red; 11 blue, 4 red, 6 green
|
||||||
|
Game 70: 11 blue, 10 red, 12 green; 9 red, 10 blue, 5 green; 2 red, 3 green, 9 blue; 5 green, 6 blue, 6 red; 12 green, 8 red, 10 blue
|
||||||
|
Game 71: 7 blue, 3 red; 1 green, 11 blue, 1 red; 1 red, 5 blue, 1 green
|
||||||
|
Game 72: 9 red, 7 blue; 1 green, 6 blue; 15 red, 6 blue; 5 red, 4 blue; 4 blue, 4 red, 1 green
|
||||||
|
Game 73: 10 green, 4 red; 1 green, 5 red; 3 red, 1 green; 1 blue, 9 green, 6 red
|
||||||
|
Game 74: 6 red, 3 blue, 8 green; 5 green, 9 red, 1 blue; 1 blue, 1 green, 2 red
|
||||||
|
Game 75: 2 blue, 3 green; 3 blue, 7 green, 1 red; 6 green, 1 red; 5 green, 1 blue; 7 green, 3 blue
|
||||||
|
Game 76: 4 red, 2 blue; 1 green, 7 red; 2 blue, 3 red; 1 green, 1 red, 1 blue; 4 red, 1 green
|
||||||
|
Game 77: 18 green, 19 red, 11 blue; 1 blue, 18 red; 5 blue, 10 red, 16 green
|
||||||
|
Game 78: 3 red, 8 blue, 1 green; 2 red, 3 blue; 1 green, 6 red, 12 blue
|
||||||
|
Game 79: 5 red, 4 green, 9 blue; 3 blue; 4 red, 5 green, 2 blue; 7 blue, 5 green, 8 red; 5 red, 6 green; 7 blue, 5 green
|
||||||
|
Game 80: 8 green, 11 red, 3 blue; 15 red, 4 blue, 8 green; 6 green, 14 red
|
||||||
|
Game 81: 11 green, 5 red; 7 green, 14 blue, 4 red; 7 red, 8 blue, 2 green; 10 red, 3 green, 18 blue; 3 red, 1 green
|
||||||
|
Game 82: 2 blue, 5 red; 3 green, 5 red, 7 blue; 3 green, 4 blue, 2 red; 10 blue, 2 green, 2 red; 8 blue, 2 red; 3 green, 3 red, 7 blue
|
||||||
|
Game 83: 7 red, 12 green, 1 blue; 5 blue, 17 green, 5 red; 9 red, 3 blue; 2 blue, 1 red, 20 green; 5 red, 6 blue; 2 blue, 3 red, 11 green
|
||||||
|
Game 84: 1 blue, 7 red, 6 green; 6 red, 8 green, 10 blue; 8 green, 1 blue, 6 red; 8 red, 4 blue, 6 green; 3 red, 12 blue, 8 green; 3 red, 2 blue, 7 green
|
||||||
|
Game 85: 1 blue, 1 green, 8 red; 9 blue, 9 green, 2 red; 10 green, 12 red, 7 blue; 7 green, 2 blue, 7 red; 7 red, 3 green; 11 red, 9 blue, 5 green
|
||||||
|
Game 86: 4 blue, 8 red; 4 red, 3 green; 7 blue, 12 red, 4 green; 4 green, 8 blue, 3 red
|
||||||
|
Game 87: 6 blue, 19 green, 5 red; 20 green, 5 red, 5 blue; 8 red, 3 blue, 9 green; 11 blue, 7 green, 7 red; 17 green, 11 blue
|
||||||
|
Game 88: 1 green, 2 red, 5 blue; 2 blue, 11 green; 3 red, 3 blue, 6 green; 4 blue, 2 green, 1 red; 8 green, 4 blue
|
||||||
|
Game 89: 19 red, 15 green, 10 blue; 17 green, 1 red, 4 blue; 13 green, 10 blue, 15 red
|
||||||
|
Game 90: 3 blue, 1 red; 4 blue, 1 red, 1 green; 4 green, 3 red; 4 red, 4 green, 5 blue; 2 green, 3 blue; 4 red, 2 green, 4 blue
|
||||||
|
Game 91: 8 red, 4 blue, 16 green; 17 green, 5 blue, 4 red; 10 green, 6 red; 11 red, 7 blue; 14 blue, 4 red
|
||||||
|
Game 92: 1 green, 3 red, 1 blue; 2 blue, 2 green, 5 red; 2 blue, 8 red; 1 blue, 2 green, 14 red; 3 red; 1 blue, 9 red
|
||||||
|
Game 93: 11 blue, 7 red, 8 green; 8 red, 6 blue, 5 green; 4 blue, 4 green, 6 red
|
||||||
|
Game 94: 2 green, 1 blue; 5 green, 5 red, 4 blue; 7 green, 2 blue; 5 red, 1 green, 3 blue; 2 blue, 1 green, 5 red; 1 red, 3 blue, 5 green
|
||||||
|
Game 95: 3 red; 7 green, 4 red, 7 blue; 5 red, 5 blue
|
||||||
|
Game 96: 3 red, 5 blue, 1 green; 3 blue, 14 red, 2 green; 7 blue, 3 red, 2 green; 15 red, 5 blue
|
||||||
|
Game 97: 17 red, 8 green, 6 blue; 8 blue, 9 green; 4 green, 18 red
|
||||||
|
Game 98: 9 blue, 2 green; 4 red, 6 blue, 3 green; 2 red; 14 red, 12 blue
|
||||||
|
Game 99: 4 red, 3 green, 3 blue; 2 red, 2 blue; 7 green, 3 blue; 5 red, 2 green
|
||||||
|
Game 100: 5 green, 7 red, 4 blue; 11 green, 9 red, 8 blue; 2 blue, 12 green
|
||||||
193
src/bin/part03.rs
Normal file
193
src/bin/part03.rs
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Line {
|
||||||
|
parts: Vec<PartNumber>,
|
||||||
|
symbols: Vec<Symbol>,
|
||||||
|
raw: String
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Symbol {
|
||||||
|
text: String,
|
||||||
|
position: u32
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
struct PartNumber {
|
||||||
|
num: u32,
|
||||||
|
position: u32,
|
||||||
|
adjacent_horizontal: bool,
|
||||||
|
adjacent_vertical: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartNumber {
|
||||||
|
fn is_valid(&self) -> bool {
|
||||||
|
self.adjacent_horizontal || self.adjacent_vertical
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let matrix = load_input();
|
||||||
|
let mut analyzed_matrix: Vec<Line> = Vec::new();
|
||||||
|
let mut analyzed_parts: Vec<PartNumber> = Vec::new();
|
||||||
|
let mut gear_ratios: Vec<u32> = Vec::new();
|
||||||
|
|
||||||
|
for (row_index, row) in matrix.iter().enumerate() {
|
||||||
|
for (_, part) in row.parts.iter().enumerate() {
|
||||||
|
let mut adjacent_horizontal = false;
|
||||||
|
let mut adjacent_vertical = false;
|
||||||
|
|
||||||
|
if row.symbols.iter().find(|s|
|
||||||
|
(part.position > 0 && s.position == part.position - 1) ||
|
||||||
|
s.position == part.position + part.num.to_string().len() as u32
|
||||||
|
).is_some() {
|
||||||
|
adjacent_horizontal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if row_index > 0 && matrix[row_index - 1].symbols.iter().find(|s|
|
||||||
|
(part.position > 0 && s.position >= part.position - 1) &&
|
||||||
|
s.position <= part.position + part.num.to_string().len() as u32
|
||||||
|
).is_some(){
|
||||||
|
adjacent_vertical = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if row_index < matrix.len() - 1 && matrix[row_index + 1].symbols.iter().find(|s|
|
||||||
|
(part.position > 0 && s.position >= part.position - 1) &&
|
||||||
|
s.position <= part.position + part.num.to_string().len() as u32
|
||||||
|
).is_some(){
|
||||||
|
adjacent_vertical = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if analyzed_matrix.len() <= row_index {
|
||||||
|
analyzed_matrix.push(Line {
|
||||||
|
parts: Vec::new(),
|
||||||
|
symbols: Vec::new(),
|
||||||
|
raw: row.raw.clone()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
analyzed_matrix[row_index].parts.push(PartNumber {
|
||||||
|
num: part.num,
|
||||||
|
position: part.position,
|
||||||
|
adjacent_horizontal,
|
||||||
|
adjacent_vertical
|
||||||
|
});
|
||||||
|
|
||||||
|
analyzed_parts.push(PartNumber {
|
||||||
|
num: part.num,
|
||||||
|
position: part.position,
|
||||||
|
adjacent_horizontal,
|
||||||
|
adjacent_vertical
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
print!("{} ->", row.raw);
|
||||||
|
|
||||||
|
for (_, symbol) in row.symbols.iter().enumerate() {
|
||||||
|
if symbol.text != "*" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut adjacent_parts: Vec<PartNumber> = Vec::new();
|
||||||
|
let pred = |p: &&PartNumber| p.position + p.num.to_string().len() as u32 >= symbol.position && p.position <= symbol.position + 1;
|
||||||
|
|
||||||
|
adjacent_parts.extend(row.parts.iter().filter(pred));
|
||||||
|
if row_index > 0 {
|
||||||
|
adjacent_parts.extend(matrix[row_index-1].parts.iter().filter(pred));
|
||||||
|
}
|
||||||
|
if row_index + 1 <= matrix.len() {
|
||||||
|
adjacent_parts.extend(matrix[row_index+1].parts.iter().filter(pred));
|
||||||
|
}
|
||||||
|
|
||||||
|
if adjacent_parts.len() == 2 {
|
||||||
|
print!(" {} * {}, ", adjacent_parts[0].num, adjacent_parts[1].num);
|
||||||
|
gear_ratios.push(adjacent_parts[0].num * adjacent_parts[1].num);
|
||||||
|
} else if adjacent_parts.len() > 0 {
|
||||||
|
print!(" (");
|
||||||
|
for (i, part) in adjacent_parts.iter().enumerate() {
|
||||||
|
print!("{}", part.num);
|
||||||
|
if i < adjacent_parts.len() - 1 {
|
||||||
|
print!(" * ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print!("), ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!();
|
||||||
|
|
||||||
|
// for (i, c) in row.raw.chars().enumerate() {
|
||||||
|
// if !c.is_numeric() {
|
||||||
|
// print!("{}", c);
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// if let Some(part) = analyzed_matrix.iter().find(|l| l.raw == row.raw).unwrap().parts.iter().find(|p| p.position == i as u32) {
|
||||||
|
// if part.is_valid() {
|
||||||
|
// print!("T");
|
||||||
|
// } else {
|
||||||
|
// print!("F");
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// print!("{}", c);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut sum: u32 = 0;
|
||||||
|
analyzed_parts.iter().for_each(|part| {
|
||||||
|
//println!("Part: {} \t| Valid: {} - H: {} | V: {}", part.num, part.is_valid(), part.adjacent_horizontal, part.adjacent_vertical);
|
||||||
|
|
||||||
|
if part.is_valid() {
|
||||||
|
sum += part.num;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
println!("Sum: {}", sum);
|
||||||
|
println!("Gear ratios: {:?}", gear_ratios);
|
||||||
|
println!("Gear ratio sum: {}", gear_ratios.iter().sum::<u32>());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_input() -> Vec<Line> {
|
||||||
|
let re = Regex::new(r"(\d+|[^.\n])").unwrap();
|
||||||
|
|
||||||
|
let lines = std::fs::read_to_string("src/bin/part03.txt")
|
||||||
|
.expect("Could not read file")
|
||||||
|
.lines()
|
||||||
|
.map(|line| {
|
||||||
|
let mut parts = Vec::new();
|
||||||
|
let mut last_part_offset: u32 = 0;
|
||||||
|
let mut symbols = Vec::new();
|
||||||
|
let mut last_symbol_offset: u32 = 0;
|
||||||
|
|
||||||
|
for caps in re.captures_iter(line) {
|
||||||
|
if caps[1].chars().all(|c| c.is_numeric()) {
|
||||||
|
let pos = line.chars().skip(last_part_offset as usize).collect::<String>().find(&caps[1]).unwrap() as u32 + last_part_offset;
|
||||||
|
let number = caps[1].parse::<u32>().unwrap();
|
||||||
|
parts.push(PartNumber {
|
||||||
|
num: number,
|
||||||
|
position: pos,
|
||||||
|
adjacent_horizontal: false,
|
||||||
|
adjacent_vertical: false
|
||||||
|
});
|
||||||
|
last_part_offset = pos + number.to_string().len() as u32;
|
||||||
|
} else {
|
||||||
|
let pos = line.chars().skip(last_symbol_offset as usize).collect::<String>().find(&caps[1]).unwrap() as u32 + last_symbol_offset;
|
||||||
|
symbols.push(Symbol {
|
||||||
|
position: pos,
|
||||||
|
text: caps[1].to_string()
|
||||||
|
});
|
||||||
|
last_symbol_offset = pos + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Line {
|
||||||
|
parts,
|
||||||
|
symbols,
|
||||||
|
raw: line.to_string()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
lines
|
||||||
|
}
|
||||||
140
src/bin/part03.txt
Normal file
140
src/bin/part03.txt
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
.............65..................998.........453...................................845..773.........................307....527...........541
|
||||||
|
............*..........125.......*...331......*.....................30.76......./...*....*..861.......*.........298*......*.........700.....
|
||||||
|
................942.......*...874...*......407...558............752......*196.274.240.345...*.....-..105...................164...........466
|
||||||
|
....+............&.....593...........516............-....=.....*....74.....................377..157................128...........175*.......
|
||||||
|
....314.750......................497...........258.....549...70.....*....745.....289*418.................351........../..............839....
|
||||||
|
..........*.......786......283......*366..........*...............899.....*......................652.......@...219..........................
|
||||||
|
........468..=249..........*..........................866.797*960..........234.......252-.686.......=............$...................&......
|
||||||
|
..386.............582....681...52....$369.+.......969..+........................276........*.................873.....824.......%627..51..25.
|
||||||
|
.....-......835..@....*....................101.......*.......444...........587...*..33....847...............&.......=.......................
|
||||||
|
...........*.......513.45.125......................883.......*...............=.988.$.............962.*595.....................*....674.534..
|
||||||
|
........180.........................891*129..957...........+.584......................291*59..71*..................../.....707.646....*.....
|
||||||
|
...................=530.....................*.......610..790........314...$....991..................231*926....29..870.264..................
|
||||||
|
......132-..............#..............$....93.........*...............*...537...$.139..........70...............&.....................131..
|
||||||
|
...36.......#.514%.......99..684.......21.........852.886../...191.....892...........*....456..-.....172...../..............................
|
||||||
|
.....*...508................&......615...........$.........964....*...................627...............*242.945..........457.....512..880..
|
||||||
|
.....211.............430...........*.......%..........702.........243..747.......506................24.......................*873....*......
|
||||||
|
.........................988..570........-..72....726*.................-........=.....340............*.555....526......................&....
|
||||||
|
........&..........#928....&../.......785..............971..585......................+............860....%...#..........628.....=....952....
|
||||||
|
..165..541......................822........930.........*...%............*737..................940..............#561......=...=..685.........
|
||||||
|
....+...........248..-...40...................*521....897............698.................................558...............52........-......
|
||||||
|
..................*...19..%...........674.....................110.........................*296.............*...........78#.........495......
|
||||||
|
................753.....................*..............@.....#....199......353.604.....737.......483.366....242....720......................
|
||||||
|
...407....973#...............352.........397............144......*............*............799....%..................#....845.......539.....
|
||||||
|
......*................*........*..............643............443..726....=......*939..439*.....*....478$.....#.............-........-......
|
||||||
|
...165.........3....599.943..840..424..268.389...*..........=.........*83.827.318............135.55........924..535*...........%............
|
||||||
|
.......163........@...............*..........+..688.......529.........................858............137............681.347...187...........
|
||||||
|
...541....*.299.340.....@..+645.492...................................#....830*.................897.*.......782$...................352......
|
||||||
|
........740.%........549..............500...-..899......671=.807.....334.......313...26........+....366.701.............330........*........
|
||||||
|
....125.....................928../......@..243...................225......182........=..................*................&.......346........
|
||||||
|
......%....814.665.........*......573.....................69.......%.........*484.................+...64.........910.........273.....450....
|
||||||
|
...............*...........383.........433.................*...........#22...........62..#569....396........736.....*708.......&....*.......
|
||||||
|
.383.........774......................*.....#............&..265.............812......*...............305*....*...................657........
|
||||||
|
.....467.392.......936...806.......373...929...463....484.............337....%...415..465.@..............154..326...........................
|
||||||
|
....../..*.....+.......=....*.....................*........517*24.-.................*.....297.......................................*.......
|
||||||
|
..........599..820.....342.438...........482...200................49..........-312..847.............548...$.....581..909.........879.616....
|
||||||
|
............................................&................&475........................528...578....@..211......*....%....791.............
|
||||||
|
..............802..............250....................................*229........923......#.....*.................635......................
|
||||||
|
552......762..#...................$..%......940......651...........461........900*.............654...673....................*437..993.......
|
||||||
|
..........$.............52............602......%........*...105..$.................938...431.............................157......#...310...
|
||||||
|
...581../...............$.........309.......*...........846.../..718..........568@..*.......*...261...............22.........-852......*....
|
||||||
|
......*.969.349..354.....................156.666....@................-378..-................632....*..........363*........./......976.871...
|
||||||
|
.....60.....*.......*....10...@..684#..............225....248.............904..........638$......896....%.................906.926...*.......
|
||||||
|
.............602.....958.....103..........703..........................$.........456.........704.........149...785.2=...........*.87...95...
|
||||||
|
....228..589.................................*...770..588...........411..902..................................................645...........
|
||||||
|
.......*....*...135.......*...909.857.207-.602.....*.....*......=.........*..........358..............535......*................../235......
|
||||||
|
.....126..747............513..*.....$...........125.....389..956.....164...797........*.....807..34......%..754.734.....140..............969
|
||||||
|
.................919*213.....232............530..................583...................986....*...*.................186...=.%881..859.......
|
||||||
|
...937......881..........774......*345.......*......894#...644*.....$....588.................520..323..218...%...../..................#.....
|
||||||
|
.....-.401.*.......359.....*....19.........728.................670.................674.511*...........*......580........203%.........470....
|
||||||
|
........*..610......-.......836.....299.........832..........................690...........528.......21.....................................
|
||||||
|
......991......#.......365................447....#...857...227.605.........%.-...599.........................*602...529...........10........
|
||||||
|
..........+471..443.....+................*..........*......=......*252..417.....*.....653.............412.727.......*.....634.304.*.....42..
|
||||||
|
.....494......................&...........552.....852...................................*....550*520............80.174.............437......
|
||||||
|
......-.....+...536.........$..969............519.......448........251..............$...794.....................*.........701...............
|
||||||
|
..373.....930.....*......298.............76+.....*...@.....*......*................856......@899..............96..40......*.......574.......
|
||||||
|
.....*........518..575...........957.112.......479.579....288..306...+.......$817........................785.....*...9.......127..#...=907..
|
||||||
|
...698.......*..........329.....$....*......92........................203..........168.....................*..346....*..........*...........
|
||||||
|
.......470........68/..............263.....*.........337..................433............................666........92......20..784..978*194
|
||||||
|
.........%................465-.............297..............193.259.............................................17.........*................
|
||||||
|
.............*.................................................*.......*............580.......763.......@.........*747....519....628..647...
|
||||||
|
......900.....261..........722.553.....284*513......*429..............155....&....$....%..914...*......468.......................$......*...
|
||||||
|
........#........................................932......413....414......829.....528.......+...527................382...835...........744..
|
||||||
|
....918......103*37..207...676.297........422..............*........*993................140...................945.#.......*...686...........
|
||||||
|
.......................$.../...*......423....*..459=...&....602..........................................................978..*.............
|
||||||
|
.........&........414.........41.........*..673......543..........848*276.......388%..792...*....700*152......596/....*........791...%...485
|
||||||
|
.....615..55.........+......+........%.859...............@363..........................*..858.........................556............748....
|
||||||
|
......../....................775..467..........700..............*492.....$..862.......266..........319............88..........724........291
|
||||||
|
........................942.............530....*.....#.259...872........157./...287...........#687..*..../...........438$........*..233.....
|
||||||
|
............../...641........534.546...+......802.847.....*........................*...................13.......................677..*......
|
||||||
|
....604.......158........818....*.........................947................24....516.......&...332...........573...................697....
|
||||||
|
...%....2................*............/..........................162....27.....$.......#860.284.....*540..309...+...........................
|
||||||
|
........................678........337........105.469.......49.....................641.....................*......644$..............128.....
|
||||||
|
.....................%..................386.............203*.....497.404.............................795..................670.........*.....
|
||||||
|
....+..............369......814.........#.......359...........-.....*.......+.......41...........353....*263.........-.........700....102...
|
||||||
|
...862......430........=.....*............*682..............195.456..........379......+...........*..........790...987......................
|
||||||
|
....................565................689......................*...296.........................599..689.829...*..............$....910......
|
||||||
|
513......721.................................645*343.105........1....*..............=349.............&.....%...785..........832../...*......
|
||||||
|
........=............50*15..............272............*....242...306...........................................................159.59......
|
||||||
|
..............190...............88#.%.........229......310....#.......330...........149*.........89.......333.....771.....701..........522..
|
||||||
|
....354.........+....................561........*..........73.....336*....$40..906......16.........-.......+.......*........*...563....*....
|
||||||
|
.......*.............948..844......#.......556...51.........*......................=...........744.....361...$.....15.644=..9...........686.
|
||||||
|
........535.796.....*......#......907.........%......286...918....714..............688.232.................51......................284......
|
||||||
|
............*........755................@255.........*...........*......=.292............./.........453.........913................$....810.
|
||||||
|
............354...................................361..406*802...112..461............162.....$......=......991/./........&..................
|
||||||
|
.......+............#892.......654/....705..........................................*........385.........................506....*506........
|
||||||
|
.444/.482.................................*.....................619.....19*239.....187.993......................*............718........884.
|
||||||
|
..............906.182..473............/..58...407.591.583...=.....%......................*.......$......1....310.196....................*...
|
||||||
|
......820@......%....@.%.........343..61........*.......-.663.............490.....209..921....288.......*..............484...956.........324
|
||||||
|
...+.........................189*.............963...878.......782..955....%..........*................72...........406*......*....-.........
|
||||||
|
...188......861....239.818..........................*.................*......7....892.............705....197.20*..........204......429......
|
||||||
|
........*....*......./....#............*236.425*147..816..............739.....*........%..../.....*.............473...455...................
|
||||||
|
.....718.939..679........................................182.281@...........597.......360..324.161.......8*671...............971............
|
||||||
|
....................+318.698*778..691......648*806..387$../..............*......174/................+133............25......................
|
||||||
|
.............620*..................*...986...............................587.....................................15......264%..128.....998..
|
||||||
|
.......%436......267..557%..#827.......................746%.48.411*309.............+.....547......-.............*.................*....*....
|
||||||
|
..690..........#.................724....*.....772...........+..........787........462...+........89.#777.....794...-.........120.662....429.
|
||||||
|
....&....$575.874........450.379...%.120.944.....*....10......378*888.%..........................................542........................
|
||||||
|
..................388.....+.....*..............108........243..............468...........363......132....-....&...............*....391......
|
||||||
|
.....*.............%....$.....554.494....784.........310.&............458...%........753*..............217...174..23*108...853.233...*......
|
||||||
|
..636.425....343.........455........$........87........*.................-........%..............823.....................-...........898....
|
||||||
|
................*728.747.......770.......913.*....855.159.....&618...*.............779...94-..........375/.318*410...324.209................
|
||||||
|
........................*399......*.......=...905.*.......24........192.......760................785...................#...............468..
|
||||||
|
.......674.414....108/.......498..443.............660.......*................*....................*....980..................................
|
||||||
|
.462.........*..............................654..............669...........427......$..............14..*...921.......897.............862....
|
||||||
|
...@.......292..370....751....639....................403..............74.......537.504.130.............779..&....89..*....615.423.%....*....
|
||||||
|
...............+..........*........958......23...160./..................*228.....*........*....66.....................378....*....735.......
|
||||||
|
......#...............&68.584..125.$....898..+....*.........130.................927.....75......*....613....414.............................
|
||||||
|
....909..968...................$.....=...#......@.935..............966.......................374.......*.....*...&......73.......*611.=888..
|
||||||
|
............*231...................93.........157..............252..%..900.869...269................550...352..123......*...7.888...........
|
||||||
|
.......833%..............277%.+860............................*...........*......*............973....................697...#........765..153
|
||||||
|
..............920@..569.........................499................44..........36....................406.98...+..295..........94*....@......
|
||||||
|
.....28...............*.413......-333......984.*............984...........878.............*.................958.....*43...829....746........
|
||||||
|
......*............320...@...799.......696..$..211...%.......+.........%...*......232$.915.....209...........................*........510...
|
||||||
|
.......429.....................*........$...........624.736..........342....960..................*..................186....402..............
|
||||||
|
....16.........838*............477....&...................%...............................977..996..........255.212.........................
|
||||||
|
245........88......209.................283.920*456...............410.............$353.....%....................*....................846.....
|
||||||
|
.......699..*....................................................*...580......................659*......=..................184....#..#......
|
||||||
|
..890...*...485..........=......................................16...*......589...................754.802........485..%...-......784...+....
|
||||||
|
.......28.........303....405.@442.......768......476..273*961......843.....*.....161....813.....................*....470..............111...
|
||||||
|
.............#...*...........................303.*..........................255.+........&.......326*309.+814.469..............5............
|
||||||
|
....208.....910.514..148..261..334.......$...*...674..597..........................*439......36.....................=876...468*.............
|
||||||
|
....*....*..........*........*...@.....205...525.....*.....863..190.......115................./..@..+17......731................626.....&...
|
||||||
|
..984....994.......396.......587....................558....*..............................112...364.........................599*.......824..
|
||||||
|
......./...............................................................935*56........146................#......%............................
|
||||||
|
.......563..................896....216*192.......................588...........423......*......657...894..678...57............&.....813*....
|
||||||
|
............#......186.-....*...................796.916........./..........810...*...532..........@.......*........394.......885........871.
|
||||||
|
..../.......484...*....101.208........%..42........*......623.....*592.....*.....572.......545.........677.....*...*........................
|
||||||
|
.479....25........535...............627..*...........652.....+.808.......926.522............*...............671.33.499.............514......
|
||||||
|
..........*............951*472............215.......*.....................................451.....152...........................58...%...903
|
||||||
|
..........178.....=....................64......22.244...898.................514.......460........-......947..........823....368...%.........
|
||||||
|
...................120.....=.....289...*........*.......................723..../...........................*....368.................349..304
|
||||||
|
..........................402...........914..707.............630/...*.............................419.....654......*..............*.....*...
|
||||||
|
......981.131....809*755...........318*.............248...........#.195........338..........23....*...............395..223.....626.498.681..
|
||||||
|
.....*.....................+.271.......457.........*......384...633.......#.....*...638..46........144........@...........*.................
|
||||||
|
...915....................14../..............595..806......*...............523.603..&....*....................165.824.....789.....347$......
|
||||||
|
.................*47.............761.265.150................967........565............=...296......-..............*...........671......379..
|
||||||
|
..............967......./.&197......*.........=.....................&................660..........292.............993...........=..581..#...
|
||||||
|
......................279........+.........755........@..............712..........*...................827....../...................*........
|
||||||
|
...........$.....*................115..................400................=......1.292..@602..=.................321..............728........
|
||||||
|
..579..410..3..44.291..........................538..................148....873.................461....................................722...
|
||||||
84
src/bin/part04.rs
Normal file
84
src/bin/part04.rs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
use std::time;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
struct Card {
|
||||||
|
id: u8,
|
||||||
|
winning_count: u8
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Card {
|
||||||
|
fn get_points(&self) -> u32 {
|
||||||
|
let correct_count = self.winning_count as u32;
|
||||||
|
if correct_count == 0 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
u32::pow(2, correct_count - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRINT_DEBUG: bool = false;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let s1 = time::Instant::now();
|
||||||
|
let cards = load_input();
|
||||||
|
let e1 = s1.elapsed();
|
||||||
|
println!("Loaded {} cards in {:?}", cards.len(), e1);
|
||||||
|
|
||||||
|
// part one
|
||||||
|
let s2 = time::Instant::now();
|
||||||
|
let total_points = cards.iter().map(|c| c.get_points()).sum::<u32>();
|
||||||
|
let e2 = s2.elapsed();
|
||||||
|
println!("Calculated total points in {:?}", e2);
|
||||||
|
|
||||||
|
// part two
|
||||||
|
let s3: time::Instant = time::Instant::now();
|
||||||
|
let total = calc_total_cards(&cards);
|
||||||
|
let e3 = s3.elapsed();
|
||||||
|
println!("Calculated total cards in {:?}", e3);
|
||||||
|
|
||||||
|
println!("Total time: {:?}", e1 + e2);
|
||||||
|
|
||||||
|
println!("Total points: {}", total_points);
|
||||||
|
println!("Total copies: {}", total);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_input() -> Vec<Card> {
|
||||||
|
let cards = std::fs::read_to_string("src/bin/part04.txt")
|
||||||
|
.expect("Could not read file")
|
||||||
|
.lines()
|
||||||
|
.map(|line| {
|
||||||
|
let parts = line.split(": ").collect::<Vec<_>>();
|
||||||
|
let card_id = parts[0].split_whitespace().last().unwrap().parse::<u8>().unwrap();
|
||||||
|
let numbers = parts[1].split(" | ").collect::<Vec<_>>();
|
||||||
|
let scoring_numbers = numbers[0].split_whitespace().map(|n| n.parse::<u8>().unwrap()).collect::<Vec<_>>();
|
||||||
|
let actual_numbers = numbers[1].split_whitespace().map(|n| n.parse::<u8>().unwrap()).collect::<Vec<_>>();
|
||||||
|
let winning_numbers: Vec<u8> = actual_numbers.iter().filter(|n| scoring_numbers.contains(n)).map(|n| *n).collect();
|
||||||
|
|
||||||
|
let card = Card {
|
||||||
|
id: card_id,
|
||||||
|
winning_count: winning_numbers.len() as u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
if PRINT_DEBUG {
|
||||||
|
println!("Card: {} - Winning: {:?} - Score: {}", card.id, card.winning_count, card.get_points());
|
||||||
|
}
|
||||||
|
|
||||||
|
card
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
cards
|
||||||
|
}
|
||||||
|
|
||||||
|
fn calc_total_cards(cards: &Vec<Card>) -> u32 {
|
||||||
|
let mut played = vec![0; cards.len()];
|
||||||
|
|
||||||
|
for i in 0..cards.len() {
|
||||||
|
played[i] += 1;
|
||||||
|
for w in 0..cards[i].winning_count as usize {
|
||||||
|
played[i+w+1] += played[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
played.iter().sum()
|
||||||
|
}
|
||||||
6
src/bin/part04.sample
Normal file
6
src/bin/part04.sample
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||||
|
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||||
|
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||||
|
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||||
|
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||||
|
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
|
||||||
188
src/bin/part04.txt
Normal file
188
src/bin/part04.txt
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
Card 1: 95 57 30 62 11 5 9 3 72 87 | 94 72 74 98 23 57 62 14 30 3 73 49 80 96 20 60 17 35 11 63 87 9 6 5 95
|
||||||
|
Card 2: 65 16 99 4 48 52 84 7 26 12 | 86 7 71 12 52 4 84 15 48 20 16 3 10 87 56 99 26 66 88 65 98 32 14 51 59
|
||||||
|
Card 3: 19 70 1 34 10 79 23 58 64 68 | 95 14 64 53 19 63 83 46 77 75 3 12 70 65 22 13 66 34 23 89 94 50 69 79 68
|
||||||
|
Card 4: 27 57 62 6 53 68 97 35 23 8 | 23 2 81 62 19 8 65 27 93 53 57 67 6 91 68 97 16 30 12 96 15 35 25 55 43
|
||||||
|
Card 5: 49 95 30 21 42 63 92 97 89 93 | 35 34 46 89 93 29 42 21 63 49 77 30 95 27 28 62 72 32 97 54 75 56 4 58 92
|
||||||
|
Card 6: 7 39 29 54 34 40 63 64 32 23 | 88 4 54 73 32 18 36 31 19 35 61 94 28 40 23 41 96 59 14 48 77 29 39 21 33
|
||||||
|
Card 7: 20 58 79 66 51 65 72 27 62 67 | 37 7 90 62 3 17 88 58 86 28 55 42 15 20 79 94 38 92 76 41 30 93 25 24 14
|
||||||
|
Card 8: 3 83 96 15 95 72 63 87 74 78 | 16 74 6 49 15 87 46 3 64 90 82 85 2 78 32 9 97 96 70 95 63 72 54 83 38
|
||||||
|
Card 9: 40 74 17 75 12 97 71 15 30 83 | 13 21 15 12 8 81 50 7 44 67 6 40 30 76 22 75 42 79 5 97 83 60 71 47 74
|
||||||
|
Card 10: 47 96 36 45 84 14 65 7 69 38 | 36 38 85 14 87 95 7 24 69 29 68 65 26 94 84 78 83 45 98 9 2 20 93 96 47
|
||||||
|
Card 11: 22 5 16 86 91 96 27 39 8 30 | 14 98 84 51 11 5 23 36 40 81 82 78 13 2 43 39 42 68 34 71 10 38 61 70 46
|
||||||
|
Card 12: 57 95 65 48 50 46 69 61 58 70 | 64 69 52 84 93 65 61 37 25 22 31 6 46 83 50 48 75 58 59 98 95 70 19 51 57
|
||||||
|
Card 13: 67 63 56 28 11 81 43 60 93 57 | 61 67 82 60 7 11 98 78 50 33 84 64 74 63 28 15 56 66 39 57 69 54 65 8 12
|
||||||
|
Card 14: 30 97 48 84 86 1 59 83 8 44 | 70 94 38 62 71 79 47 99 68 93 67 15 33 57 60 72 50 31 88 20 82 40 18 63 29
|
||||||
|
Card 15: 7 2 46 28 61 63 17 95 32 47 | 56 97 17 93 36 78 16 25 18 33 61 90 10 55 82 26 2 69 43 22 96 37 64 74 95
|
||||||
|
Card 16: 45 90 36 48 81 64 68 58 4 66 | 31 36 34 41 46 56 2 74 50 57 93 86 22 60 43 24 12 17 73 79 15 63 82 97 32
|
||||||
|
Card 17: 1 82 47 86 6 33 52 51 98 91 | 88 98 26 33 82 93 16 45 65 68 47 96 39 83 14 86 61 71 75 90 3 54 59 77 9
|
||||||
|
Card 18: 43 73 13 32 98 11 15 12 97 99 | 83 15 60 62 95 36 98 16 51 79 20 24 73 46 5 67 12 32 11 84 89 23 93 59 74
|
||||||
|
Card 19: 54 93 71 65 66 56 26 97 33 24 | 67 24 89 17 99 18 5 54 26 14 57 10 3 33 91 94 16 80 97 49 12 46 19 75 38
|
||||||
|
Card 20: 65 10 75 93 72 62 29 69 59 66 | 58 55 56 87 66 88 7 34 36 62 4 35 67 90 33 52 99 17 32 68 80 79 40 48 31
|
||||||
|
Card 21: 93 75 39 12 21 77 99 46 4 24 | 39 19 98 59 43 14 28 9 89 81 1 5 63 87 48 95 41 36 29 27 44 15 50 17 18
|
||||||
|
Card 22: 78 39 74 11 41 24 9 33 68 45 | 41 66 29 79 15 90 62 60 95 69 57 55 81 33 20 89 76 65 56 77 61 18 88 75 19
|
||||||
|
Card 23: 64 16 33 77 80 89 90 50 57 4 | 46 94 45 42 82 61 67 3 76 74 96 79 7 70 73 97 11 34 35 72 55 51 36 12 13
|
||||||
|
Card 24: 40 13 83 79 42 70 26 33 7 12 | 95 17 5 74 68 28 46 21 96 43 73 47 18 86 54 88 82 61 85 51 11 9 56 20 75
|
||||||
|
Card 25: 97 54 33 84 85 49 4 26 25 67 | 22 41 72 84 25 16 85 8 83 62 15 33 97 17 38 67 69 51 45 77 28 87 24 54 4
|
||||||
|
Card 26: 54 22 60 99 15 96 80 3 5 64 | 96 65 54 38 60 87 8 15 80 10 3 32 22 56 43 5 44 14 78 18 97 64 25 63 99
|
||||||
|
Card 27: 88 93 30 77 33 46 38 66 7 20 | 96 75 30 77 83 76 54 46 15 66 38 88 55 40 22 21 34 42 29 20 71 16 28 61 18
|
||||||
|
Card 28: 48 85 39 25 47 80 98 33 68 66 | 50 82 40 60 84 46 29 51 25 47 11 22 58 64 36 2 63 92 80 15 72 27 37 98 10
|
||||||
|
Card 29: 85 92 67 13 70 60 9 35 18 98 | 44 16 66 33 81 56 58 73 64 85 39 40 49 63 23 17 19 1 28 62 2 65 10 68 11
|
||||||
|
Card 30: 15 64 30 28 6 97 69 38 17 79 | 92 50 33 24 85 6 38 44 91 28 35 58 90 97 39 79 64 80 84 22 15 66 2 45 17
|
||||||
|
Card 31: 7 74 79 40 62 55 16 48 59 97 | 31 70 34 85 23 17 4 92 12 66 1 50 43 87 27 64 11 28 26 47 94 2 36 15 39
|
||||||
|
Card 32: 97 95 38 61 7 22 36 94 47 4 | 21 37 44 88 77 33 11 12 91 27 80 67 25 83 17 45 89 61 98 40 59 76 96 71 1
|
||||||
|
Card 33: 15 35 9 39 25 62 57 19 81 47 | 64 57 71 56 35 25 33 1 76 97 48 84 44 79 82 39 19 74 78 59 14 49 81 29 11
|
||||||
|
Card 34: 97 3 81 82 28 40 35 67 38 85 | 36 76 21 89 38 34 43 10 85 9 99 83 68 94 47 19 17 91 41 26 20 30 63 25 69
|
||||||
|
Card 35: 43 49 58 92 57 71 56 28 33 3 | 32 1 70 43 29 93 54 63 58 27 14 28 51 31 81 57 25 50 87 90 82 73 97 7 12
|
||||||
|
Card 36: 18 85 61 97 29 25 66 28 11 62 | 44 26 46 65 83 59 30 66 68 47 90 93 15 84 9 7 72 1 95 87 3 20 23 81 86
|
||||||
|
Card 37: 97 22 74 4 43 78 76 8 26 1 | 4 93 24 5 80 37 48 12 59 32 50 71 66 69 52 23 34 25 57 89 51 99 41 56 63
|
||||||
|
Card 38: 20 57 93 41 87 71 76 29 33 66 | 63 56 49 11 64 2 62 68 82 8 67 81 41 4 78 17 85 97 69 35 19 47 30 95 65
|
||||||
|
Card 39: 6 81 87 68 29 23 76 9 44 33 | 74 71 60 82 98 72 85 57 7 96 84 30 19 3 35 12 22 50 15 26 94 65 62 61 83
|
||||||
|
Card 40: 96 61 74 3 10 54 58 86 97 87 | 16 37 57 5 72 93 74 45 88 67 97 54 69 2 71 58 46 96 87 44 10 20 86 28 3
|
||||||
|
Card 41: 28 83 7 40 32 56 82 70 14 22 | 82 81 37 73 76 65 35 56 17 40 83 29 39 6 80 61 25 28 31 32 1 38 42 85 8
|
||||||
|
Card 42: 16 47 55 93 99 1 7 72 12 40 | 78 2 26 88 9 98 40 47 61 77 23 1 66 27 55 5 72 67 50 12 85 83 90 71 25
|
||||||
|
Card 43: 17 94 80 60 24 12 20 66 99 41 | 53 69 76 97 15 54 29 73 98 33 30 45 24 19 70 66 16 78 6 90 61 96 32 89 46
|
||||||
|
Card 44: 16 20 87 88 90 27 69 81 79 70 | 52 70 85 7 13 87 34 26 60 82 15 88 69 79 58 62 75 44 42 49 48 11 97 16 27
|
||||||
|
Card 45: 72 9 25 20 48 79 15 2 49 67 | 4 3 60 85 48 73 15 98 25 84 95 80 22 7 58 72 44 67 79 20 40 70 1 29 13
|
||||||
|
Card 46: 86 95 61 42 30 43 1 72 19 53 | 65 88 13 2 3 30 51 7 5 19 74 25 56 50 10 32 43 85 78 61 99 12 75 42 80
|
||||||
|
Card 47: 80 62 17 58 21 95 18 65 19 54 | 23 1 28 41 80 46 18 17 35 54 19 40 43 62 96 77 45 90 13 21 12 66 52 53 65
|
||||||
|
Card 48: 52 43 23 72 73 82 9 19 60 83 | 35 29 60 57 22 46 78 39 86 27 92 90 19 71 28 44 41 40 52 79 6 50 15 82 21
|
||||||
|
Card 49: 10 19 28 81 32 46 42 8 54 16 | 42 93 82 62 95 67 59 8 87 36 28 35 38 31 75 70 96 10 56 1 54 44 4 88 24
|
||||||
|
Card 50: 12 66 62 83 81 13 2 38 85 57 | 73 95 59 70 54 93 71 35 25 75 82 46 14 21 76 32 8 81 68 42 79 44 34 41 55
|
||||||
|
Card 51: 62 51 82 74 97 93 49 94 76 58 | 4 46 69 1 33 38 68 89 59 91 57 67 3 92 19 53 77 50 94 48 62 26 98 9 81
|
||||||
|
Card 52: 52 51 23 12 82 32 96 89 47 55 | 12 4 60 90 17 35 52 64 94 43 27 14 9 25 6 66 41 68 38 56 37 19 55 85 69
|
||||||
|
Card 53: 23 59 46 4 62 48 71 20 50 1 | 41 77 25 16 35 34 44 81 65 17 78 15 42 12 72 55 57 3 58 88 40 95 66 13 74
|
||||||
|
Card 54: 43 96 23 40 48 38 10 21 8 20 | 98 88 67 99 97 56 54 1 29 57 37 69 63 32 89 35 41 85 11 49 74 36 28 65 91
|
||||||
|
Card 55: 9 66 49 29 54 15 36 93 50 13 | 84 79 55 53 41 8 78 89 18 40 56 61 45 7 88 63 37 4 67 85 90 28 34 51 10
|
||||||
|
Card 56: 51 99 43 34 16 30 8 36 71 88 | 99 36 8 16 71 28 43 29 61 94 92 48 77 58 51 34 88 67 47 30 54 14 66 70 68
|
||||||
|
Card 57: 46 90 29 80 82 93 4 66 57 91 | 90 57 74 20 54 42 93 60 88 80 5 78 82 51 7 29 4 55 33 89 32 12 27 63 44
|
||||||
|
Card 58: 46 16 53 11 58 63 65 93 99 36 | 22 29 59 91 79 40 95 68 67 99 88 87 13 73 54 8 49 20 16 94 9 43 47 4 98
|
||||||
|
Card 59: 57 93 76 90 32 22 30 9 98 88 | 48 93 22 33 14 92 80 3 2 17 82 54 42 63 41 74 56 87 45 52 71 35 70 32 60
|
||||||
|
Card 60: 26 74 89 84 81 10 79 99 75 11 | 86 81 64 26 54 35 66 99 84 53 89 79 13 75 24 98 60 19 94 74 5 11 49 10 23
|
||||||
|
Card 61: 51 99 9 36 82 83 40 25 97 39 | 2 82 72 65 7 17 63 28 16 84 34 56 37 81 25 13 26 50 73 51 40 94 49 8 39
|
||||||
|
Card 62: 98 72 92 16 2 68 65 61 20 78 | 89 60 42 83 20 7 64 36 77 95 63 37 39 4 74 75 25 67 9 58 49 2 87 10 68
|
||||||
|
Card 63: 17 86 72 89 44 30 21 64 36 84 | 72 30 91 27 31 50 64 7 25 9 89 84 17 86 92 71 13 63 36 2 41 28 33 94 82
|
||||||
|
Card 64: 9 71 80 49 16 90 92 17 39 45 | 53 9 30 93 7 12 98 87 45 16 67 71 90 18 17 31 42 36 39 48 47 85 19 97 95
|
||||||
|
Card 65: 76 39 34 30 80 38 16 45 46 58 | 16 79 45 51 40 67 31 49 30 22 85 63 57 34 76 80 3 48 46 36 38 58 19 55 6
|
||||||
|
Card 66: 97 57 52 42 67 92 28 6 7 73 | 55 79 71 61 94 86 83 35 72 78 4 58 10 51 73 89 68 92 42 24 69 57 91 7 43
|
||||||
|
Card 67: 99 35 28 30 61 98 51 73 4 85 | 90 34 58 69 21 59 36 97 96 98 44 47 12 15 61 29 28 42 99 51 52 71 19 40 73
|
||||||
|
Card 68: 72 30 78 60 61 91 14 73 76 47 | 46 41 40 6 94 56 16 45 60 20 33 24 43 1 88 67 62 68 2 84 29 12 4 96 74
|
||||||
|
Card 69: 14 20 41 89 85 13 98 6 33 4 | 36 99 26 58 49 55 16 68 15 52 30 35 28 21 82 57 65 56 7 37 3 20 14 47 22
|
||||||
|
Card 70: 93 18 99 57 25 81 95 4 58 37 | 24 66 67 61 34 55 85 37 78 30 75 79 3 32 83 33 10 52 69 98 20 45 2 68 44
|
||||||
|
Card 71: 47 27 78 40 34 56 59 62 26 93 | 50 18 84 99 64 10 97 22 85 20 15 19 72 31 58 89 37 6 26 44 68 60 43 21 17
|
||||||
|
Card 72: 28 18 7 3 11 94 85 44 90 40 | 59 2 49 16 27 42 72 33 50 5 92 37 88 55 95 11 62 7 52 23 41 74 98 35 30
|
||||||
|
Card 73: 1 46 31 33 20 19 97 89 15 45 | 50 77 71 24 88 87 74 95 56 44 42 70 4 75 96 25 21 11 59 47 29 35 83 2 85
|
||||||
|
Card 74: 88 55 81 82 51 18 48 12 72 19 | 41 78 28 96 83 5 33 60 3 73 53 85 22 4 50 61 98 23 32 68 34 80 49 75 36
|
||||||
|
Card 75: 17 93 50 45 57 97 39 3 87 32 | 79 87 59 15 1 71 54 37 80 85 14 93 45 3 24 50 94 74 75 64 55 97 17 76 21
|
||||||
|
Card 76: 37 19 35 66 32 28 43 68 13 86 | 68 45 91 37 33 69 35 24 1 14 58 25 52 3 50 70 62 64 94 32 49 13 28 43 21
|
||||||
|
Card 77: 5 6 46 30 74 35 48 94 26 88 | 82 55 59 35 74 92 36 26 48 5 7 98 27 42 60 94 11 71 6 33 23 30 56 25 46
|
||||||
|
Card 78: 27 81 2 26 70 83 28 75 15 82 | 47 25 73 15 36 86 93 90 46 37 1 28 75 89 49 83 2 79 81 27 9 44 82 70 61
|
||||||
|
Card 79: 35 38 41 81 18 89 9 34 55 16 | 21 31 76 69 50 45 88 63 89 70 15 96 99 8 67 42 20 59 74 19 48 37 98 10 39
|
||||||
|
Card 80: 97 65 69 37 10 86 57 41 15 31 | 17 58 2 50 45 27 33 73 96 12 29 86 60 74 89 81 51 95 37 41 75 98 38 93 20
|
||||||
|
Card 81: 12 6 42 18 14 74 61 85 47 28 | 13 49 34 78 81 75 57 11 95 3 69 27 2 42 44 76 54 4 68 48 24 53 52 20 15
|
||||||
|
Card 82: 40 27 39 47 34 78 31 79 91 12 | 63 6 76 5 50 8 86 96 99 57 82 87 7 37 95 56 28 26 77 67 45 17 51 66 30
|
||||||
|
Card 83: 38 96 19 65 28 70 54 95 62 15 | 29 26 46 50 32 18 89 93 22 24 1 52 2 39 59 86 69 56 72 58 25 70 54 7 10
|
||||||
|
Card 84: 76 89 49 56 46 1 83 64 73 40 | 19 60 49 99 18 28 54 73 32 38 97 87 2 79 8 61 12 93 35 20 52 51 58 3 21
|
||||||
|
Card 85: 77 86 68 78 37 82 93 17 15 36 | 9 19 79 80 39 8 15 54 68 27 98 50 46 41 88 12 34 47 76 93 81 7 35 85 73
|
||||||
|
Card 86: 68 22 45 20 26 79 88 44 46 90 | 84 19 67 86 49 18 21 65 23 6 57 90 75 28 51 83 4 56 26 98 38 5 3 80 63
|
||||||
|
Card 87: 43 34 86 6 75 41 38 17 22 61 | 54 95 20 36 72 28 59 90 40 50 63 81 89 30 92 32 26 78 53 42 46 15 73 51 7
|
||||||
|
Card 88: 15 32 22 2 63 17 62 94 99 83 | 44 25 22 16 58 54 67 4 92 8 75 27 41 99 53 97 76 5 51 32 78 74 73 81 45
|
||||||
|
Card 89: 67 75 27 99 94 7 57 15 40 65 | 61 42 96 13 53 56 3 63 70 41 69 28 86 11 54 16 34 22 31 76 14 5 43 79 77
|
||||||
|
Card 90: 10 49 37 75 89 18 62 16 65 13 | 8 67 79 40 27 23 15 56 69 71 5 85 87 88 14 74 22 19 64 98 93 35 18 82 31
|
||||||
|
Card 91: 73 28 59 31 18 92 69 84 38 52 | 86 70 65 90 53 95 45 33 16 94 23 71 25 34 26 98 13 87 55 8 1 49 6 93 63
|
||||||
|
Card 92: 18 60 22 23 16 6 88 4 32 44 | 37 88 46 75 97 6 22 9 5 18 92 32 16 4 49 82 13 60 44 26 28 86 8 12 23
|
||||||
|
Card 93: 14 39 72 74 69 9 4 13 57 7 | 22 6 96 21 23 80 50 83 55 81 30 1 79 92 34 32 95 91 11 76 85 12 73 99 89
|
||||||
|
Card 94: 38 18 52 85 43 3 89 63 78 77 | 78 35 89 77 96 27 38 46 3 58 84 37 85 4 13 52 80 7 21 50 63 42 86 28 43
|
||||||
|
Card 95: 72 18 32 20 23 9 43 97 71 30 | 21 29 14 50 5 48 35 15 58 75 24 73 81 88 82 13 98 86 26 33 70 64 96 11 90
|
||||||
|
Card 96: 36 27 25 77 60 63 49 1 39 31 | 29 78 5 67 77 24 71 59 22 73 6 69 99 88 37 25 21 47 42 61 2 40 26 45 23
|
||||||
|
Card 97: 40 74 36 19 92 51 78 44 96 20 | 18 98 69 94 73 40 82 45 38 44 78 58 57 32 99 14 34 63 35 92 3 83 4 84 75
|
||||||
|
Card 98: 57 55 61 60 77 56 50 33 48 47 | 61 77 33 86 75 47 65 50 48 84 10 55 14 28 19 53 3 46 83 31 1 51 89 56 57
|
||||||
|
Card 99: 93 47 74 10 37 90 76 1 40 54 | 62 72 8 28 79 84 23 75 2 45 96 32 16 71 56 14 13 63 78 30 12 55 65 46 91
|
||||||
|
Card 100: 15 33 70 46 11 23 24 69 47 5 | 6 68 69 86 55 3 50 43 45 75 36 97 91 20 15 77 21 23 17 71 70 82 42 35 9
|
||||||
|
Card 101: 40 41 98 7 73 21 47 68 59 1 | 11 79 77 37 48 96 92 30 18 24 31 88 49 99 14 23 82 35 42 16 22 84 8 75 32
|
||||||
|
Card 102: 92 51 37 63 18 54 28 58 40 4 | 10 94 9 42 64 11 91 23 50 30 90 81 74 77 65 24 49 60 19 70 79 83 76 72 99
|
||||||
|
Card 103: 66 62 18 43 33 50 51 30 22 63 | 20 68 54 91 55 14 1 31 71 38 80 86 81 87 89 53 42 83 65 64 30 73 6 61 2
|
||||||
|
Card 104: 2 86 13 94 18 9 74 35 49 91 | 82 21 12 51 25 10 89 6 73 95 2 16 83 36 49 64 3 87 41 78 27 98 67 56 7
|
||||||
|
Card 105: 51 42 19 18 31 2 29 80 99 65 | 27 55 14 37 52 11 25 5 30 73 41 32 76 28 50 69 88 66 22 74 40 21 13 35 90
|
||||||
|
Card 106: 6 19 88 46 69 13 49 20 63 31 | 47 32 72 78 79 53 55 75 98 16 76 52 93 17 27 77 74 45 44 60 10 91 3 87 30
|
||||||
|
Card 107: 11 42 78 2 9 91 46 51 68 88 | 30 7 18 76 94 87 50 57 73 14 54 36 80 59 71 61 20 64 5 44 55 93 27 74 24
|
||||||
|
Card 108: 4 79 42 25 54 92 93 88 90 81 | 86 92 79 4 52 58 3 65 95 14 42 59 15 81 12 39 90 25 98 49 38 63 27 84 88
|
||||||
|
Card 109: 65 16 49 63 6 37 48 75 77 19 | 16 73 6 25 14 28 27 75 49 11 61 77 76 19 85 95 63 37 33 88 48 22 65 72 31
|
||||||
|
Card 110: 83 63 27 82 72 40 70 35 12 86 | 14 96 39 40 72 56 8 83 63 43 42 86 91 58 48 70 3 73 22 35 82 33 29 31 12
|
||||||
|
Card 111: 36 31 68 37 83 23 9 39 12 26 | 80 92 71 20 48 37 53 32 75 31 83 58 9 26 77 52 42 68 70 7 72 36 23 87 50
|
||||||
|
Card 112: 94 61 81 68 89 42 52 92 74 39 | 94 89 15 76 86 92 65 57 84 2 21 81 49 68 42 39 90 31 13 27 69 61 3 74 52
|
||||||
|
Card 113: 68 9 32 67 96 43 14 15 28 48 | 2 81 58 90 45 89 53 34 39 7 46 55 20 69 25 66 17 54 44 19 93 23 92 26 10
|
||||||
|
Card 114: 25 77 57 50 59 16 46 80 2 14 | 58 14 78 81 8 75 21 45 50 67 55 1 51 92 20 25 86 32 72 54 65 44 38 91 70
|
||||||
|
Card 115: 11 10 76 79 84 82 16 14 43 6 | 84 59 20 63 79 33 23 47 40 17 48 80 76 25 83 16 82 89 6 11 10 97 44 43 14
|
||||||
|
Card 116: 21 1 37 82 29 36 57 76 68 63 | 86 38 20 14 36 8 7 31 68 21 56 1 63 26 28 57 96 54 29 82 37 76 61 71 40
|
||||||
|
Card 117: 4 7 73 26 78 49 22 11 74 35 | 76 26 57 22 66 36 73 35 16 77 87 49 32 54 92 43 7 15 20 38 8 82 29 78 11
|
||||||
|
Card 118: 58 12 45 87 44 90 48 72 77 66 | 34 57 66 52 90 98 4 99 21 80 8 3 18 45 79 23 50 10 43 62 54 60 39 29 33
|
||||||
|
Card 119: 58 97 56 38 78 75 84 99 7 32 | 92 33 78 72 7 84 64 18 38 43 27 32 21 99 85 40 58 93 97 13 3 75 56 25 46
|
||||||
|
Card 120: 40 31 79 63 24 20 11 56 92 32 | 63 32 92 22 1 30 79 20 58 53 64 24 56 36 81 6 49 48 17 26 73 83 47 3 8
|
||||||
|
Card 121: 51 39 2 99 40 21 4 8 14 46 | 11 29 41 74 55 73 16 95 21 30 85 81 2 76 59 99 9 51 58 8 44 43 61 27 25
|
||||||
|
Card 122: 29 76 10 60 87 27 35 65 37 59 | 59 53 46 17 1 48 36 88 95 85 13 41 67 31 90 39 99 24 51 11 84 42 96 91 92
|
||||||
|
Card 123: 99 34 55 8 23 83 28 26 21 54 | 99 8 2 10 26 76 11 52 95 73 38 74 23 92 59 57 71 56 1 13 93 87 43 4 70
|
||||||
|
Card 124: 75 96 37 43 92 85 68 78 18 4 | 71 43 78 96 92 62 76 19 39 21 52 29 36 93 81 33 53 2 10 69 82 87 14 85 68
|
||||||
|
Card 125: 11 32 49 86 21 95 94 64 77 23 | 53 25 9 94 75 21 10 35 95 81 39 41 90 18 45 43 78 73 63 56 27 74 46 17 85
|
||||||
|
Card 126: 8 64 16 62 90 93 98 27 57 4 | 39 89 62 42 60 33 90 3 44 32 8 13 24 85 5 93 68 55 73 22 4 52 28 58 12
|
||||||
|
Card 127: 22 52 46 90 56 44 84 62 48 8 | 46 86 7 72 80 58 38 76 53 12 83 22 15 60 84 14 33 17 52 49 88 93 36 4 71
|
||||||
|
Card 128: 49 31 89 7 43 41 27 58 74 72 | 92 24 40 95 80 84 2 19 70 29 83 69 42 17 39 67 97 98 32 56 23 59 21 5 68
|
||||||
|
Card 129: 92 50 77 38 85 25 5 72 34 84 | 39 38 55 26 58 83 75 70 80 94 42 9 12 69 29 88 50 3 62 96 13 48 93 44 22
|
||||||
|
Card 130: 45 23 32 47 89 28 9 95 94 14 | 53 78 75 3 50 29 65 60 1 98 15 13 36 71 52 21 66 19 73 67 91 37 76 26 56
|
||||||
|
Card 131: 70 27 15 12 83 23 96 57 90 77 | 14 34 88 74 59 68 94 44 99 39 40 78 47 17 43 42 80 9 73 93 41 25 71 22 75
|
||||||
|
Card 132: 16 32 43 64 77 1 14 78 97 98 | 78 97 64 75 52 98 13 81 16 57 3 9 14 83 32 28 56 58 1 43 87 12 77 24 31
|
||||||
|
Card 133: 95 53 4 45 36 20 77 60 8 49 | 2 62 83 20 53 95 57 86 8 45 38 63 49 82 85 26 36 60 89 81 92 51 54 4 99
|
||||||
|
Card 134: 95 23 88 8 52 67 46 15 36 55 | 74 44 67 8 94 88 82 46 6 34 64 23 36 14 19 91 15 72 98 56 55 95 65 13 52
|
||||||
|
Card 135: 27 40 81 65 23 49 89 67 4 32 | 75 32 8 40 16 27 38 54 48 67 22 42 85 57 4 97 76 81 82 28 55 65 2 72 23
|
||||||
|
Card 136: 7 35 1 24 95 80 25 4 75 37 | 73 28 64 72 56 66 55 29 52 2 80 98 11 41 16 78 75 89 35 12 85 69 24 42 39
|
||||||
|
Card 137: 19 38 84 95 77 68 50 70 16 17 | 71 69 30 27 86 7 35 96 33 74 20 93 36 47 6 55 29 32 78 72 58 46 21 99 9
|
||||||
|
Card 138: 97 58 41 82 43 64 26 81 2 36 | 55 79 30 88 96 99 34 82 25 6 71 44 54 77 91 11 90 80 76 40 92 69 64 29 15
|
||||||
|
Card 139: 41 27 9 87 98 24 72 58 2 88 | 93 72 58 89 34 23 24 48 49 98 78 50 87 64 2 14 85 21 62 75 88 60 41 53 16
|
||||||
|
Card 140: 79 92 45 91 75 2 1 57 66 40 | 42 82 45 28 75 91 1 11 63 17 20 54 27 92 48 40 12 57 69 66 2 21 19 88 79
|
||||||
|
Card 141: 33 4 49 55 78 9 61 83 58 50 | 50 9 94 83 98 78 14 66 67 61 71 4 72 39 49 40 29 30 36 16 47 3 58 19 33
|
||||||
|
Card 142: 80 32 49 19 43 42 50 86 97 87 | 42 15 71 58 18 85 80 19 97 86 32 62 95 44 56 50 83 28 51 34 33 43 36 87 49
|
||||||
|
Card 143: 76 89 44 30 69 84 47 85 42 23 | 54 17 16 52 86 48 81 92 1 7 78 64 66 59 21 55 36 58 46 37 6 61 89 72 82
|
||||||
|
Card 144: 22 9 57 50 38 82 66 70 92 37 | 71 18 63 27 87 34 23 13 39 92 77 60 74 46 50 48 57 54 66 22 59 83 44 9 70
|
||||||
|
Card 145: 56 90 36 66 70 16 73 62 4 37 | 18 34 96 7 47 65 99 56 58 75 85 31 36 3 90 70 5 66 83 62 73 16 55 37 4
|
||||||
|
Card 146: 68 59 27 32 62 43 25 22 42 3 | 67 68 59 70 98 16 8 25 24 22 44 53 63 11 6 65 54 74 81 32 91 50 13 62 99
|
||||||
|
Card 147: 21 95 4 18 23 68 83 36 29 3 | 94 42 90 33 50 39 41 66 58 8 96 83 15 85 56 93 14 99 67 37 5 61 24 4 3
|
||||||
|
Card 148: 13 22 23 39 61 17 50 28 25 19 | 86 92 67 42 85 22 17 19 7 5 39 55 47 20 64 25 50 66 31 30 61 41 18 89 74
|
||||||
|
Card 149: 24 79 8 18 15 97 95 13 33 89 | 72 18 13 85 89 49 47 1 11 84 40 50 44 71 15 53 43 26 8 86 23 22 83 21 97
|
||||||
|
Card 150: 98 78 63 19 91 86 1 9 55 35 | 41 33 95 85 83 20 66 23 86 94 8 87 43 37 71 58 21 14 96 3 29 6 39 53 32
|
||||||
|
Card 151: 47 78 1 40 26 97 61 73 24 21 | 59 60 94 4 52 42 92 19 23 57 82 88 70 45 43 96 7 72 26 58 71 6 16 53 8
|
||||||
|
Card 152: 3 79 50 95 26 91 66 60 71 53 | 12 96 93 92 49 5 9 76 30 8 23 58 63 73 94 10 19 46 39 55 33 87 18 78 86
|
||||||
|
Card 153: 2 55 64 32 42 68 63 52 50 90 | 60 20 30 16 98 85 1 35 97 33 64 65 79 12 51 78 48 49 86 50 57 99 3 10 46
|
||||||
|
Card 154: 4 72 77 78 27 68 37 57 82 91 | 38 39 36 23 43 53 71 24 63 64 89 80 49 97 60 47 21 90 93 48 70 86 65 66 3
|
||||||
|
Card 155: 90 34 33 91 74 28 36 4 5 39 | 51 23 30 73 37 97 99 25 32 54 67 52 75 48 38 78 42 35 13 6 81 63 49 83 80
|
||||||
|
Card 156: 38 8 26 2 43 32 72 45 29 5 | 77 89 32 45 73 34 23 80 1 78 5 86 19 38 7 59 75 29 8 43 26 72 20 12 2
|
||||||
|
Card 157: 42 20 82 74 94 44 54 33 69 93 | 94 98 34 54 20 68 82 18 13 53 33 67 22 42 72 16 62 6 25 17 46 56 87 9 7
|
||||||
|
Card 158: 41 46 13 9 93 48 65 76 3 4 | 10 67 53 57 44 18 47 13 98 59 6 52 5 91 17 54 97 61 68 26 25 42 40 72 22
|
||||||
|
Card 159: 73 1 50 18 66 97 12 93 41 80 | 12 80 36 41 53 1 50 18 19 75 3 40 39 16 83 85 66 73 35 70 97 25 56 67 93
|
||||||
|
Card 160: 86 47 9 35 3 85 33 53 99 50 | 44 55 12 43 86 13 20 31 3 37 33 28 9 41 98 39 35 58 19 29 25 1 82 67 71
|
||||||
|
Card 161: 68 93 52 43 62 15 66 33 53 84 | 27 44 37 39 50 71 63 94 20 79 62 38 42 72 12 33 85 9 43 93 83 68 28 47 45
|
||||||
|
Card 162: 54 43 38 6 50 80 72 41 78 92 | 92 73 55 15 34 61 79 57 72 71 53 83 50 41 47 60 10 58 67 36 69 2 63 84 5
|
||||||
|
Card 163: 58 52 14 99 77 51 70 16 35 57 | 60 51 34 86 92 66 10 93 99 16 67 27 47 19 35 61 58 4 9 28 82 84 42 38 43
|
||||||
|
Card 164: 9 19 34 3 38 46 74 85 42 87 | 68 71 70 98 63 84 10 59 16 76 91 18 36 4 60 77 97 80 64 88 95 66 94 58 37
|
||||||
|
Card 165: 46 68 72 82 41 79 28 6 19 23 | 88 74 16 36 44 19 46 63 85 77 94 38 42 28 21 26 70 66 1 51 9 45 49 20 6
|
||||||
|
Card 166: 94 97 38 52 45 84 81 71 49 22 | 86 66 45 40 21 58 6 82 29 87 38 68 20 96 95 49 4 77 25 36 32 51 18 94 48
|
||||||
|
Card 167: 47 98 46 63 38 23 57 61 31 96 | 63 44 68 56 67 26 27 7 10 93 79 50 4 48 42 9 19 5 23 11 47 52 40 88 58
|
||||||
|
Card 168: 36 59 73 99 8 49 63 19 34 74 | 24 30 98 46 65 95 91 14 7 37 87 57 40 67 16 94 66 93 12 82 48 28 88 90 58
|
||||||
|
Card 169: 34 48 11 54 74 40 13 71 86 76 | 7 65 66 23 95 45 27 42 47 60 20 92 28 84 50 73 2 80 41 99 77 62 17 21 85
|
||||||
|
Card 170: 67 6 17 58 51 2 19 72 33 41 | 34 20 46 35 29 89 12 77 37 97 88 4 98 44 82 39 38 15 32 48 63 65 68 21 93
|
||||||
|
Card 171: 63 1 50 71 14 33 78 85 40 99 | 40 32 54 69 4 93 85 1 99 50 71 78 57 22 63 5 14 38 33 72 16 24 29 64 13
|
||||||
|
Card 172: 33 52 35 85 57 49 60 11 80 43 | 39 92 94 83 49 81 82 79 97 5 72 33 87 80 63 52 96 53 1 43 35 60 85 57 11
|
||||||
|
Card 173: 33 40 92 88 97 77 20 84 27 23 | 58 33 12 27 34 92 46 23 13 62 77 82 43 54 40 64 37 96 15 84 60 88 20 97 1
|
||||||
|
Card 174: 4 6 66 57 77 24 59 50 9 46 | 63 57 2 60 4 89 88 46 24 14 5 66 16 59 11 13 64 39 38 92 65 44 77 17 79
|
||||||
|
Card 175: 55 82 61 80 67 89 90 93 43 1 | 7 3 84 23 14 69 47 35 57 10 95 99 64 63 42 93 96 6 53 72 29 33 18 56 83
|
||||||
|
Card 176: 70 7 30 29 66 82 8 24 89 11 | 9 67 86 87 22 76 50 51 40 21 6 98 94 17 12 74 33 34 55 20 53 99 1 80 52
|
||||||
|
Card 177: 78 14 51 53 26 44 36 2 33 23 | 53 26 48 24 5 88 33 90 36 22 29 89 51 45 70 44 23 2 73 91 57 92 78 47 14
|
||||||
|
Card 178: 19 75 43 85 35 45 93 59 57 7 | 57 32 12 45 76 59 71 85 74 46 69 25 86 10 50 44 79 95 93 49 63 24 82 33 73
|
||||||
|
Card 179: 35 18 9 3 88 62 83 98 61 41 | 41 70 64 48 31 61 45 46 15 99 69 51 98 28 87 17 30 26 24 52 29 71 60 38 66
|
||||||
|
Card 180: 13 20 97 73 94 22 80 40 47 85 | 41 30 22 11 65 87 69 23 58 27 59 57 96 55 82 20 79 76 85 3 89 13 8 25 94
|
||||||
|
Card 181: 14 74 36 86 59 49 69 24 65 28 | 93 24 57 83 34 62 80 85 74 36 23 9 13 45 52 67 64 26 15 69 95 21 43 38 77
|
||||||
|
Card 182: 41 88 35 24 7 6 11 79 8 56 | 25 78 66 69 64 44 95 81 85 48 87 26 47 63 56 3 94 86 8 52 24 73 15 20 19
|
||||||
|
Card 183: 2 35 46 34 76 99 12 47 33 64 | 15 53 32 21 73 11 7 26 75 95 37 17 67 56 77 99 39 72 82 47 2 64 20 33 55
|
||||||
|
Card 184: 73 43 57 65 99 86 29 32 69 53 | 4 19 89 82 48 94 18 53 17 64 45 85 26 52 97 43 47 1 41 90 65 72 46 20 31
|
||||||
|
Card 185: 81 71 51 68 27 22 63 76 85 3 | 84 20 91 48 47 98 13 30 83 64 93 26 50 78 66 77 9 97 32 12 90 41 74 52 43
|
||||||
|
Card 186: 76 27 92 85 62 60 75 11 65 70 | 48 51 58 99 40 52 50 10 95 1 46 21 67 78 86 36 55 14 84 28 12 18 8 42 53
|
||||||
|
Card 187: 88 55 79 69 45 73 16 21 5 11 | 95 24 32 59 96 37 87 7 28 89 33 82 35 60 83 20 43 75 57 80 1 9 52 31 36
|
||||||
|
Card 188: 61 32 89 34 13 46 66 42 22 91 | 74 52 2 85 82 57 8 41 26 6 10 38 95 64 90 79 3 60 98 76 45 94 51 70 28
|
||||||
166
src/bin/part05.rs
Normal file
166
src/bin/part05.rs
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
use std::time;
|
||||||
|
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
|
struct Almanac {
|
||||||
|
seeds: Vec<u32>,
|
||||||
|
seed_to_soil: Vec<Mapping>,
|
||||||
|
soil_to_fertilizer: Vec<Mapping>,
|
||||||
|
fertilizer_to_water: Vec<Mapping>,
|
||||||
|
water_to_light:Vec<Mapping>,
|
||||||
|
light_to_temperature: Vec<Mapping>,
|
||||||
|
temperature_to_humidity: Vec<Mapping>,
|
||||||
|
humidity_to_location: Vec<Mapping>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Almanac {
|
||||||
|
fn new() -> Almanac {
|
||||||
|
Almanac {
|
||||||
|
seeds: Vec::new(),
|
||||||
|
seed_to_soil: Vec::new(),
|
||||||
|
soil_to_fertilizer: Vec::new(),
|
||||||
|
fertilizer_to_water: Vec::new(),
|
||||||
|
water_to_light: Vec::new(),
|
||||||
|
light_to_temperature: Vec::new(),
|
||||||
|
temperature_to_humidity: Vec::new(),
|
||||||
|
humidity_to_location: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_soil(&self, seed: u32) -> u32 {
|
||||||
|
map(seed, &self.seed_to_soil)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_fertilizer(&self, seed: u32) -> u32 {
|
||||||
|
map(self.get_soil(seed), &self.soil_to_fertilizer)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_water(&self, seed: u32) -> u32 {
|
||||||
|
map(self.get_fertilizer(seed), &self.fertilizer_to_water)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_light(&self, seed: u32) -> u32 {
|
||||||
|
map(self.get_water(seed), &self.water_to_light)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_temperature(&self, seed: u32) -> u32 {
|
||||||
|
map(self.get_light(seed), &self.light_to_temperature)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_humidity(&self, seed: u32) -> u32 {
|
||||||
|
map(self.get_temperature(seed), &self.temperature_to_humidity)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_location(&self, seed: u32) -> u32 {
|
||||||
|
map(self.get_humidity(seed), &self.humidity_to_location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Mapping {
|
||||||
|
dst_range_start: u64,
|
||||||
|
src_range_start: u64,
|
||||||
|
range_length: u64
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let s = time::Instant::now();
|
||||||
|
|
||||||
|
let almanac = load_input();
|
||||||
|
let mut locations: Vec<u32> = Vec::new();
|
||||||
|
|
||||||
|
// for seed in &almanac.seeds {
|
||||||
|
// let location = almanac.get_location(*seed);
|
||||||
|
// locations.push(location);
|
||||||
|
|
||||||
|
// println!("Seed: {}", seed);
|
||||||
|
// println!("Location: {}", location);
|
||||||
|
// println!();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// println!("Lowest location #1: {}", locations.iter().min().unwrap());
|
||||||
|
// locations.clear();
|
||||||
|
|
||||||
|
let mut seeds = almanac.seeds.iter();
|
||||||
|
loop {
|
||||||
|
let seed_start = seeds.next().unwrap_or(&0);
|
||||||
|
if *seed_start == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let seed_end = seed_start + seeds.next().unwrap();
|
||||||
|
let seed_count = seed_end - seed_start;
|
||||||
|
|
||||||
|
let s1 = time::Instant::now();
|
||||||
|
|
||||||
|
let locs = (*seed_start..seed_end).into_par_iter().map(|seed| {
|
||||||
|
almanac.get_location(seed)
|
||||||
|
});
|
||||||
|
locations.push(locs.min().unwrap());
|
||||||
|
|
||||||
|
let d1 = time::Instant::now().duration_since(s1);
|
||||||
|
println!("Parsed {} seeds in {:?} ({} seeds/s)", seed_count, d1, seed_count as f64 / d1.as_secs_f64());
|
||||||
|
}
|
||||||
|
|
||||||
|
let d = time::Instant::now().duration_since(s);
|
||||||
|
println!("Parsed in {:?}", d);
|
||||||
|
|
||||||
|
println!("Lowest location #2: {}", locations.iter().min().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_input() -> Almanac {
|
||||||
|
let mut almanac = Almanac::new();
|
||||||
|
|
||||||
|
let data = std::fs::read_to_string("src/bin/part05.txt")
|
||||||
|
.expect("Could not read file");
|
||||||
|
let mut lines = data.lines();
|
||||||
|
|
||||||
|
almanac.seeds = lines.next().unwrap().split(": ").last().unwrap().split_whitespace().map(|s| s.parse::<u32>().unwrap()).collect::<Vec<_>>();
|
||||||
|
almanac.seed_to_soil = parse_map(&mut lines);
|
||||||
|
almanac.soil_to_fertilizer = parse_map(&mut lines);
|
||||||
|
almanac.fertilizer_to_water = parse_map(&mut lines);
|
||||||
|
almanac.water_to_light = parse_map(&mut lines);
|
||||||
|
almanac.light_to_temperature = parse_map(&mut lines);
|
||||||
|
almanac.temperature_to_humidity = parse_map(&mut lines);
|
||||||
|
almanac.humidity_to_location = parse_map(&mut lines);
|
||||||
|
|
||||||
|
almanac
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_map(line_iter: &mut dyn Iterator<Item=&str>) -> Vec<Mapping> {
|
||||||
|
let mut mappings = Vec::new();
|
||||||
|
|
||||||
|
line_iter.nth(0);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let line = line_iter.next().unwrap_or("");
|
||||||
|
if line.is_empty() {
|
||||||
|
break;
|
||||||
|
} else if line.ends_with(":") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let mut raw_mapping = line.split_whitespace();
|
||||||
|
mappings.push(Mapping {
|
||||||
|
dst_range_start: raw_mapping.next().unwrap().parse::<u64>().unwrap(),
|
||||||
|
src_range_start: raw_mapping.next().unwrap().parse::<u64>().unwrap(),
|
||||||
|
range_length: raw_mapping.next().unwrap().parse::<u64>().unwrap()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mappings.sort_by(|a, b| b.src_range_start.cmp(&a.src_range_start));
|
||||||
|
|
||||||
|
mappings
|
||||||
|
}
|
||||||
|
|
||||||
|
fn map(src: u32, mappings: &Vec<Mapping>) -> u32 {
|
||||||
|
let src = src as u64;
|
||||||
|
let mut dst = src;
|
||||||
|
|
||||||
|
let mapping = mappings.iter().find(|mapping| {
|
||||||
|
src >= mapping.src_range_start && src < mapping.src_range_start + mapping.range_length
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(mapping) = mapping {
|
||||||
|
dst = (mapping.dst_range_start + src) - mapping.src_range_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
dst as u32
|
||||||
|
}
|
||||||
33
src/bin/part05.sample
Normal file
33
src/bin/part05.sample
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
seeds: 79 14 55 13
|
||||||
|
|
||||||
|
seed-to-soil map:
|
||||||
|
50 98 2
|
||||||
|
52 50 48
|
||||||
|
|
||||||
|
soil-to-fertilizer map:
|
||||||
|
0 15 37
|
||||||
|
37 52 2
|
||||||
|
39 0 15
|
||||||
|
|
||||||
|
fertilizer-to-water map:
|
||||||
|
49 53 8
|
||||||
|
0 11 42
|
||||||
|
42 0 7
|
||||||
|
57 7 4
|
||||||
|
|
||||||
|
water-to-light map:
|
||||||
|
88 18 7
|
||||||
|
18 25 70
|
||||||
|
|
||||||
|
light-to-temperature map:
|
||||||
|
45 77 23
|
||||||
|
81 45 19
|
||||||
|
68 64 13
|
||||||
|
|
||||||
|
temperature-to-humidity map:
|
||||||
|
0 69 1
|
||||||
|
1 0 69
|
||||||
|
|
||||||
|
humidity-to-location map:
|
||||||
|
60 56 37
|
||||||
|
56 93 4
|
||||||
213
src/bin/part05.txt
Normal file
213
src/bin/part05.txt
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
seeds: 3139431799 50198205 3647185634 110151761 2478641666 139825503 498892555 8913570 961540761 489996751 568452082 100080382 907727477 42158689 1617552130 312026427 342640189 97088268 2049289560 336766062
|
||||||
|
|
||||||
|
seed-to-soil map:
|
||||||
|
1615836342 1401909974 23067952
|
||||||
|
785532007 269485885 88937774
|
||||||
|
3019002892 2773729385 10470414
|
||||||
|
4202163101 2747292152 26437233
|
||||||
|
3183210415 4217634159 77333137
|
||||||
|
2847460091 3211730218 136699600
|
||||||
|
2455891790 3791729773 70553041
|
||||||
|
3260543552 2581343101 165949051
|
||||||
|
3840286095 2849853212 361877006
|
||||||
|
4228600334 2361239030 66366962
|
||||||
|
1594559581 1077839137 21276761
|
||||||
|
380069408 165017790 44262617
|
||||||
|
3598718222 1894384162 241567873
|
||||||
|
0 1424977926 190757551
|
||||||
|
1894384162 2810496375 39356837
|
||||||
|
424332025 606264721 196539291
|
||||||
|
3521487829 2221977524 77230393
|
||||||
|
742681934 69797365 36566707
|
||||||
|
1638904294 1615735477 139190145
|
||||||
|
1335949488 0 69797365
|
||||||
|
779248641 802804012 6283366
|
||||||
|
2638766896 4008940964 208693195
|
||||||
|
250963029 1142644585 70452661
|
||||||
|
1933740999 3470280789 321448984
|
||||||
|
190757551 209280407 60205478
|
||||||
|
1778094439 1099115898 43528687
|
||||||
|
2255189983 3348429818 121850971
|
||||||
|
1000500225 809087378 268751759
|
||||||
|
1269251984 1754925622 66697504
|
||||||
|
874469781 358423659 126030444
|
||||||
|
2526444831 2135952035 86025489
|
||||||
|
2439072067 3992121241 16819723
|
||||||
|
3426492603 3897126015 94995226
|
||||||
|
1405746853 1213097246 188812728
|
||||||
|
321415690 106364072 58653718
|
||||||
|
2984159691 3862282814 34843201
|
||||||
|
2377040954 2299207917 62031113
|
||||||
|
3029473306 2427605992 153737109
|
||||||
|
2612470320 2784199799 26296576
|
||||||
|
620871316 484454103 121810618
|
||||||
|
|
||||||
|
soil-to-fertilizer map:
|
||||||
|
4245401761 2352458099 28057201
|
||||||
|
2099789767 3998256334 14950546
|
||||||
|
3446056574 2749719529 135349925
|
||||||
|
890092371 1379309857 42097049
|
||||||
|
953714890 896502554 10335567
|
||||||
|
3115342240 2380515300 218129381
|
||||||
|
3333471621 3885671381 112584953
|
||||||
|
663999152 0 226093219
|
||||||
|
1873325002 727305635 169196919
|
||||||
|
2042521921 1328150912 51158945
|
||||||
|
3581406499 4034715214 260252082
|
||||||
|
500989478 564295961 163009674
|
||||||
|
4273458962 4013206880 21508334
|
||||||
|
3992733429 2099789767 164092891
|
||||||
|
4156826320 2263882658 88575441
|
||||||
|
3841658581 2598644681 151074848
|
||||||
|
1094703999 226093219 21270249
|
||||||
|
1708571521 399542480 164753481
|
||||||
|
964050457 247363468 130653542
|
||||||
|
1236290130 1421406906 171284482
|
||||||
|
0 1592691388 500989478
|
||||||
|
932189420 378017010 21525470
|
||||||
|
2114740313 2885069454 1000601927
|
||||||
|
1115974248 1207835030 120315882
|
||||||
|
1407574612 906838121 300996909
|
||||||
|
|
||||||
|
fertilizer-to-water map:
|
||||||
|
3217858280 3761663130 355893932
|
||||||
|
2319366035 2401839275 72374872
|
||||||
|
1962726423 909927230 105011330
|
||||||
|
2115307878 441322644 204058157
|
||||||
|
2095064202 1824085445 20243676
|
||||||
|
110580631 329763915 34129824
|
||||||
|
2573484127 2701101998 225220022
|
||||||
|
1780224111 2342656863 59182412
|
||||||
|
1717605398 1571533532 62618713
|
||||||
|
3589165621 3062909078 75538793
|
||||||
|
842280446 1871096488 471560375
|
||||||
|
409726333 0 243114563
|
||||||
|
397401582 760576019 12324751
|
||||||
|
0 667815878 92760141
|
||||||
|
3990305711 2926322020 5981819
|
||||||
|
251664023 1741105813 32320840
|
||||||
|
2072629125 645380801 22435077
|
||||||
|
92760141 363893739 17820490
|
||||||
|
2798704149 3138447871 156185660
|
||||||
|
3664704414 2573484127 127617871
|
||||||
|
1839406523 381714229 59608415
|
||||||
|
283984863 1844329121 26767367
|
||||||
|
1313840821 1176023584 27579684
|
||||||
|
2391740907 1790738543 33346902
|
||||||
|
3929650615 4234312200 60655096
|
||||||
|
3996287530 3557602002 204061128
|
||||||
|
1402088224 772900770 137026460
|
||||||
|
1911435456 2474214147 51290967
|
||||||
|
1539114684 1393042818 178490714
|
||||||
|
3573752212 4117557062 15413409
|
||||||
|
1341420505 1014938560 60667719
|
||||||
|
3792322285 4132970471 6723091
|
||||||
|
4200348658 4139693562 80082634
|
||||||
|
652840896 1203603268 189439550
|
||||||
|
310752230 243114563 86649352
|
||||||
|
2425087809 1075606279 100417305
|
||||||
|
1899014938 1773426653 12420518
|
||||||
|
2067737753 1785847171 4891372
|
||||||
|
3799045376 2932303839 130605239
|
||||||
|
2954889809 3294633531 262968471
|
||||||
|
4280431292 4219776196 14536004
|
||||||
|
144710455 1634152245 106953568
|
||||||
|
|
||||||
|
water-to-light map:
|
||||||
|
1071107509 759231097 26724064
|
||||||
|
1293599454 642189614 64567949
|
||||||
|
3147690498 1633749175 71376364
|
||||||
|
3487999223 4080968704 155844998
|
||||||
|
1700873635 2097781236 292450760
|
||||||
|
1146121952 1950303734 147477502
|
||||||
|
2864027062 1470573702 75076585
|
||||||
|
2507471274 3021419800 175807670
|
||||||
|
2939103647 922829268 123372939
|
||||||
|
2826742681 2551285626 37284381
|
||||||
|
719212681 1821763210 100196810
|
||||||
|
4236813702 4292227071 2740225
|
||||||
|
3643844221 3837685117 243283587
|
||||||
|
209103905 785955161 52302440
|
||||||
|
100332146 752700417 6530680
|
||||||
|
1478192138 3229160565 10342236
|
||||||
|
1358167403 3239502801 94242072
|
||||||
|
3219066862 706757563 45942854
|
||||||
|
3062476586 1358475140 29661777
|
||||||
|
819409491 2390231996 26561329
|
||||||
|
4195136152 3511184798 41677550
|
||||||
|
1488534374 1046202207 35444248
|
||||||
|
3887127808 3552862348 284822769
|
||||||
|
2188804057 1705125539 116637671
|
||||||
|
0 309410320 100332146
|
||||||
|
1117778238 1921960020 28343714
|
||||||
|
261406345 3333744873 74978759
|
||||||
|
2100705169 1545650287 88098888
|
||||||
|
3450098653 3473284228 37900570
|
||||||
|
2742067948 1273800407 84674733
|
||||||
|
2305441728 107380774 202029546
|
||||||
|
3265009716 1130086491 143713916
|
||||||
|
1993324395 0 107380774
|
||||||
|
1523978622 465294601 176895013
|
||||||
|
106862826 2588570007 102241079
|
||||||
|
2683278944 864040264 58789004
|
||||||
|
4239553927 4236813702 55413369
|
||||||
|
1097831573 1081646455 19946665
|
||||||
|
524293914 1101593120 28493371
|
||||||
|
336385104 2833510990 187908810
|
||||||
|
552787285 3197227470 31933095
|
||||||
|
845970820 2690811086 142699904
|
||||||
|
988670724 1388136917 82436785
|
||||||
|
1452409475 838257601 25782663
|
||||||
|
3092138363 409742466 55552135
|
||||||
|
584720380 2416793325 134492301
|
||||||
|
4171950577 3450098653 23185575
|
||||||
|
|
||||||
|
light-to-temperature map:
|
||||||
|
2906633798 3843376160 451591136
|
||||||
|
1332454428 1190958320 69004583
|
||||||
|
1837712164 0 353313230
|
||||||
|
494809338 353313230 376619264
|
||||||
|
871428602 729932494 461025826
|
||||||
|
1401459011 1754772241 373416033
|
||||||
|
3976747173 3375456648 91164221
|
||||||
|
3495346659 3466620869 376755291
|
||||||
|
0 1259962903 494809338
|
||||||
|
2608238358 2459541635 298395440
|
||||||
|
3907558614 2984992977 69188559
|
||||||
|
3872101950 2286963246 35456664
|
||||||
|
4067911394 2757937075 227055902
|
||||||
|
3358224934 2322419910 137121725
|
||||||
|
2286963246 3054181536 321275112
|
||||||
|
1774875044 2128188274 62837120
|
||||||
|
|
||||||
|
temperature-to-humidity map:
|
||||||
|
3966168141 3406025946 214996780
|
||||||
|
4181164921 3292223571 113802375
|
||||||
|
1493139015 1471031672 367564898
|
||||||
|
1423475871 1838596570 69663144
|
||||||
|
0 479293006 226560784
|
||||||
|
2500785470 2859072453 433151118
|
||||||
|
3197453551 2500785470 96923792
|
||||||
|
758446483 1237739489 233292183
|
||||||
|
991738666 0 278789291
|
||||||
|
3555740534 3884539689 410427607
|
||||||
|
3294377343 2597709262 261363191
|
||||||
|
226560784 705853790 531885699
|
||||||
|
1860703913 305742584 20602508
|
||||||
|
2933936588 3621022726 263516963
|
||||||
|
1881306421 278789291 26953293
|
||||||
|
1270527957 326345092 152947914
|
||||||
|
|
||||||
|
humidity-to-location map:
|
||||||
|
848612454 2250862530 61410922
|
||||||
|
910023376 3689675651 35197452
|
||||||
|
3724873103 3865027106 240221283
|
||||||
|
483883727 3324946924 364728727
|
||||||
|
0 1766978803 483883727
|
||||||
|
1957894300 561533 922927950
|
||||||
|
945220828 2590144784 734802140
|
||||||
|
2880822250 0 561533
|
||||||
|
3447014853 1489120553 277858250
|
||||||
|
2881383783 923489483 565631070
|
||||||
|
3965094386 3724873103 140154003
|
||||||
|
1680022968 2312273452 277871332
|
||||||
87
src/bin/part06.rs
Normal file
87
src/bin/part06.rs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
use std::time;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Race {
|
||||||
|
time: u64,
|
||||||
|
distance: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Race {
|
||||||
|
fn get_boundaries(&self) -> (u32, u32) {
|
||||||
|
let sqrt = ((self.time * self.time - 4 * self.distance) as f64).sqrt() / 2.0;
|
||||||
|
let t1 = (self.time as f64 / 2.0) - sqrt + 0.0001;
|
||||||
|
let t2 = (self.time as f64 / 2.0) + sqrt - 0.0001;
|
||||||
|
(t1.ceil() as u32, t2.floor() as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_num_of_solutions(&self) -> u32 {
|
||||||
|
let (t1, t2) = self.get_boundaries();
|
||||||
|
t2 - t1 + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("PART 1");
|
||||||
|
|
||||||
|
let s1 = time::Instant::now();
|
||||||
|
let races = load_input_part1();
|
||||||
|
let d1 = s1.elapsed();
|
||||||
|
println!("Load: {:?}", d1);
|
||||||
|
|
||||||
|
let s2 = time::Instant::now();
|
||||||
|
let num_solutions = races.iter().map(|r| r.get_num_of_solutions()).collect::<Vec<_>>();
|
||||||
|
let d2 = s2.elapsed();
|
||||||
|
println!("Num-Solutions: {:?} in {:?}", num_solutions, d2);
|
||||||
|
|
||||||
|
let s3 = time::Instant::now();
|
||||||
|
let result: u32 = num_solutions.iter().map(|n| *n as u32).product();
|
||||||
|
let d3 = s3.elapsed();
|
||||||
|
println!("Result: {} in {:?}", result, d3);
|
||||||
|
|
||||||
|
println!("PART 2");
|
||||||
|
|
||||||
|
let race = load_input_part2();
|
||||||
|
let s4 = time::Instant::now();
|
||||||
|
let num_solutions = race.get_num_of_solutions();
|
||||||
|
let d4 = s4.elapsed();
|
||||||
|
println!("Num-Solutions: {:?} in {:?}", num_solutions, d4);
|
||||||
|
|
||||||
|
println!("Total: {:?}", d1 + d2 + d3 + d4);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_input_part1() -> Vec<Race> {
|
||||||
|
let mut races: Vec<Race> = Vec::new();
|
||||||
|
|
||||||
|
let data = std::fs::read_to_string("src/bin/part06.txt")
|
||||||
|
.expect("Could not read file");
|
||||||
|
let mut lines = data.lines();
|
||||||
|
|
||||||
|
let times = lines.next().unwrap().split_whitespace().skip(1).map(|s| s.parse::<u64>().unwrap()).collect::<Vec<_>>();
|
||||||
|
let distances = lines.next().unwrap().split_whitespace().skip(1).map(|s| s.parse::<u64>().unwrap()).collect::<Vec<_>>();
|
||||||
|
|
||||||
|
for (i, t) in times.iter().enumerate() {
|
||||||
|
races.push(
|
||||||
|
Race {
|
||||||
|
time: *t,
|
||||||
|
distance: distances[i]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
races
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_input_part2() -> Race {
|
||||||
|
let data = std::fs::read_to_string("src/bin/part06.txt")
|
||||||
|
.expect("Could not read file");
|
||||||
|
let mut lines = data.lines();
|
||||||
|
|
||||||
|
let time = lines.next().unwrap().split_whitespace().skip(1).fold(String::new(), |acc, x| acc.to_owned() + x).parse::<u64>().unwrap();
|
||||||
|
let distance = lines.next().unwrap().split_whitespace().skip(1).fold(String::new(), |acc, x| acc.to_owned() + x).parse::<u64>().unwrap();
|
||||||
|
|
||||||
|
Race {
|
||||||
|
time,
|
||||||
|
distance
|
||||||
|
}
|
||||||
|
}
|
||||||
2
src/bin/part06.sample
Normal file
2
src/bin/part06.sample
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Time: 7 15 30
|
||||||
|
Distance: 9 40 200
|
||||||
2
src/bin/part06.txt
Normal file
2
src/bin/part06.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Time: 61 70 90 66
|
||||||
|
Distance: 643 1184 1362 1041
|
||||||
Reference in New Issue
Block a user