From 9caad95da239473f4e4014feabb3f82d909e5961 Mon Sep 17 00:00:00 2001 From: TuDatTr Date: Thu, 1 Dec 2022 22:17:40 +0100 Subject: [PATCH] Added solution for AoC 2022/1 Signed-off-by: TuDatTr --- .gitignore | 1 + 2022/day-1_calorie_counting/.gitignore | 1 + 2022/day-1_calorie_counting/Cargo.lock | 493 ++++ 2022/day-1_calorie_counting/Cargo.toml | 16 +- 2022/day-1_calorie_counting/input/input.txt | 2252 +++++++++++++++++++ 2022/day-1_calorie_counting/src/bin.rs | 46 + 2022/day-1_calorie_counting/src/cli.rs | 10 + 2022/day-1_calorie_counting/src/lib.rs | 91 + 2022/day-1_calorie_counting/src/main.rs | 3 - README.md | 7 +- create_readme.sh | 3 + 11 files changed, 2914 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 2022/day-1_calorie_counting/.gitignore create mode 100644 2022/day-1_calorie_counting/Cargo.lock create mode 100644 2022/day-1_calorie_counting/input/input.txt create mode 100644 2022/day-1_calorie_counting/src/bin.rs create mode 100644 2022/day-1_calorie_counting/src/cli.rs create mode 100644 2022/day-1_calorie_counting/src/lib.rs delete mode 100644 2022/day-1_calorie_counting/src/main.rs create mode 100755 create_readme.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/2022/day-1_calorie_counting/.gitignore b/2022/day-1_calorie_counting/.gitignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/2022/day-1_calorie_counting/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/2022/day-1_calorie_counting/Cargo.lock b/2022/day-1_calorie_counting/Cargo.lock new file mode 100644 index 0000000..3e363c8 --- /dev/null +++ b/2022/day-1_calorie_counting/Cargo.lock @@ -0,0 +1,493 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cc" +version = "1.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d" +dependencies = [ + "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "day-1_calorie_counting" +version = "0.1.0" +dependencies = [ + "clap", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "linux-raw-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustix" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb93e85278e08bb5788653183213d3a60fc242b10cb9be96586f5a73dcb67c23" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[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.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/2022/day-1_calorie_counting/Cargo.toml b/2022/day-1_calorie_counting/Cargo.toml index 7aba72f..437b449 100644 --- a/2022/day-1_calorie_counting/Cargo.toml +++ b/2022/day-1_calorie_counting/Cargo.toml @@ -3,6 +3,20 @@ name = "day-1_calorie_counting" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.release] +lto = true +codegen-units = 1 +debug = 1 + +[lib] +name = "calorie_counting_lib" +path = "src/lib.rs" + +[[bin]] +name = "calorie_counting_bin" +path = "src/bin.rs" [dependencies] +clap = {version = "4.0.22", features = ["derive"]} +tracing = "0.1" +tracing-subscriber = {version = "0.3.16", features = ["env-filter"]} \ No newline at end of file diff --git a/2022/day-1_calorie_counting/input/input.txt b/2022/day-1_calorie_counting/input/input.txt new file mode 100644 index 0000000..46bf59e --- /dev/null +++ b/2022/day-1_calorie_counting/input/input.txt @@ -0,0 +1,2252 @@ +6529 +8085 +4534 +1503 +2983 +5030 +2135 +5866 +5092 +5059 +1232 + +15219 +7137 +2691 +2898 +1798 + +4495 +2146 +3114 +5971 +2023 +2326 +6386 +4454 +2632 +3077 +2878 +2850 + +8347 +4368 +2646 +3785 +8383 +1847 +10738 +4345 + +1561 +5338 +3783 +4897 +3623 +6192 +2419 +6170 +1459 +1708 +4129 +4703 +3723 +5623 + +4684 +4823 +1065 +2276 + +5594 +2941 +3455 +3358 +4167 +4799 +3685 +3151 +3152 +1653 +5886 +5390 +1322 + +5305 +3665 +1763 +3359 +1851 +2194 +7262 +5151 +6598 +6326 +3639 + +7665 +4909 +5829 +6440 +7734 +7955 +5366 +8355 +3715 +5227 + +13214 +14041 +16730 +5522 + +1594 +5656 +2728 +5500 +7330 +7734 +7427 +3196 +1523 +1596 + +4125 +5353 +6549 +6118 +1294 +1272 +7007 +5572 +4896 +3169 +7709 + +1252 +9688 +2823 +7172 +8492 +4208 +1800 +5715 +3152 + +3186 +12541 +19573 + +11484 +8691 +11020 +2916 +1963 +12731 + +1451 +14095 +6033 +8075 +10327 + +5059 +1674 +5504 +5870 +6537 +3352 +7099 +5695 + +1238 +6348 +3080 +2109 +8335 +5178 +5324 +8800 +6917 + +5791 +2597 +4437 +4446 +2491 +5246 +5065 +2294 +1523 +2427 +5077 +3624 + +29241 +1823 + +4907 +4748 +4849 +5602 +1965 +1184 +2380 +3794 +4338 +1647 +5942 +2999 +4634 +1627 +5374 + +3929 +3291 +4898 +6074 +5349 +3256 +5042 +4300 +2866 +1660 +5942 +4029 +3301 +4653 + +6239 +3830 +1773 +4081 +1078 +6356 +1570 +5862 +3328 +5806 +4974 +6552 +2162 + +62947 + +11189 +2609 +1987 +6087 +7704 + +6355 +15744 +4331 +14437 + +10677 +3241 +7979 +3643 +1131 +7711 +2069 +3945 + +5626 +7282 +10610 +5553 +9387 +2196 +6064 +8325 + +2376 +5418 +5256 +2834 +5146 +1356 +5956 +3389 +2357 +3216 +1988 +1264 +2620 +1334 +4345 + +3774 +4300 +5766 +8511 +1535 +1431 +4666 +2073 +8279 +6881 + +4788 +6221 +3354 +2403 +9211 +1869 + +6052 +6845 +1214 +3467 +2008 +1129 +4537 +1810 +4805 +2752 +1294 +3764 + +5326 +2255 +6754 +3961 +2481 +3493 +1696 +5639 +8564 +5161 + +4773 +1683 +3104 +6495 +6879 +1932 +1894 +4526 +5013 +3114 +3956 +2401 +1211 + +10777 + +4328 +1321 +3656 +4368 +3932 +5701 +4040 +1146 +6344 +2406 +6461 +6133 +5276 +1058 + +10525 +2492 +1508 +7667 +3349 +4659 +8078 +9070 + +6095 +6001 +9615 +11546 +9401 +1185 +9038 + +7528 +3118 +12935 +13110 +1345 + +5863 +3750 +1911 +1501 +3564 +5163 +5684 +1544 +1535 +1009 +3071 +4870 +2717 + +10390 +1714 +12404 +3155 +5534 + +5965 +8382 +1849 +1844 +7654 +9554 +3685 +6535 + +3281 +7001 +4418 +1128 +7339 +5821 +7149 +2368 +2086 +7218 +5802 +5233 + +9320 + +1200 +7288 +8100 +8743 +5675 +4827 +3289 +2862 +8348 + +16472 +18172 +16411 +16413 + +7073 +1820 +8120 +7426 +6211 +1610 +5391 +7900 + +4090 +4417 +5467 +5302 +4528 +3809 +4313 +1853 +3770 +3602 +6049 +3511 +5848 +2778 +3514 + +3874 +5419 +2536 +6061 +5871 +3103 +4837 +2054 +2506 +2473 +3696 +1648 +2932 +1520 +5730 + +69921 + +8742 +8516 +14482 +12871 +8146 + +5021 +1804 +1718 +2605 +4966 +5385 +2086 +5648 +3237 +5928 +5856 +3234 +2297 +4183 + +3940 +3186 +1121 +5004 +9081 +8588 +7769 +2550 + +7876 +8684 +4238 +6074 +9447 +1273 +4027 +8267 +2911 + +1478 +4303 +6935 +3396 +2043 +3050 +1902 +4931 +3412 +3110 +2572 +2105 +6598 + +2899 +2696 +2432 +1589 +5805 +5805 +4449 +5500 +2118 +3318 +2042 +4366 +1067 +3348 +3660 + +7248 +3934 +6003 +4893 +8136 +10163 + +18757 +22220 +5027 + +3657 +8529 +2498 +2381 +3308 +3133 +6646 +1892 +7461 + +49084 + +46725 + +2961 +5118 +4034 +2690 +5181 +5797 +5978 +1013 +6579 +7485 + +17005 +16457 + +6120 +5668 +6006 +3880 +1494 +6090 +5394 +3980 +1051 +1125 +1411 +4546 +1840 + +28701 + +6038 +7823 +3235 +7303 +3904 +2572 +1478 +8661 +2921 +1287 + +1387 +2751 +4748 +2307 +2675 +2168 +5663 +7359 +7753 +3952 +3101 + +11736 +4778 +1596 + +3065 +3481 +1775 +2516 +2214 +4046 +5415 +4580 +4221 +4566 +6724 +6870 +5590 + +3348 +3348 +5112 +4493 +3259 +2540 +2407 +4276 +3328 +4447 +1123 +3431 +5191 +5144 +3374 + +38950 + +6208 +3976 +5557 +5338 +3420 +4221 +6829 +6686 +6516 +2024 +1675 +4972 + +5491 +3707 +7833 +5247 +7155 + +1246 +9839 +1590 +7833 +8812 +4296 + +3305 +4483 +4617 +3308 +3851 +5978 +4419 +4527 +4789 +3590 +6406 +1741 +5882 +5743 + +25321 +32917 + +3654 +3962 +5489 +6090 +1643 +5186 +3220 +6542 +5029 +3857 +3746 + +5243 +12859 +6728 +19483 + +15385 +17342 + +7771 +5721 +3603 +3661 +3682 +6139 +2645 +1725 +7200 +8120 + +11232 +6787 +9618 +11104 +8613 +5183 +3189 + +25964 +23122 +11479 + +6572 +6512 +5407 +2640 +6992 +1730 +7317 +2995 +1435 +5295 +5741 + +1647 +12453 +11893 +18188 + +10366 +3241 +9612 +2966 +6200 +1073 +9429 +8688 + +4080 +4133 +9987 +4345 +4526 +1076 +10504 + +1424 +9981 +5575 +2334 +1554 +6135 +4184 +4241 + +15678 +13808 +12505 +14449 +16278 + +14461 +4481 + +4720 +8418 +6511 +8148 +6346 +6025 +6794 +7252 +3811 +1189 + +6209 +5901 +1677 +3047 +8828 +3745 +7073 +5612 +3005 + +6455 +2873 +6972 +6296 +6960 +4124 +4382 +1269 +2683 +4131 +4768 + +9877 +8415 +17318 +7294 + +7595 +4689 +1674 +1215 +1887 +2247 +7359 +4295 +5184 +4274 +3674 + +2440 +2559 +4609 +3775 +4553 +3364 +1084 +5611 +1463 +2196 +2027 +2054 +2010 +1269 +4411 + +3384 +3054 +4987 +3713 +5142 +5343 +5043 +2738 +3549 +6059 + +4822 +9613 +1653 +1112 +1470 +5641 +7374 +4129 + +25877 +4799 +8409 + +4926 +2883 +2384 +2806 +3819 +4187 +2162 +2670 +3604 +1060 +2671 +2978 +2791 +3216 +6055 + +37492 + +5945 +5609 +5071 +6765 +7648 +3932 +7251 +5630 +7043 +1675 +5676 + +3852 +15773 +9032 +11524 + +5487 +3806 +6971 +2135 +4971 +5629 +3195 +1693 +1041 +3837 +1478 +1063 + +3291 +3252 +5375 +2706 +4367 +3229 +5712 +4769 +2743 +3576 +5938 +4705 +5276 +3964 + +13470 +1497 +13303 +2923 +11201 + +1514 +4869 +2929 +4167 +1065 +2915 +5472 +1344 +2236 +4734 +2487 + +6568 +5764 +1760 +1988 +1842 +2124 +4665 +4653 +5020 +2928 +4274 +4508 +1549 + +4844 +2544 +2022 +4723 +1450 +4579 +1410 +4474 +4762 +5963 +1299 +4196 +5663 +5894 +3438 + +2910 +3538 +7573 +4233 +6030 +7195 +4073 +4317 +5065 +5512 +6284 + +1090 +4494 +4085 +3378 +2631 +3533 +1667 +2167 +1840 +1750 +1209 +4066 +4965 +3571 +4156 + +3540 +5820 +4389 +7232 +4366 +6384 +1106 +4408 +8053 +1266 + +13848 +2160 +13791 +14041 +11152 + +4299 +2211 +3798 +9867 +13325 +5998 + +6292 +5641 +4698 +5604 +4022 +2314 +2876 +6889 +6322 +5038 +5623 +2943 +3426 + +5374 +2158 +13022 +4657 +8483 +3112 + +5337 +3564 +3978 +4692 +6418 +5877 +2936 +1534 +5147 +5403 +4000 +3786 +2723 +2665 + +2243 +4517 +6021 +3948 +4251 +3157 +3985 +4325 +6779 +4205 +6417 +2664 + +2547 +5363 +3277 +1601 +3498 +3581 +1882 +2294 +7464 +2203 +1440 +2119 + +56540 + +4114 +6633 +7409 +2081 +3364 +2428 +5812 +6104 +3459 +1216 +4749 + +9792 + +5672 +5220 +2217 +5072 +4068 +2214 +7023 +6975 +4430 +5375 +4351 +3875 + +6394 +3166 +4308 +3760 +2712 +2207 +4830 +6165 +4717 +4483 +4568 +6496 +4028 + +1113 +2766 +5360 +5590 +3535 +4420 +2554 +2339 +2905 +5054 +2954 +2953 +5128 +5970 +5064 + +4688 +17010 +7287 + +25959 +16973 + +6698 +7478 +6731 +1324 +7721 +7731 +3471 +1071 +4544 +2879 +6244 + +5335 +2716 +3073 +6624 +3710 +2488 +6201 +3117 + +3446 +1221 +8736 +9519 +8604 +9563 +6241 +1964 +8546 + +1950 +2550 +4261 +10511 +9023 +9729 +8882 + +3380 +3474 +2462 +5721 +5728 +8104 +5746 +8395 +3078 + +24787 +21907 +9130 + +4487 +3463 +4453 +5325 +4555 +5709 +1424 +3149 +3695 +4030 +2529 +5465 +2544 +2147 +5561 + +29311 +13793 + +65354 + +1094 +2132 +2019 +5234 +3514 +1873 +4363 +1395 +6290 +1685 +4297 + +6240 +3902 +3457 +7592 +4596 +5988 +4647 +2331 +3409 +3818 +3156 + +12669 +4058 +14475 +1124 + +19249 +28191 + +11176 +4240 +5949 +15876 +13090 + +5812 +1314 +6397 +2303 +2371 +2955 +2624 +3035 +6322 +2288 +5643 +6326 +2157 + +4073 +10747 +12263 +6031 +13390 + +9228 +8451 +16266 +9348 +6395 + +24990 +12527 +17026 + +14534 +19849 +14849 +6185 + +6427 +1995 +4227 +6946 +6345 +3284 +1982 +6415 +5996 +4840 +1657 +1324 + +20567 +16054 +3294 + +6989 +1535 +7128 +6653 +7060 +4023 +4041 +7119 +6428 +5189 +1968 +5184 + +8986 +28335 + +3739 +5164 +3972 +4791 +4171 +1276 +4546 +5024 +6224 +3280 +3118 +2283 +2591 + +66586 + +4747 +31552 + +6575 +6202 +7744 +8298 +8022 +1574 +7635 +7135 +2227 + +18465 +5912 + +5659 +2780 +2678 +6838 +1102 +2615 +5060 +3681 +1710 +1618 +5997 +5730 +6887 + +10009 +8637 +10267 +11737 + +7843 +3135 +3618 +2453 +2112 +3075 +4248 +3881 +1662 +3737 +5143 + +2093 +3199 +4806 +6406 +5864 +7205 +5964 +7831 +7954 +7029 +7384 + +2560 +2823 + +1529 +7467 +2912 +2857 +2505 +6923 +7118 +7203 +4146 +3657 +5065 +6754 + +7142 +3048 +3386 +7443 +4071 +4173 +4400 +2863 +1656 +5693 +5895 +2526 + +8654 +7439 +8871 +2786 +2597 +6301 +1233 +5254 + +5900 +1116 +3219 +1281 +2023 +1395 +4355 +1368 +5337 +3611 +4007 +5670 +2416 +5050 +4930 + +6085 +1021 +2072 +5284 +4538 +4496 +1483 +2386 +5955 +4557 +6548 +3776 + +3093 +2877 +17823 +18819 + +10160 +8582 +8538 +6647 +7614 +3570 + +43301 + +10538 +2596 +8339 +7342 +9710 +9051 +7271 +2822 + +6264 +6544 +1150 +6224 +5472 +5747 +3405 +1962 +5948 + +13398 +16778 +15554 +2173 + +4616 +2528 +1631 +11988 +3788 +9095 +11021 + +19193 + +24816 + +2335 +2232 +4247 +5104 +2085 +4732 +1646 +2689 +5182 +1949 +1030 +4538 +5628 +4298 +2006 + +6145 +5453 +6567 +5254 +3538 +4106 +3076 +6080 +2023 +3233 +6706 +2530 +3569 + +3644 +13707 +11721 +12291 +1798 +9214 + +3227 +4812 +1364 +4183 +2462 +1384 +4649 +2010 +2771 +2114 +2284 +6032 +5376 +5773 + +7091 +11367 +11050 +1177 +1698 +7646 +9085 + +2697 +2541 +4898 +6708 +1349 +4640 +8273 +2063 +6007 +3683 + +61753 + +3993 +7000 +6769 +7454 +2998 +7523 +3069 +6862 +1382 + +55910 + +14386 +24790 + +8219 +2081 +4611 +11785 +5734 +12051 + +6648 +3217 +3406 +2725 +1770 +1991 +4649 +5939 +3057 +4673 +1986 +6766 +3955 + +4409 +3015 +2068 +4331 +8752 +6399 +1043 +2111 + +3826 +6028 +5083 +6987 +3181 +6147 +6074 +5237 +2423 +2037 +6353 +7104 + +4766 +3207 +7062 +5163 +4673 +7121 +3374 +4113 +1090 +6951 +6919 + +2848 +5358 +2402 +2485 +1366 +2620 +3930 +4174 +2767 +3336 +6871 + +1834 +3257 +6061 +3107 +3054 +1442 +3560 +2815 +4979 +1496 +1610 +2670 +2365 +4488 +1991 + +4995 +4348 +4425 +4765 +3891 +4132 +2565 +6416 +1284 +2608 +3027 +1474 +4237 + +5231 +1041 +2430 +3795 +3356 +3607 +1285 +4566 +3637 +1036 +3375 +3999 +5275 +1731 + +4505 +3079 +5583 +3314 +5962 +6709 +6080 +4266 +4252 +4665 +2331 +1835 +6744 + +4674 +6194 +1155 +3895 +4736 +5553 +2237 +2628 +4887 +2705 +3890 +1629 +1474 +3686 + +1217 +5258 +2210 +2151 +3012 +6117 +2261 +5054 +3062 +1365 +4633 +3810 +4117 +2223 + +4301 +4875 +9069 +3312 +1382 +9454 + +5405 +1117 +2206 +4622 +5346 +1066 +5791 +4496 +5785 +4172 +4220 +6302 +4667 +6162 + +7211 +15334 + +10114 +9964 +4173 +9143 +10306 +9238 +9310 +8202 + +5579 +9087 +6909 +4321 +10075 +7365 +4559 +2390 + +6853 +8713 +7697 +7839 +5738 +7412 +6935 +7112 +1731 +6992 + +2680 +1464 +8710 +14949 +11441 + +20388 +10859 + +3378 +10073 +10939 +4344 +10261 +7987 + +3809 +6653 +7000 +3264 +3039 +4211 +2910 +6677 +2070 +2591 +6428 + +5067 +4573 +5452 +4266 +4586 +3038 +2181 +3103 +2256 +4213 +3972 +4232 +3116 +6089 + +16022 +14856 +13679 +9065 +15471 + +3920 +1084 +4979 +3939 +1770 +3703 +1152 +4529 +5107 +2015 +2219 +5927 +1278 +5955 +1089 + +4397 +3826 +4466 +5239 +4252 +5282 +4799 +1304 +2415 +2410 +2274 +5387 +1988 +2832 +6045 + +4378 +6750 +10740 +13078 +3530 +4127 + +49692 + +2066 +18338 +2268 +5102 + +14892 +9200 +7896 +2929 +15232 + +19812 +32572 + +9976 +2611 +13203 +5570 +11153 +5662 + +36870 +32349 + +4706 +5222 +6886 +6591 +2468 +7409 +3359 +2406 +3148 +4911 +1916 + +6467 +1320 +4005 +6343 +3878 +4489 +9372 +3094 +7544 + +3947 +1050 +3981 +4744 +3554 +4837 +4250 +2043 +1835 +1241 +3644 +4384 +3020 +5362 +1526 + +7284 +2864 +5799 +1178 +3401 +5905 +5165 +4614 +4444 +6816 +7764 + +16810 +8023 + +3539 +3058 +4349 +1681 +6743 +6362 +4657 +1784 +6327 +6208 +5791 +3005 +4895 + +5594 +6187 +3228 +9350 +7580 +7880 +7025 +7708 +6845 + +17364 +21708 +18029 + +1319 +5649 +4974 +1020 +5994 +3808 +6597 +2955 +1286 +2611 +7171 +7455 + +4698 +4359 +6493 +10361 +2469 +8957 +6003 +2315 + +5640 +1645 +5958 +5900 +5252 +5635 +5109 +6010 +2800 +4106 +5045 +2142 +3958 + +12044 +2521 +5040 +2492 +1303 + +13259 +9994 +11909 +1837 +9723 +3576 + +8880 +10106 +6982 +2660 +10392 +11186 +3976 + +7019 +4976 +3671 +5070 +7475 +5928 +2449 +2493 +3296 +3670 + +15028 +9325 +2762 +10082 +8250 + +10739 +1473 +16919 + +8508 +13859 +4973 +1578 + +25794 +18161 +19633 + +8105 +6980 +1013 + +3074 +2012 +1626 +1572 +2784 +6136 +4692 +2653 +6144 +1875 +4248 +6430 +1381 +2853 + +10687 +5423 +1011 +3092 +4127 + +8642 +5106 +9038 +2188 +9360 +4232 +4993 +1949 +5812 + +2143 +1039 +6975 +9893 +2685 +10361 + +1737 +2651 +1248 +8953 +5328 +7754 +7213 +6237 +6923 + +10310 +4157 +10056 +5610 +6765 +8579 +2518 +10263 + +8314 +3395 +6408 +1446 +8922 +2433 +6172 +7375 +2360 + +6246 +3401 +4016 +4599 +6351 +6958 +4174 +2707 +2812 +3225 +2887 +4995 +5737 + +2232 +14703 +10506 + +10622 +12187 +7851 +1543 +11457 + +11456 +9663 +9068 +6380 +5945 + +6881 +1977 +10997 +8110 +11591 +7071 +8285 + +8164 +2663 +8024 +9441 +5027 +9077 +6889 +7045 +8717 + diff --git a/2022/day-1_calorie_counting/src/bin.rs b/2022/day-1_calorie_counting/src/bin.rs new file mode 100644 index 0000000..3b70522 --- /dev/null +++ b/2022/day-1_calorie_counting/src/bin.rs @@ -0,0 +1,46 @@ +use calorie_counting_lib::*; +use std::path::PathBuf; +use std::collections::BinaryHeap; +use clap::Parser; +use tracing::{info, debug}; +use crate::cli::Cli; + +mod cli; + +/// Finds the Elf carrying the most Calories. +/// Outputs how many total Calories that Elf is carrying. +fn task_1a(input: &PathBuf) { + debug!("Running task 1a"); + let file_path = input; + let content = calorie_counting_lib::read_file(file_path).unwrap(); + let splits = content.split("\n\n"); + + println!("{}", splits.map(|s| Elf::new(s).total_calories()).max().unwrap()); +} + +/// Finds the top three Elves carrying the most Calories. +/// Outputs how many Calories those Elves are carrying in total. +fn task_1b(input: &PathBuf) { + debug!("Running task 1b"); + let file_path = input; + let content = calorie_counting_lib::read_file(file_path).unwrap(); + let splits = content.split("\n\n"); + let mut heap = splits.map(|s| Elf::new(s).total_calories()).collect::>(); + + let mut top_three = Vec::new(); + for _ in 0..3 { + if let Some(c) = heap.pop() { + top_three.push(c); + } + } + println!("{}", top_three.iter().sum::()); +} + +pub fn main() { + tracing_subscriber::fmt::init(); + debug!("Running with debugging level logging"); + + let args = Cli::parse(); + task_1a(&args.input); + task_1b(&args.input); +} diff --git a/2022/day-1_calorie_counting/src/cli.rs b/2022/day-1_calorie_counting/src/cli.rs new file mode 100644 index 0000000..78647a6 --- /dev/null +++ b/2022/day-1_calorie_counting/src/cli.rs @@ -0,0 +1,10 @@ +use clap::Parser; +use std::path::PathBuf; + +#[derive(Parser, Debug)] +#[command(author, version, about="CLI tool to output latency at a given gps location.", long_about = None)] +pub struct Cli { + /// Path to the input file. + #[arg(short, long)] + pub input: PathBuf, +} diff --git a/2022/day-1_calorie_counting/src/lib.rs b/2022/day-1_calorie_counting/src/lib.rs new file mode 100644 index 0000000..b540a04 --- /dev/null +++ b/2022/day-1_calorie_counting/src/lib.rs @@ -0,0 +1,91 @@ +use std::fs::File; +use std::io::{Write, Read}; +use std::path::Path; +use std::fmt; +use tracing::{info, debug}; + +pub fn create_file(path: &Path, content: String) { + debug!("Creating file"); + let mut file = File::create(path).unwrap(); + let _ = file.write_all(content.as_bytes()); +} + +pub fn read_file(path: &Path) -> std::io::Result { + debug!("Reading file"); + let mut file = File::open(path)?; + let mut contents = String::new(); + let _ = file.read_to_string(&mut contents)?; + Ok(contents.trim().to_string()) +} + +#[derive(Debug, Clone)] +pub struct Elf { + _input: String, + calories: Vec, +} + +impl Elf { + pub fn new (input: &str) -> Self { + let cal: Vec = input.split('\n') + .map(|i| i.parse::().unwrap()) + .collect(); + Self { _input: input.to_string(), calories: cal } + } + + pub fn total_calories(self) -> u64 { + self.calories.iter().sum() + } +} + +impl fmt::Display for Elf{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Elf: {:?}", self.calories) + } +} + +// pub fn get_calories() -> std::io::Result> { +// let content = read_file(Path::new("input.txt"))?; +// } + +#[cfg(test)] +mod tests { + use super::*; + use std::fs::remove_file; + use std::str::from_utf8; + + const PATH: &str = "input.txt"; + const CONTENT: &[u8; 55] = b"1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000\n"; + + fn create_test_setup() { + let file_path = Path::new(PATH); + let original = CONTENT; + create_file(file_path, from_utf8(original).unwrap().to_string()); + } + + fn cleanup_test_setup() { + let _ = remove_file(&Path::new(PATH)); + } + /// Test if we corretly read file input. + #[test] + fn file_io() { + create_test_setup(); + let content = read_file(&Path::new(PATH)); + cleanup_test_setup(); + assert_eq!(from_utf8(CONTENT).unwrap(), content.unwrap().to_string()); + } + + /// Test if the calculation of calories each elf is carrying is correct. + #[test] + fn elf_calories() { + create_test_setup(); + let content = read_file(&Path::new(PATH)).unwrap(); + let file_path = Path::new("input.txt"); + let content = calorie_counting_lib::read_file(file_path).unwrap(); + let splits = content.split("\n\n"); + let result_vec = Vec::::new(); + for elf in splits.map(|s| Elf::new(s)) { + result_vec.push(elf.total_calories()); + } + cleanup_test_setup(); + } +} diff --git a/2022/day-1_calorie_counting/src/main.rs b/2022/day-1_calorie_counting/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/2022/day-1_calorie_counting/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/README.md b/README.md index 536cd36..1b8c744 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ -# Advent of Code - +#Advent of Code ``` . ├── 2022 │   └── day-1_calorie_counting -│   ├── Cargo.toml -│   └── src -│   └── main.rs +├── create_readme.sh └── README.md ``` diff --git a/create_readme.sh b/create_readme.sh new file mode 100755 index 0000000..248cde0 --- /dev/null +++ b/create_readme.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo -e "#Advent of Code\n\`\`\`\n$(tree -L 2|head -n -1)\n\`\`\`" > README.md