Import aoc2022 history into 2022/
git-subtree-dir: 2022 git-subtree-mainline:addb35fc75git-subtree-split:e5d89711e2
No files matched your search
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 5.2 KiB |
@@ -0,0 +1,7 @@
|
||||
**/target
|
||||
input
|
||||
flamegraph.svg
|
||||
perf.data*
|
||||
guesses
|
||||
.aoc_tiles/*
|
||||
!.aoc_tiles/tiles/
|
||||
@@ -0,0 +1,32 @@
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: rust-linting
|
||||
name: Rust linting
|
||||
entry: cargo fmt --all --
|
||||
pass_filenames: true
|
||||
types: [file, rust]
|
||||
language: system
|
||||
- id: rust-clippy
|
||||
name: Rust clippy
|
||||
entry: cargo clippy --lib --all-features --tests --
|
||||
pass_filenames: false
|
||||
types: [file, rust]
|
||||
language: system
|
||||
- repo: https://github.com/LiquidFun/aoc_tiles
|
||||
rev: 0.7.2
|
||||
hooks:
|
||||
- id: aoc-tiles
|
||||
language: system
|
||||
# Optionally use these arguments. Auto add tiles to git adds the tiles to git,
|
||||
# possibly amends your commit by creating the tile images and updating the README.
|
||||
# Language sorting shows the preference of the order of the languages to use.
|
||||
# Exclude paterns are globs which can be used to exclude files when creating
|
||||
# the tiles. See the customization section in the README for more flags.
|
||||
# Simply remove the comments (#) below for args and the flags you want.
|
||||
args:
|
||||
- --auto-add-tiles-to-git=amend
|
||||
- --overwrite-year=2022
|
||||
- --tile-width-px=200
|
||||
# - --language-sorting=jl,kt,py,rs
|
||||
# - --exclude-patterns=2021/*/*.apl,2021/*/*.py,2021/*/*.cpp
|
||||
@@ -0,0 +1 @@
|
||||
max_width = 120
|
||||
@@ -0,0 +1,712 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
||||
|
||||
[[package]]
|
||||
name = "aoc-runner"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d21ef9204ad206a5a3e918e9920da04e1118ad91ce4f23570be964b9d6b9dfcb"
|
||||
|
||||
[[package]]
|
||||
name = "aoc-runner-derive"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba8b944269d3fee645d281b1335e1797044db497bb02d0098cc3fdb8900069cc"
|
||||
dependencies = [
|
||||
"aoc-runner-internal",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aoc-runner-internal"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "274b0ba7f3669a45ec0aaacf94eb032a749de880ab776091576cca94037c9982"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aoc2022"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aoc-runner",
|
||||
"aoc-runner-derive",
|
||||
"atoi",
|
||||
"bitflags",
|
||||
"cached",
|
||||
"colored",
|
||||
"indicatif",
|
||||
"itertools",
|
||||
"lazy_static",
|
||||
"nom",
|
||||
"rayon",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"thread_local",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atoi"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
|
||||
|
||||
[[package]]
|
||||
name = "cached"
|
||||
version = "0.54.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9718806c4a2fe9e8a56fd736f97b340dd10ed1be8ed733ed50449f351dc33cae"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"cached_proc_macro",
|
||||
"cached_proc_macro_types",
|
||||
"hashbrown",
|
||||
"once_cell",
|
||||
"thiserror",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cached_proc_macro"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f42a145ed2d10dce2191e1dcf30cfccfea9026660e143662ba5eec4017d5daa"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cached_proc_macro_types"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ade8366b8bd5ba243f0a58f036cc0ca8a2f069cff1a2351ef1cac6b083e16fc0"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.15.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"unicode-width",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
|
||||
|
||||
[[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.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
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 = "indicatif"
|
||||
version = "0.17.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
|
||||
dependencies = [
|
||||
"console",
|
||||
"number_prefix",
|
||||
"portable-atomic",
|
||||
"rayon",
|
||||
"unicode-width",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.177"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "number_prefix"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f"
|
||||
dependencies = [
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.145"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[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.111"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.111",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-time"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.111",
|
||||
]
|
||||
@@ -0,0 +1,25 @@
|
||||
[package]
|
||||
name = "aoc2022"
|
||||
edition = "2024"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
aoc-runner = "0.3.0"
|
||||
aoc-runner-derive = "0.3.0"
|
||||
atoi = "2.0.0"
|
||||
bitflags = "2.6.0"
|
||||
cached = "0.54.0"
|
||||
colored = "2.1.0"
|
||||
indicatif = { version = "0.17.9", features = ["rayon"] }
|
||||
itertools = "0.13.0"
|
||||
lazy_static = "1.5.0"
|
||||
nom = "7.1.3"
|
||||
rayon = "1.10.0"
|
||||
regex = "1.11.1"
|
||||
rustc-hash = "2.1.0"
|
||||
thread_local = "1.1.8"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
opt-level = 3
|
||||
overflow-checks = false
|
||||
@@ -0,0 +1,26 @@
|
||||
<!-- AOC TILES BEGIN -->
|
||||
<h1 align="center">
|
||||
2022 - 14 ⭐ - Rust
|
||||
</h1>
|
||||
<a href="src/day1.rs">
|
||||
<img src=".aoc_tiles/tiles/2022/01.png" width="200">
|
||||
</a>
|
||||
<a href="src/day2.rs">
|
||||
<img src=".aoc_tiles/tiles/2022/02.png" width="200">
|
||||
</a>
|
||||
<a href="src/day3.rs">
|
||||
<img src=".aoc_tiles/tiles/2022/03.png" width="200">
|
||||
</a>
|
||||
<a href="src/day4.rs">
|
||||
<img src=".aoc_tiles/tiles/2022/04.png" width="200">
|
||||
</a>
|
||||
<a href="src/day5.rs">
|
||||
<img src=".aoc_tiles/tiles/2022/05.png" width="200">
|
||||
</a>
|
||||
<a href="src/day6.rs">
|
||||
<img src=".aoc_tiles/tiles/2022/06.png" width="200">
|
||||
</a>
|
||||
<a href="src/day7.rs">
|
||||
<img src=".aoc_tiles/tiles/2022/07.png" width="200">
|
||||
</a>
|
||||
<!-- AOC TILES END -->
|
||||
@@ -0,0 +1,60 @@
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use itertools::Itertools;
|
||||
use std::io::BufRead;
|
||||
|
||||
#[aoc_generator(day1)]
|
||||
// Sum the calories of each elf's food items
|
||||
fn parse(input: &[u8]) -> Vec<u64> {
|
||||
let mut result = Vec::new();
|
||||
let mut cur_elf = 0u64;
|
||||
for line in input.lines() {
|
||||
if let Ok(calories) = line.unwrap().parse::<u64>() {
|
||||
cur_elf += calories
|
||||
} else {
|
||||
result.push(cur_elf);
|
||||
cur_elf = 0
|
||||
}
|
||||
}
|
||||
result.push(cur_elf);
|
||||
result
|
||||
}
|
||||
|
||||
#[aoc(day1, part1)]
|
||||
fn part1(input: &[u64]) -> u64 {
|
||||
*input.iter().max().unwrap()
|
||||
}
|
||||
|
||||
#[aoc(day1, part2)]
|
||||
fn part2(input: &[u64]) -> u64 {
|
||||
input.iter().sorted().rev().take(3).sum::<u64>()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const EXAMPLE: &[u8] = b"1000
|
||||
2000
|
||||
3000
|
||||
|
||||
4000
|
||||
|
||||
5000
|
||||
6000
|
||||
|
||||
7000
|
||||
8000
|
||||
9000
|
||||
|
||||
10000";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(&parse(EXAMPLE)), 24000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn part2_example() {
|
||||
assert_eq!(part2(&parse(EXAMPLE)), 45000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
use std::{io::BufRead, str::FromStr};
|
||||
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy)]
|
||||
pub enum Shape {
|
||||
Rock,
|
||||
Paper,
|
||||
Scissors,
|
||||
}
|
||||
|
||||
impl FromStr for Shape {
|
||||
type Err = Box<dyn std::error::Error>;
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
match value {
|
||||
"A" | "X" => Ok(Self::Rock),
|
||||
"B" | "Y" => Ok(Self::Paper),
|
||||
"C" | "Z" => Ok(Self::Scissors),
|
||||
c => Err(format!("Invalid shape `{c:?}`").into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
fn fight(&self, opponent: &Shape) -> Outcome {
|
||||
match (self, opponent) {
|
||||
(Self::Rock, Self::Scissors) | (Self::Scissors, Self::Paper) | (Self::Paper, Self::Rock) => Outcome::Win,
|
||||
_ if self == opponent => Outcome::Tie,
|
||||
_ => Outcome::Lose,
|
||||
}
|
||||
}
|
||||
fn score(&self, opponent: &Shape) -> u64 {
|
||||
self.points() + self.fight(opponent).points()
|
||||
}
|
||||
fn points(&self) -> u64 {
|
||||
match self {
|
||||
Shape::Rock => 1,
|
||||
Shape::Paper => 2,
|
||||
Shape::Scissors => 3,
|
||||
}
|
||||
}
|
||||
// Return the Shape that will produce the desired outcome against us for the opponent
|
||||
fn fix_round(&self, goal: &Outcome) -> Shape {
|
||||
match goal {
|
||||
Outcome::Tie => *self,
|
||||
Outcome::Win => match self {
|
||||
Shape::Rock => Shape::Paper,
|
||||
Shape::Paper => Shape::Scissors,
|
||||
Shape::Scissors => Shape::Rock,
|
||||
},
|
||||
Outcome::Lose => match self {
|
||||
Shape::Rock => Shape::Scissors,
|
||||
Shape::Paper => Shape::Rock,
|
||||
Shape::Scissors => Shape::Paper,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Outcome {
|
||||
Win,
|
||||
Lose,
|
||||
Tie,
|
||||
}
|
||||
|
||||
impl Outcome {
|
||||
fn points(&self) -> u64 {
|
||||
match self {
|
||||
Self::Win => 6,
|
||||
Self::Tie => 3,
|
||||
Self::Lose => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Outcome {
|
||||
type Err = Box<dyn std::error::Error>;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"X" => Ok(Self::Lose),
|
||||
"Y" => Ok(Self::Tie),
|
||||
"Z" => Ok(Self::Win),
|
||||
_ => Err(format!("Invalid outcome : `{s}").into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Move {
|
||||
ours: Shape,
|
||||
theirs: Shape,
|
||||
}
|
||||
|
||||
impl FromStr for Move {
|
||||
type Err = Box<dyn std::error::Error>;
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
let (theirs, ours) = value.split_once(" ").ok_or("Unable to split")?;
|
||||
Ok(Move {
|
||||
ours: ours.parse()?,
|
||||
theirs: theirs.parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Move {
|
||||
fn score(&self) -> u64 {
|
||||
self.ours.score(&self.theirs)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MoveGoal {
|
||||
theirs: Shape,
|
||||
goal: Outcome,
|
||||
}
|
||||
|
||||
impl FromStr for MoveGoal {
|
||||
type Err = Box<dyn std::error::Error>;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let (theirs, goal) = s.split_once(" ").ok_or("Unable to split")?;
|
||||
Ok(MoveGoal {
|
||||
theirs: theirs.parse()?,
|
||||
goal: goal.parse()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl MoveGoal {
|
||||
fn get_move(&self) -> Move {
|
||||
Move {
|
||||
theirs: self.theirs,
|
||||
ours: self.theirs.fix_round(&self.goal),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[aoc_generator(day2, part1)]
|
||||
fn parse_part1(input: &[u8]) -> Vec<Move> {
|
||||
input.lines().map(|l| l.unwrap().parse().unwrap()).collect()
|
||||
}
|
||||
#[aoc_generator(day2, part2)]
|
||||
fn parse_part2(input: &[u8]) -> Vec<MoveGoal> {
|
||||
input.lines().map(|l| l.unwrap().parse().unwrap()).collect()
|
||||
}
|
||||
|
||||
#[aoc(day2, part1)]
|
||||
fn part1(input: &[Move]) -> u64 {
|
||||
input.iter().map(|m| m.score()).sum()
|
||||
}
|
||||
|
||||
#[aoc(day2, part2)]
|
||||
fn part2(input: &[MoveGoal]) -> u64 {
|
||||
input.iter().map(|mg| mg.get_move().score()).sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const EXAMPLE: &[u8] = b"A Y
|
||||
B X
|
||||
C Z";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(&parse_part1(EXAMPLE)), 15);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn part2_example() {
|
||||
assert_eq!(part2(&parse_part2(EXAMPLE)), 12);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use itertools::Itertools;
|
||||
use std::fmt::Display;
|
||||
|
||||
struct Rucksack {
|
||||
items: Vec<u8>,
|
||||
}
|
||||
|
||||
impl From<&[u8]> for Rucksack {
|
||||
fn from(s: &[u8]) -> Self {
|
||||
Self { items: s.to_vec() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Rucksack {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_fmt(format_args!(
|
||||
"{}{}",
|
||||
String::from_utf8_lossy(self.compartments()[0]),
|
||||
String::from_utf8_lossy(self.compartments()[1])
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Rucksack {
|
||||
fn compartments(&self) -> [&[u8]; 2] {
|
||||
let tup = self.items.split_at(self.items.len() / 2);
|
||||
[tup.0, tup.1]
|
||||
}
|
||||
fn common(&self) -> u8 {
|
||||
for item in self.compartments()[0] {
|
||||
if self.compartments()[1].contains(item) {
|
||||
return *item;
|
||||
}
|
||||
}
|
||||
panic!("Common item not found");
|
||||
}
|
||||
fn common_with(&self, other: &[u8]) -> impl Iterator<Item = u8> {
|
||||
self.compartments()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|c| other.contains(c))
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
fn priority(c: u8) -> u8 {
|
||||
if c.is_ascii_uppercase() {
|
||||
c - b'A' + 27
|
||||
} else if c.is_ascii_lowercase() {
|
||||
c - b'a' + 1
|
||||
} else {
|
||||
panic!("Invalid item {c}")
|
||||
}
|
||||
}
|
||||
|
||||
#[aoc_generator(day3)]
|
||||
fn parse(input: &[u8]) -> Vec<Rucksack> {
|
||||
input.split(|i| *i == b'\n').map(|x| x.into()).collect()
|
||||
}
|
||||
|
||||
#[aoc(day3, part1)]
|
||||
fn part1(input: &[Rucksack]) -> u64 {
|
||||
input.iter().map(|sack| priority(sack.common()) as u64).sum()
|
||||
}
|
||||
|
||||
#[aoc(day3, part2)]
|
||||
fn part2(input: &[Rucksack]) -> u64 {
|
||||
let mut total = 0u64;
|
||||
for sacks in input.chunks(3) {
|
||||
let commons_1 = sacks[0].common_with(&sacks[1].items).unique().collect_vec();
|
||||
let commons = sacks[2].common_with(&commons_1).unique().collect_vec();
|
||||
|
||||
if commons.len() != 1 {
|
||||
panic!(
|
||||
"Wrong number ({}) of commons for sacks {} {} {}",
|
||||
commons.len(),
|
||||
sacks[0],
|
||||
sacks[1],
|
||||
sacks[2]
|
||||
);
|
||||
}
|
||||
total += priority(commons[0]) as u64
|
||||
}
|
||||
total
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const EXAMPLE: &[u8] = b"vJrwpWtwJgWrhcsFMMfFFhFp
|
||||
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
|
||||
PmmdzqPrVvPwwTWBwg
|
||||
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
|
||||
ttgJtRGJQctTZtZT
|
||||
CrZsJsPPZsGzwwsLwLmpwMDw";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(&parse(EXAMPLE)), 157);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn part2_example() {
|
||||
assert_eq!(part2(&parse(EXAMPLE)), 70);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
|
||||
struct Pair([RangeInclusive<u64>; 2]);
|
||||
|
||||
impl From<&str> for Pair {
|
||||
fn from(value: &str) -> Self {
|
||||
let ranges = value.split_once(',').unwrap();
|
||||
Pair([parse_range(ranges.0), parse_range(ranges.1)])
|
||||
}
|
||||
}
|
||||
|
||||
impl Pair {
|
||||
fn fully_contained(&self) -> bool {
|
||||
(self.0[0].start() <= self.0[1].start() && self.0[0].end() >= self.0[1].end())
|
||||
|| (self.0[1].start() <= self.0[0].start() && self.0[1].end() >= self.0[0].end())
|
||||
}
|
||||
fn overlaps(&self) -> bool {
|
||||
self.0[0].contains(self.0[1].start())
|
||||
|| self.0[0].contains(self.0[1].end())
|
||||
|| self.0[1].contains(self.0[0].start())
|
||||
|| self.0[1].contains(self.0[0].end())
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_range(s: &str) -> RangeInclusive<u64> {
|
||||
let (lower, upper) = s.split_once('-').unwrap();
|
||||
RangeInclusive::new(lower.parse().unwrap(), upper.parse().unwrap())
|
||||
}
|
||||
|
||||
#[aoc_generator(day4)]
|
||||
fn parse(input: &str) -> Vec<Pair> {
|
||||
input.lines().map(|l| l.into()).collect()
|
||||
}
|
||||
|
||||
#[aoc(day4, part1)]
|
||||
fn part1(input: &[Pair]) -> u64 {
|
||||
input.iter().filter(|p| p.fully_contained()).count() as u64
|
||||
}
|
||||
|
||||
#[aoc(day4, part2)]
|
||||
fn part2(input: &[Pair]) -> u64 {
|
||||
input.iter().filter(|p| p.overlaps()).count() as u64
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const EXAMPLE: &str = "2-4,6-8
|
||||
2-3,4-5
|
||||
5-7,7-9
|
||||
2-8,3-7
|
||||
6-6,4-6
|
||||
2-6,4-8";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(&parse(EXAMPLE)), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn part2_example() {
|
||||
assert_eq!(part2(&parse(EXAMPLE)), 4);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use itertools::Itertools;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Instruction {
|
||||
n: usize,
|
||||
from: usize,
|
||||
to: usize,
|
||||
}
|
||||
|
||||
fn run_machine(stacks: &mut Vec<VecDeque<u8>>, instructions: &Vec<Instruction>) {
|
||||
for inst in instructions {
|
||||
for _ in 0..inst.n {
|
||||
let moving = stacks[inst.from].pop_front().unwrap();
|
||||
stacks[inst.to].push_front(moving);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_machine2(stacks: &mut Vec<VecDeque<u8>>, instructions: &Vec<Instruction>) {
|
||||
for inst in instructions {
|
||||
let mut moving = stacks[inst.from].split_off(inst.n);
|
||||
// semantics of split_off are opposite of what we want
|
||||
std::mem::swap(&mut moving, &mut stacks[inst.from]);
|
||||
moving.append(&mut stacks[inst.to]);
|
||||
stacks[inst.to] = moving;
|
||||
}
|
||||
}
|
||||
|
||||
#[aoc_generator(day5)]
|
||||
fn parse(input: &str) -> (Vec<VecDeque<u8>>, Vec<Instruction>) {
|
||||
enum State {
|
||||
Stacks,
|
||||
Ids,
|
||||
Instructions,
|
||||
}
|
||||
let mut stacks = HashMap::new();
|
||||
let mut instructions = Vec::new();
|
||||
let mut state = State::Stacks;
|
||||
for line in input.lines() {
|
||||
match state {
|
||||
State::Stacks => {
|
||||
for (stack, top) in line.as_bytes().chunks(4).into_iter().map(|s| s[1]).enumerate() {
|
||||
if top.is_ascii_digit() {
|
||||
state = State::Ids
|
||||
} else if top != b' ' {
|
||||
stacks.entry(stack).or_insert(VecDeque::new()).push_back(top);
|
||||
}
|
||||
}
|
||||
}
|
||||
State::Ids => {
|
||||
if line == "" {
|
||||
state = State::Instructions
|
||||
}
|
||||
}
|
||||
State::Instructions => {
|
||||
let tokens = line.split_ascii_whitespace().collect_vec();
|
||||
|
||||
instructions.push(Instruction {
|
||||
n: tokens[1].parse::<usize>().unwrap(),
|
||||
from: tokens[3].parse::<usize>().unwrap() - 1,
|
||||
to: tokens[5].parse::<usize>().unwrap() - 1,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
stacks
|
||||
.iter()
|
||||
.sorted_by_key(|(k, _v)| **k)
|
||||
.map(|(_k, v)| v.clone())
|
||||
.collect_vec(),
|
||||
instructions,
|
||||
)
|
||||
}
|
||||
|
||||
#[aoc(day5, part1)]
|
||||
fn part1((stacks, instructions): &(Vec<VecDeque<u8>>, Vec<Instruction>)) -> String {
|
||||
let mut stacks = stacks.clone();
|
||||
run_machine(&mut stacks, &instructions);
|
||||
stacks.iter().map(|s| *s.front().unwrap() as char).join("")
|
||||
}
|
||||
|
||||
#[aoc(day5, part2)]
|
||||
fn part2((stacks, instructions): &(Vec<VecDeque<u8>>, Vec<Instruction>)) -> String {
|
||||
let mut stacks = stacks.clone();
|
||||
run_machine2(&mut stacks, &instructions);
|
||||
stacks.iter().map(|s| *s.front().unwrap() as char).join("")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
const EXAMPLE: &str = " [D]
|
||||
[N] [C]
|
||||
[Z] [M] [P]
|
||||
1 2 3
|
||||
|
||||
move 1 from 2 to 1
|
||||
move 3 from 1 to 3
|
||||
move 2 from 2 to 1
|
||||
move 1 from 1 to 2";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(&parse(EXAMPLE)), "CMZ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn part2_example() {
|
||||
assert_eq!(part2(&parse(EXAMPLE)), "MCD");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
use aoc_runner_derive::aoc;
|
||||
use itertools::Itertools;
|
||||
use std::io::BufRead;
|
||||
|
||||
// PROBLEM 1 solution
|
||||
#[aoc(day6, part1)]
|
||||
fn part1(input: &[u8]) -> u64 {
|
||||
let s = input.lines().next().unwrap().unwrap();
|
||||
s.as_bytes()
|
||||
.windows(4)
|
||||
.enumerate()
|
||||
.find_map(|(i, window)| {
|
||||
if window[1..4].iter().all(|c| *c != window[0])
|
||||
&& window[2..4].iter().all(|c| *c != window[1])
|
||||
&& window[2] != window[3]
|
||||
{
|
||||
println!(
|
||||
"Unique window: {:?} at {}",
|
||||
window.iter().map(|c| *c as char).collect_vec(),
|
||||
i
|
||||
);
|
||||
Some(i + 4)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap() as u64
|
||||
}
|
||||
|
||||
// PROBLEM 2 solution
|
||||
#[aoc(day6, part2)]
|
||||
fn part2(input: &[u8]) -> u64 {
|
||||
let s = input.lines().next().unwrap().unwrap();
|
||||
let size = 14;
|
||||
s.as_bytes()
|
||||
.windows(size)
|
||||
.enumerate()
|
||||
.find_map(|(i, window)| {
|
||||
for i in 1..size {
|
||||
let shifted = &window[i..];
|
||||
if shifted.iter().enumerate().any(|(j, c)| *c == window[j]) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(i + 14)
|
||||
})
|
||||
.unwrap() as u64
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::day6::*;
|
||||
|
||||
const EXAMPLE1: &[u8] = b"bvwbjplbgvbhsrlpgdmjqwftvncz";
|
||||
const EXAMPLE2: &[u8] = b"nppdvjthqldpwncqszvftbrmjlhg";
|
||||
const EXAMPLE3: &[u8] = b"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg";
|
||||
const EXAMPLE4: &[u8] = b"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(EXAMPLE1), 5);
|
||||
assert_eq!(part1(EXAMPLE2), 6);
|
||||
assert_eq!(part1(EXAMPLE3), 10);
|
||||
assert_eq!(part1(EXAMPLE4), 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn part2_example() {
|
||||
assert_eq!(part2(EXAMPLE1), 23);
|
||||
assert_eq!(part2(EXAMPLE2), 23);
|
||||
assert_eq!(part2(EXAMPLE3), 29);
|
||||
assert_eq!(part2(EXAMPLE4), 26);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use itertools::Itertools;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DirEntry {
|
||||
Directory,
|
||||
File(u64),
|
||||
}
|
||||
|
||||
type Filesystem = HashMap<String, HashMap<String, DirEntry>>;
|
||||
|
||||
fn new_cwd(old_cwd: &str, target: &str) -> String {
|
||||
match target {
|
||||
"/" => "/".to_owned(),
|
||||
".." => {
|
||||
let mut tokens = old_cwd.split('/').collect_vec();
|
||||
tokens.pop();
|
||||
tokens.pop();
|
||||
tokens.join("/") + "/"
|
||||
}
|
||||
s => old_cwd.to_owned() + s + "/",
|
||||
}
|
||||
}
|
||||
|
||||
fn dir_usage(fs: &Filesystem, path: &str) -> u64 {
|
||||
fs.iter()
|
||||
.filter(|(k, _v)| k.starts_with(path))
|
||||
.map(|(_k, v)| {
|
||||
v.values()
|
||||
.map(|v| match v {
|
||||
DirEntry::File(n) => *n,
|
||||
_ => 0,
|
||||
})
|
||||
.sum::<u64>()
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[aoc_generator(day7)]
|
||||
fn parse(input: &str) -> Filesystem {
|
||||
let mut cwd = "/".to_owned();
|
||||
let mut fs = Filesystem::new();
|
||||
let mut lines = input.lines();
|
||||
|
||||
while let Some(line) = lines.next() {
|
||||
let tokens = line.split_ascii_whitespace().collect_vec();
|
||||
if tokens[0] == "$" {
|
||||
// command
|
||||
match tokens[1] {
|
||||
"cd" => {
|
||||
cwd = new_cwd(&cwd, tokens[2]);
|
||||
fs.entry(cwd.to_owned()).or_insert(HashMap::new());
|
||||
}
|
||||
"ls" => {}
|
||||
s => {
|
||||
panic!("invalid command `{s}`")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// file entry
|
||||
if let Ok(size) = tokens[0].parse() {
|
||||
fs.entry(cwd.to_owned()).and_modify(|e| {
|
||||
e.insert(tokens[1].into(), DirEntry::File(size));
|
||||
});
|
||||
}
|
||||
// dir entry
|
||||
else {
|
||||
fs.entry(cwd.to_owned() + tokens[1] + "/").or_insert(HashMap::new());
|
||||
fs.entry(cwd.to_owned()).and_modify(|e| {
|
||||
e.insert(tokens[1].into(), DirEntry::Directory);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs
|
||||
}
|
||||
|
||||
const AVAIL_DISK: u64 = 70000000;
|
||||
const MIN_FREE: u64 = 30000000;
|
||||
|
||||
#[aoc(day7, part1)]
|
||||
fn part1(fs: &Filesystem) -> u64 {
|
||||
fs.keys()
|
||||
.map(|path| dir_usage(&fs, path))
|
||||
.filter(|v| *v <= 100000)
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[aoc(day7, part2)]
|
||||
fn part2(fs: &Filesystem) -> u64 {
|
||||
let mut usages = fs.keys().map(|path| dir_usage(&fs, path)).sorted().collect_vec();
|
||||
|
||||
let total_usage = usages.pop().unwrap(); // sorted list, largest dir will always be the root which can't be deleted
|
||||
let need_to_free_at_least = MIN_FREE - (AVAIL_DISK - total_usage);
|
||||
|
||||
*usages.iter().find(|s| **s >= need_to_free_at_least).unwrap()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const EXAMPLE: &str = "$ cd /
|
||||
$ ls
|
||||
dir a
|
||||
14848514 b.txt
|
||||
8504156 c.dat
|
||||
dir d
|
||||
$ cd a
|
||||
$ ls
|
||||
dir e
|
||||
29116 f
|
||||
2557 g
|
||||
62596 h.lst
|
||||
$ cd e
|
||||
$ ls
|
||||
584 i
|
||||
$ cd ..
|
||||
$ cd ..
|
||||
$ cd d
|
||||
$ ls
|
||||
4060174 j
|
||||
8033020 d.log
|
||||
5626152 d.ext
|
||||
7214296 k";
|
||||
|
||||
#[test]
|
||||
fn part1_example() {
|
||||
assert_eq!(part1(&parse(EXAMPLE)), 95437);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn part2_example() {
|
||||
assert_eq!(part2(&parse(EXAMPLE)), 24933642);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
mod day5;
|
||||
mod day7;
|
||||
mod day4;
|
||||
mod day1;
|
||||
mod day2;
|
||||
mod day3;
|
||||
use aoc_runner_derive::aoc_lib;
|
||||
|
||||
mod day6;
|
||||
|
||||
aoc_lib! { year = 2022 }
|
||||
@@ -0,0 +1,3 @@
|
||||
use aoc_runner_derive::aoc_main;
|
||||
|
||||
aoc_main! { lib = aoc2022 }
|
||||