From f3f3b40d477fd3c6cfe8899ad520efb685e3e5b4 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 5 Dec 2022 22:57:19 +0100 Subject: [PATCH 1/5] 2022: day 01 part 1 --- Cargo.lock | 16 + Cargo.toml | 2 +- aoc2022/Cargo.toml | 18 + aoc2022/aoc2022_bench/Cargo.toml | 17 + .../aoc2022_bench/benches/aoc2022_bench.rs | 14 + aoc2022/input/day01.txt | 2253 +++++++++++++++++ aoc2022/input/day01_provided.txt | 14 + aoc2022/src/day01.rs | 63 + aoc2022/src/lib.rs | 3 + aoc2022/src/main.rs | 11 + flake.lock | 8 +- flake.nix | 2 +- 12 files changed, 2415 insertions(+), 6 deletions(-) create mode 100644 aoc2022/Cargo.toml create mode 100644 aoc2022/aoc2022_bench/Cargo.toml create mode 100644 aoc2022/aoc2022_bench/benches/aoc2022_bench.rs create mode 100644 aoc2022/input/day01.txt create mode 100644 aoc2022/input/day01_provided.txt create mode 100644 aoc2022/src/day01.rs create mode 100644 aoc2022/src/lib.rs create mode 100644 aoc2022/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 757f897..aa0f66e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,6 +100,22 @@ dependencies = [ "criterion", ] +[[package]] +name = "aoc2022" +version = "0.1.0" +dependencies = [ + "anyhow", + "aoc", +] + +[[package]] +name = "aoc2022_bench" +version = "0.1.0" +dependencies = [ + "aoc2022", + "criterion", +] + [[package]] name = "atty" version = "0.2.14" diff --git a/Cargo.toml b/Cargo.toml index 6604557..a228d23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] members = ["aoc20*", "aoc20*/aoc20*_bench"] -default-members = ["aoc2021"] +default-members = ["aoc2022"] [profile.release] debug = true diff --git a/aoc2022/Cargo.toml b/aoc2022/Cargo.toml new file mode 100644 index 0000000..9fe9672 --- /dev/null +++ b/aoc2022/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "aoc2022" +version = "0.1.0" +authors = ["Antoine Martin "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aoc = { path = "../aoc" } +anyhow = "1.0" + +[lib] +path = "src/lib.rs" + +[[bin]] +name = "aoc2022" +path = "src/main.rs" diff --git a/aoc2022/aoc2022_bench/Cargo.toml b/aoc2022/aoc2022_bench/Cargo.toml new file mode 100644 index 0000000..e5ef4bc --- /dev/null +++ b/aoc2022/aoc2022_bench/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "aoc2022_bench" +version = "0.1.0" +authors = ["Antoine Martin "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aoc2022 = { path = "../" } + +[dev-dependencies] +criterion = "0.3" + +[[bench]] +name = "aoc2022_bench" +harness = false diff --git a/aoc2022/aoc2022_bench/benches/aoc2022_bench.rs b/aoc2022/aoc2022_bench/benches/aoc2022_bench.rs new file mode 100644 index 0000000..618c7f5 --- /dev/null +++ b/aoc2022/aoc2022_bench/benches/aoc2022_bench.rs @@ -0,0 +1,14 @@ +use criterion::{criterion_group, criterion_main, Criterion}; + +use aoc2022::day01; + +fn aoc2022_all(c: &mut Criterion) { + c.bench_function("day01", |b| b.iter(|| day01::run().unwrap())); +} + +criterion_group! { + name = all_days; + config = Criterion::default().sample_size(200); + targets = aoc2022_all +} +criterion_main!(all_days); diff --git a/aoc2022/input/day01.txt b/aoc2022/input/day01.txt new file mode 100644 index 0000000..e1e0531 --- /dev/null +++ b/aoc2022/input/day01.txt @@ -0,0 +1,2253 @@ +4601 +1583 +2995 +5319 +3352 +1722 +4331 +5840 +3339 +5341 +3415 +1297 +1610 +2703 + +5928 +1266 +6405 +4354 +2815 +1621 +3545 +1733 +2162 +1155 +3674 +4055 +4262 +2115 + +25873 +16103 +17042 + +6479 +1521 +6902 +6331 +6146 +1591 +2063 +2149 +1463 +1865 +2598 +6893 +3617 + +1431 +8935 +8134 +8885 +8698 +8884 +7982 +3617 +7079 + +34031 +8383 + +3697 +1199 +3703 +1322 +5679 +1627 +5910 +1092 +6445 +2371 +3672 +2281 +2710 +5111 + +17480 + +58355 + +3711 +2406 +2101 +1406 +5376 +2149 +4608 +6768 +6322 +3792 +4249 +2342 +2014 + +6197 +6908 +8484 +3901 +3001 +7880 +5165 +2536 + +3964 +4229 +4898 +4544 +3535 +6329 +1573 +4988 +1424 + +57606 + +16325 + +6038 +11538 +13026 +12734 +6077 + +4696 +3914 +2375 +1188 +1247 +1594 +1843 +5297 +6053 +1114 +3179 +5968 +1430 +4268 +2514 + +6684 +2321 +3946 +1746 +7583 +10379 +3696 +10110 + +5834 +5944 +9336 +9638 +3373 +4279 +9942 + +7208 +7801 +3771 +8183 +1824 +8217 +1545 +3041 +7369 +5980 + +8368 +6180 +3100 +4801 +4430 +6758 +3023 +3394 + +2545 +4992 +3347 +5830 +3764 +3237 +2431 +3406 +1408 +5601 +6548 +4625 + +32334 + +1112 +5471 +10983 +8298 +4342 +4221 +7807 + +5733 +2012 +5928 +3503 +2785 +4867 +1515 +4819 +3569 +3353 +5997 +4921 +5498 +3234 +5588 + +11040 +5547 +12070 +2168 +7603 +7245 +4966 + +13027 +12518 +15381 +3251 +14935 + +15858 +29295 + +2476 +4289 +10350 +3953 +10089 +6953 +5555 +3007 + +61732 + +5567 +4895 +6095 +4880 +2945 +6022 +2129 +5010 +4100 +3554 +3410 +1820 + +9902 +33605 + +15331 +15615 +5062 +15073 + +5940 +2252 +1233 +2582 +3624 +2754 +2304 +3189 +4060 +3862 +5164 +1487 +2776 +1807 +3385 + +6798 +2385 +3755 +10299 +11500 +6478 +1911 + +1469 +9309 +1785 +17145 + +3363 +3210 +3285 +4491 +5992 +2927 +4098 +2133 +3191 +2810 +4694 + +31006 +1582 + +4356 +6146 +2051 +6503 +9487 +9244 +4808 +7761 +7108 + +1771 +6062 +7135 +5575 +3278 +1221 +2547 +7266 +5444 +7395 + +10634 +1196 + +1361 + +2810 +3106 +8654 +9455 +3778 +4219 +8882 +9387 +5128 + +7114 +1441 +6146 +4752 +2388 +6420 +7350 +1624 +6050 +5469 +6751 + +5570 +4674 + +2074 +3476 +4064 +9446 +2889 +4871 +6298 +2970 +8588 + +3482 +8492 +2226 +4951 +6733 +5463 +3183 +4807 +4806 + +6974 +10251 +4637 +9558 +5153 +4665 + +6860 +6949 +1524 +4201 +4397 +2278 +4909 +1353 +2074 +1920 +7439 +1040 + +4135 +1411 +5536 +8004 +3090 +1036 +6613 +6353 +6810 + +3932 +4743 +1615 +3201 +3791 +6357 +2511 +3440 +2290 +4741 +2844 +3121 +3641 +3497 + +4549 +5142 +4438 +2945 +4576 +4871 +4795 +6007 +4884 +1031 +2111 +4388 +4705 +5725 +3425 + +45444 + +6688 +9460 +2727 +6989 +6789 +12460 + +7310 +5910 +7822 +7627 +7600 +4793 +3152 +5747 +5197 +8006 + +23983 +33879 + +1020 +4783 +5117 +3628 +3065 +6131 +5543 +1576 +1159 +3721 +3182 +1409 +2738 +5084 + +42750 + +8509 +4370 +1042 +5664 + +59445 + +1589 +5133 +6413 +6578 +3301 +8256 +7749 +4321 +8190 +5025 + +27739 +18609 + +5447 +4022 +4069 +1437 +2811 +6929 +2754 +1108 +7390 +3995 +3480 +3225 + +4240 +6959 +3289 +8063 +4751 +4896 +4611 +6256 +1105 +1334 +7598 + +27831 + +1821 +5333 +7853 +6574 +7985 +3972 +2306 +1875 +1857 +6386 + +12780 +2513 +22939 + +9625 +3785 +8050 +7432 +11772 +10914 + +1387 +3439 +4644 +3880 +1878 +3911 +5329 +1480 +5779 +2083 +3886 +5525 +3930 +4813 +2570 + +15763 +2839 +14258 +1460 + +6193 +3397 +3222 +3262 +3735 +2406 +5588 +2068 +2862 +3271 +1401 +3957 +5690 +4632 + +15070 +5164 +8902 +9580 +4271 + +4494 +5665 +7242 +7687 +7031 +6135 +2670 +3315 +6146 +8085 + +2625 +24285 + +4414 +5985 +2681 +7036 +6486 +2501 +4408 +8582 +5150 +4295 + +1082 +1497 +5638 +4643 +1413 +5969 +1515 +4016 +4856 +3287 +3122 +2948 +3711 +5031 +4692 + +6445 +2261 +2132 +3517 +2461 +2767 +2071 +2176 +6357 +1304 +6034 +1346 + +1318 +4719 +2054 +1433 +6514 +3729 +4329 +1026 +1502 +2611 +1363 +6379 +3617 + +1885 +7519 +2849 +5167 +3136 +4819 +8018 +4110 +2666 +6098 +4943 + +6575 +1624 +6004 +4178 +7453 +5979 +6736 +3883 +7109 +1271 +1175 + +9494 +12633 +11576 +3547 + +4653 +6777 +4497 +2246 +4666 +4675 +4440 +7227 +3808 +2425 +6014 +7305 + +2538 +6155 +4321 +6239 +6279 +1445 +5592 + +4920 +5435 +1392 +4122 +10513 +6359 +1574 +7222 + +9013 +2150 +8377 +8884 +4108 +5427 +1605 +6907 + +7861 +10554 +1210 +1346 +5296 +4419 +9147 + +1858 +2956 +2070 +10271 +5810 +2632 +9429 +3941 + +4306 +4972 +6216 +6345 +3971 +3920 +6295 +3552 +1399 +5425 +5218 +4512 +3376 +4460 + +4107 +4484 +5148 +5456 +7902 +2185 +3439 +7199 +9514 + +11030 +12096 + +2886 +1561 +14057 +7480 +12186 + +8600 +4085 +11755 +4564 +1697 +6345 +10176 + +2538 +10138 +8328 +10621 +13322 +13907 + +5450 +3403 +5776 +5967 +3873 +2761 +5992 +2251 +2278 +4673 +3442 +2720 +2556 +4848 +5967 + +2806 +8228 +9047 +10630 +4367 +4917 +4084 +7893 + +2842 +18343 +1497 +19962 + +3985 +10986 +1431 +1569 +8053 +8987 +6474 + +5733 +2237 +6183 +1642 +1005 +4389 +1889 +2385 +2470 +6338 +2200 +3399 +3659 +4092 + +6579 +5872 +4229 +1081 +2254 +1229 +5218 +4267 +6906 +2818 +1084 +3655 +2294 + +1882 +5005 +3805 +2088 +6809 +4982 +1935 +6789 +1961 +1842 +5988 +2859 +3965 + +2313 +1021 +5090 +1309 +5110 +3142 +4102 +2919 +6010 +3079 +5786 +3701 +2659 +5728 + +4251 +1899 +4119 +8941 +6677 +2161 +2119 +2772 +3122 + +7821 +6113 +5150 +3486 +2072 +4089 +2820 +3161 +7589 +1787 +5988 + +10582 +8240 +1934 +1504 +9070 +1186 +7766 +1066 + +6700 +6181 +3238 +1940 +1229 +3688 +1375 +5873 +2328 +6384 +7446 +7246 + +5542 +6771 +1964 +4532 +3011 +2300 +1451 +6726 +4595 +2926 +5237 +5020 +6129 + +15008 +4409 +6769 +2211 + +11825 +8947 +17411 +2893 + +8460 +11664 +2304 +6865 +2132 +9174 + +15540 +16925 +12015 +7621 + +1439 +11886 +3028 + +4604 +1057 +5342 +4723 +7773 +3373 +7488 +8028 +3246 +6355 +1939 + +2921 +4447 +3472 +5175 +5909 +5936 +5263 +3993 +1589 +3906 +4865 +3156 +2010 + +10089 + +5964 +7650 +4692 +1537 +3281 +3162 +1064 +4567 +3910 +2229 +3566 + +15533 +17311 +11818 +6179 + +4583 +4577 +3573 +1379 +3761 +1048 +4799 +4275 +3515 +5637 +5435 +3801 +5933 +1926 + +11841 +16030 +3213 + +4307 +7300 +1237 +5513 +6799 +2402 +2554 + +67023 + +1573 +6798 +3002 +7536 +2373 +5994 +10122 + +1149 +1836 +7129 +6621 +7432 +2468 +4028 +6560 +5127 +3781 +7035 +5845 + +13729 +10212 +10942 +10087 +10080 +6493 + +6850 +5969 +3370 +5400 +6433 +4762 +5702 +6193 +1836 +1507 +2637 +3051 +1394 + +5465 +10565 +4923 +1671 +9789 +9150 +6466 +8013 + +31283 + +2001 +6032 +6765 +3896 +7593 +3175 +3447 +1718 + +6062 +7630 +6302 +4448 +1014 +4756 +4696 +4069 +5663 +2181 +6153 + +9228 +1871 +11739 +10894 + +7435 +6290 +3249 +9358 +9196 +8951 +5023 +4910 +9686 + +3823 +4247 +7159 + +4630 +3352 +7700 +7752 +3343 +4577 +2448 +10326 + +10002 +28943 + +2592 +4430 +4077 +2126 +4628 +6466 +5919 +7019 +2667 +2573 +7038 +3153 + +2837 +12151 +9774 +1574 +3046 +13079 + +6949 + +5306 +7432 +4274 +6835 +7057 +5695 +4727 +5581 +6516 +3903 +3138 + +4083 +4247 +1806 +2753 +3612 +3509 +5498 +2160 +5814 +1502 +5760 +4663 +1354 +1592 + +59040 + +3738 +7624 +4539 +8649 +9418 +5495 +1178 +8389 + +4458 +5283 +2572 +3530 +6228 +4711 +2621 +2131 +6363 +5611 +3236 +2314 +2547 +1905 + +3744 +1413 +2997 + +2214 +4673 +4481 +5827 +3752 +5489 +5301 +7568 +6869 +2928 +2900 + +11668 +7579 +2324 +7245 +14362 + +1191 +5622 +2764 +3241 +3690 +3627 +2637 +4043 +3012 +2773 +4276 +1127 +3649 + +5327 +6535 +4821 +5531 +3037 +4700 +6287 +6476 +2266 +7550 + +3054 +5023 +1296 +4394 +5649 +1822 +6609 +7038 +5836 +6571 +6918 + +9473 +5377 +8449 +4839 +3118 +7861 + +8784 +3880 +5133 +6131 +2114 +5196 +10405 +1040 + +5003 +5888 +6058 +6910 +3155 +3278 +1159 +3863 +4565 +1181 +2716 +6431 +3014 + +7633 +4984 +1297 +4524 +5183 +3717 +12038 + +5908 +7784 +11211 +7635 +2060 +5502 +9179 + +6537 +6895 +3455 +4799 +5557 +3497 +4467 +1694 +5227 +1663 +2377 +3538 +4529 + +9371 +2421 +9789 +7373 +6459 +6405 +7775 +8218 + +2077 +8589 +3417 +7811 +10255 +4325 +7168 + +5963 +2806 +3512 +2369 +5721 +3852 +3022 +3764 +6152 +1158 +6460 +4694 +1909 +2655 + +7789 +3030 +3621 +6269 +3149 +6405 +2288 +3512 +5674 +1301 + +6120 +2629 +6348 +7105 +3459 +6678 +5903 +4519 +3074 +2086 +3927 + +2924 +12290 +1873 +5613 +3098 +8641 + +24464 +37206 + +7180 +13271 +4832 +10691 +9084 + +4915 +1440 +1841 +1476 +7124 +1692 +7480 +4583 +1896 +3475 +5424 + +6864 +3187 +4680 +5159 +4314 +3148 +1060 +7290 +2080 +8308 + +2412 +16405 +15203 +5606 +9411 + +13201 +6242 +11906 +15782 +12558 + +5319 +7968 +6732 +9702 + +7203 +3571 +7241 +8764 +3466 +6032 +6608 +6898 +7189 +2749 + +6184 +7590 +4976 +4289 +8553 +8238 +5844 +8314 + +3264 +2924 +2586 +1234 +3126 +5269 +6147 +6029 +2384 +6440 +6161 +1708 +2928 +2336 + +24565 +31964 + +11118 +10621 +1430 +3312 +1135 +6740 +9456 + +16874 +4385 +8675 +4237 + +1537 +4313 +5552 +2195 +3530 +2433 +3056 +3693 +1151 +4297 +2017 +4917 +3823 +3388 +1580 + +5795 +2642 +3822 +1824 +2366 +3800 +2020 +4065 +2758 +2677 +3951 +5175 +4433 +1199 +3212 + +4183 +2822 +6355 +4427 +6384 +2931 +4892 +3148 +5802 +3885 +4892 +5233 +4269 +4286 + +3711 +5430 +6115 +5561 +5066 +2796 +3886 +1960 +6083 +4657 + +11662 +12901 +6891 +3897 + +1086 +4333 +1477 +1046 +5670 +3996 +1909 +3544 +5143 +1387 +6319 +3084 +3136 +6084 + +36111 +14790 + +6552 +8491 + +6636 +9718 +15736 +1619 + +9531 +7507 +7311 +5991 +6901 +12139 +10580 + +10956 +7878 +9100 +11884 +2906 +10388 + +7767 +4040 +5872 +1060 +2299 +1008 +3597 +2749 +5025 + +1550 + +5364 +7108 +8661 +8894 +9240 +10008 +4243 + +46695 + +4195 +2850 +2978 +4995 +2944 +5773 +3669 +3662 +4471 +6343 +4258 +1252 +6408 +5995 + +9482 +11898 +9022 +8167 +9232 + +2647 +1990 +2948 +5314 +2341 +3828 +2513 +2091 +4173 + +9640 +2690 +8774 +11619 +11201 +2429 +7216 + +3433 +5914 +5223 +4879 +1349 +4692 +2906 +3761 +4416 +4813 +2751 +4474 +2057 +1675 + +9803 +8986 +3617 +2175 +1412 +8370 + +7671 +6448 +6759 +1857 + +25790 +14495 + +1872 +6441 +4585 +4053 +4142 +5844 +2089 +3387 +2660 +5890 +6499 +3769 +2710 + +23432 +16915 + +1351 +2656 +6557 +1149 +5054 +1681 +6871 +2643 +3158 +1617 +4087 +6498 +4993 + +5494 +10055 +2730 +5800 +2923 +8037 +3448 +1527 + +5803 +18165 +21951 + +4766 +3809 +4678 +3184 +9687 +7825 +7222 +6638 +2016 + +1801 +1717 +4955 +6088 +1848 +4033 +7023 +3551 +5970 +1415 +7027 +7411 + +25450 +11523 +22548 + +1566 +4742 +3947 +2708 +2019 +3479 +4735 +6002 +7042 +1828 +7071 +1535 + +14218 +5232 +10228 +3340 +7975 + +8837 +3510 +10363 +11854 +2821 +7627 +10186 + +1102 +3749 +1436 +1561 +3098 +3849 +3726 +2041 +1100 +1532 +5473 +4643 +5922 +4739 +1216 + +4408 +7369 +1369 +4742 +7109 +4368 +3468 +2777 +3296 +6999 +5777 +5019 + +3750 +12190 + +15694 +12690 +14834 +15532 +1955 + +8702 +1209 +3012 +3074 +8390 +6779 +6117 +2544 +3900 +6374 + +4126 +5772 +7149 +3949 +2371 +2374 +2469 +7839 +7898 +2871 +5808 + +1108 + +9610 +4374 +10275 +2595 +9413 +8906 +6402 +1551 + +6560 +8632 +5064 +2152 +3443 +4229 + +13104 +24831 +17968 + +4648 +5332 +4866 +1048 +4089 +4710 +1406 +2544 +5319 +4685 +4622 +6080 +5899 +3266 + +5694 +12879 +4015 +16066 +1600 + +11186 +31873 + +3871 +6382 +5076 +3606 +4283 +7913 +11124 + +9959 +14807 +17825 +5880 + +3914 +14183 + +8104 +8322 +10254 +3957 +1410 +9402 +2012 + +1130 +4640 +5738 +3860 +1510 +3067 +5021 +5321 +2820 +1269 +3433 +5216 +5585 +1344 + +5975 +9879 +4969 +9796 +1404 +6772 +3240 +1954 + +12512 +13741 +6425 +13234 +10597 +12414 + +2031 +2255 +3306 +1831 +1601 +1959 +4452 +5054 +4967 +5392 +4040 +4989 +4385 +5838 +5043 + +3165 +10185 +10580 +1626 +5436 +9644 +10842 + +5139 +8090 +1045 +5867 +5987 +8488 +2409 + +1045 +2843 +3543 +3224 +2855 +3318 +4192 +4600 +5773 +4074 +4705 +4716 +1798 +5274 +2443 + +6325 +7878 +4932 +7543 +8073 +2113 +5481 +8138 +2151 +1296 + +6007 +2506 +2346 +3631 +1526 +4875 +3099 +5253 +6281 +2057 +3209 +2622 +2930 +4926 + +2901 +4561 +2361 +4474 +8508 +6515 +5024 +2201 +4402 +6922 + +4219 +24714 +17196 + +38164 + +1900 +5727 +3935 +5498 +6165 +4621 +3347 +4387 +5982 +4213 +1742 +1302 +2452 +3923 + +9558 +7131 +15662 +9101 +13730 + +6474 +2222 +6539 +3747 +5995 +5573 +6288 +4684 +5121 +2226 +1722 +1117 +1020 + +3565 +3489 + +18395 +20407 + +57158 + +19992 + +3636 +4392 +4584 +5421 +3159 +5817 +2303 +1013 +1758 +1802 +4630 +4261 +1524 +1639 + +4652 +1967 +4765 +4946 +3023 +2732 +2749 +5258 +5935 +6428 +3053 +6328 +2389 +5681 + +5450 +1993 +2824 +3596 +2658 +8545 +6577 +3024 +4001 +1780 + +7902 +6187 + +1349 +6028 +3307 +1964 +5116 +2308 +6108 +4286 +1689 +3324 +3728 +4946 +4267 +3801 +3806 + +14183 +29320 + +32460 +25012 + +3317 +5545 +7302 +4936 +7934 +6094 +7971 +2497 +8130 +3752 + +4195 +2147 +7770 +4214 +4737 +7962 +5942 +4478 +3816 +7508 +6693 + +26013 +8614 +19828 + +1144 +2361 +4371 +4246 +3442 +1693 +5137 +5806 +2434 +1413 +3135 +4028 +4757 +6005 + +2351 +4927 +3004 +3384 +1545 +2172 +3407 +4120 +3954 +1806 +2342 +5847 +5228 +1005 + +11490 +7855 +9775 +10577 +3232 +5211 + +8316 +2984 +13490 +15716 +7433 + +11288 +14551 +10056 +14839 +7241 + +4573 +2731 +3358 +4850 +6352 +5419 +1021 +6611 +6489 +3794 +6089 diff --git a/aoc2022/input/day01_provided.txt b/aoc2022/input/day01_provided.txt new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/aoc2022/input/day01_provided.txt @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 diff --git a/aoc2022/src/day01.rs b/aoc2022/src/day01.rs new file mode 100644 index 0000000..57e623f --- /dev/null +++ b/aoc2022/src/day01.rs @@ -0,0 +1,63 @@ +use std::fmt::Write; + +use anyhow::{Context, Result}; + +const INPUT: &str = include_str!("../input/day01.txt"); + +pub fn run() -> Result { + let mut res = String::with_capacity(128); + + writeln!(res, "part 1: {}", part1(INPUT)?)?; + + Ok(res) +} + +fn part1(input: &str) -> Result { + let inventories = input + .split("\n\n") + .map(str::parse::) + .collect::>>()?; + + inventories + .iter() + .map(Inventory::total_calories) + .max() + .context("inventory list was empty") +} + +struct Inventory(Vec); + +impl std::str::FromStr for Inventory { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + Ok(Inventory( + s.lines() + .map(|line| line.parse::().map_err(anyhow::Error::new)) + .collect::>>()?, + )) + } +} + +impl Inventory { + fn total_calories(&self) -> u64 { + self.0.iter().sum() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + const PROVIDED: &str = include_str!("../input/day01_provided.txt"); + + #[test] + fn part1_provided() { + assert_eq!(part1(PROVIDED).unwrap(), 24000); + } + + #[test] + fn part1_real() { + assert_eq!(part1(INPUT).unwrap(), 68923); + } +} diff --git a/aoc2022/src/lib.rs b/aoc2022/src/lib.rs new file mode 100644 index 0000000..784a117 --- /dev/null +++ b/aoc2022/src/lib.rs @@ -0,0 +1,3 @@ +#![warn(clippy::explicit_iter_loop, clippy::redundant_closure_for_method_calls)] + +pub mod day01; diff --git a/aoc2022/src/main.rs b/aoc2022/src/main.rs new file mode 100644 index 0000000..98d4d03 --- /dev/null +++ b/aoc2022/src/main.rs @@ -0,0 +1,11 @@ +use anyhow::Result; + +use aoc::DayFunc; + +use aoc2022::day01; + +fn main() -> Result<()> { + let days: &[DayFunc] = &[day01::run]; + + aoc::run(days) +} diff --git a/flake.lock b/flake.lock index 7f2e0b6..f8b7e1c 100644 --- a/flake.lock +++ b/flake.lock @@ -32,16 +32,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1637593665, - "narHash": "sha256-R7jKS7A+0tZS8qD5pBr1UFcMiTdsw5bfoxgXbYsoWhM=", + "lastModified": 1669834992, + "narHash": "sha256-YnhZGHgb4C3Q7DSGisO/stc50jFb9F/MzHeKS4giotg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "98747f27ecfee70c8c97b195cbb94df80a074dda", + "rev": "596a8e828c5dfa504f91918d0fa4152db3ab5502", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixpkgs-unstable", + "ref": "nixos-22.11", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 31a64b2..ffaa247 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; rust-overlay.url = "github:oxalica/rust-overlay"; flake-utils.url = "github:numtide/flake-utils"; }; From 8e1328571b993069595515198bd1c64b3d13cc0c Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 5 Dec 2022 23:04:07 +0100 Subject: [PATCH 2/5] 2021: bump bitvec to 1.0 --- Cargo.lock | 16 ++++++++-------- aoc2021/Cargo.toml | 2 +- aoc2021/src/day16.rs | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa0f66e..8976861 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,9 +141,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitvec" -version = "0.22.3" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" dependencies = [ "funty", "radium", @@ -347,9 +347,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "funty" -version = "1.2.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "generic-array" @@ -574,9 +574,9 @@ dependencies = [ [[package]] name = "radium" -version = "0.6.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" [[package]] name = "rand" @@ -912,9 +912,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "wyz" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] diff --git a/aoc2021/Cargo.toml b/aoc2021/Cargo.toml index e31557d..a33f86c 100644 --- a/aoc2021/Cargo.toml +++ b/aoc2021/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" aoc = { path = "../aoc" } anyhow = "1.0" rand = "0.8" -bitvec = "0.22" +bitvec = "1.0" [lib] path = "src/lib.rs" diff --git a/aoc2021/src/day16.rs b/aoc2021/src/day16.rs index 688fa8a..d02fd94 100644 --- a/aoc2021/src/day16.rs +++ b/aoc2021/src/day16.rs @@ -122,7 +122,7 @@ impl std::str::FromStr for Packet { fn from_str(s: &str) -> Result { let s = s.trim(); - let mut bits = BitVec::::new(); + let mut bits = BitVec::::new(); bits.resize(4 * s.len(), false); for (i, c) in s.chars().enumerate() { @@ -149,13 +149,13 @@ const TLID1_SUBPACKET_NUMBER_BITS: usize = 11; const SUBPACKET_START_INDEX_TLID1: usize = LENGTH_INDEX + TLID1_SUBPACKET_NUMBER_BITS; const SUBPACKETS_NUMBER_RANGE: Range = LENGTH_INDEX..SUBPACKET_START_INDEX_TLID1; -impl<'bits, Store> TryFrom<&'bits BitSlice> for Packet +impl<'bits, Store> TryFrom<&'bits BitSlice> for Packet where Store: BitStore, { type Error = anyhow::Error; - fn try_from(bits: &'bits BitSlice) -> Result { + fn try_from(bits: &'bits BitSlice) -> Result { let version: u8 = bits[VERSION_RANGE].load_be(); let type_id: u8 = bits[TYPE_ID_RANGE].load_be(); From a25dc5beae0fdb35dafd70f4d70de20b671c19fd Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 5 Dec 2022 23:08:19 +0100 Subject: [PATCH 3/5] bump Cargo.lock --- Cargo.lock | 262 +++++++++++++++++++++++------------------------------ 1 file changed, 115 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8976861..07ae2c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.51" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "aoc" @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" @@ -186,9 +186,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.8.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byte-tools" @@ -204,12 +204,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cast" -version = "0.2.7" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" -dependencies = [ - "rustc_version", -] +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cfg-if" @@ -230,16 +227,16 @@ dependencies = [ [[package]] name = "criterion" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" +checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", "cast", "clap", "criterion-plot", "csv", - "itertools 0.10.3", + "itertools 0.10.5", "lazy_static", "num-traits", "oorandom", @@ -256,19 +253,19 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" +checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" dependencies = [ "cast", - "itertools 0.10.3", + "itertools 0.10.5", ] [[package]] name = "crossbeam-channel" -version = "0.5.1" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" dependencies = [ "cfg-if", "crossbeam-utils", @@ -276,9 +273,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -287,25 +284,24 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.5" +version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" dependencies = [ + "autocfg", "cfg-if", "crossbeam-utils", - "lazy_static", "memoffset", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ "cfg-if", - "lazy_static", ] [[package]] @@ -341,9 +337,9 @@ dependencies = [ [[package]] name = "either" -version = "1.6.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "funty" @@ -362,9 +358,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", @@ -397,9 +393,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] @@ -412,15 +408,15 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" -version = "0.3.55" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -433,15 +429,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.112" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -459,15 +455,15 @@ dependencies = [ [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" -version = "0.6.5" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ "autocfg", ] @@ -480,34 +476,39 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "nom" -version = "7.1.0" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" dependencies = [ "memchr", "minimal-lexical", - "version_check", ] [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", ] [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ "hermit-abi", "libc", ] +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + [[package]] name = "oorandom" version = "11.1.3" @@ -522,9 +523,9 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "plotters" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" dependencies = [ "num-traits", "plotters-backend", @@ -535,39 +536,39 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" [[package]] name = "plotters-svg" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" dependencies = [ "plotters-backend", ] [[package]] name = "ppv-lite86" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.34" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.10" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -580,14 +581,13 @@ checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" [[package]] name = "rand" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", "rand_core", - "rand_hc", ] [[package]] @@ -602,29 +602,19 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" -dependencies = [ - "rand_core", -] - [[package]] name = "rayon" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +checksum = "1e060280438193c554f654141c9ea9417886713b7acd75974c85b18a69a88e0b" dependencies = [ - "autocfg", "crossbeam-deque", "either", "rayon-core", @@ -632,22 +622,21 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.1" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", "num_cpus", ] [[package]] name = "regex" -version = "1.5.4" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "regex-syntax", ] @@ -660,24 +649,15 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "same-file" @@ -694,17 +674,11 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "semver" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" - [[package]] name = "serde" -version = "1.0.132" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008" +checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055" [[package]] name = "serde_cbor" @@ -718,9 +692,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.132" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276" +checksum = "b4eae9b04cbffdfd550eb462ed33bc6a1b68c935127d008b27444d08380f94e4" dependencies = [ "proc-macro2", "quote", @@ -729,24 +703,24 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.73" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5" +checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" dependencies = [ - "itoa 1.0.1", + "itoa 1.0.4", "ryu", "serde", ] [[package]] name = "syn" -version = "1.0.82" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -776,27 +750,21 @@ dependencies = [ [[package]] name = "typenum" -version = "1.14.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "version_check" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "walkdir" @@ -811,15 +779,15 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.78" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -827,13 +795,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.78" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -842,9 +810,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.78" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -852,9 +820,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.78" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -865,15 +833,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.78" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.55" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", From 2ca6bce781fc21a62a2f3caf7b9f224a429bf9a7 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Mon, 5 Dec 2022 23:28:51 +0100 Subject: [PATCH 4/5] 2022: day01 part 2 --- aoc2022/src/day01.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/aoc2022/src/day01.rs b/aoc2022/src/day01.rs index 57e623f..230ce57 100644 --- a/aoc2022/src/day01.rs +++ b/aoc2022/src/day01.rs @@ -1,3 +1,4 @@ +use std::collections::BinaryHeap; use std::fmt::Write; use anyhow::{Context, Result}; @@ -8,6 +9,7 @@ pub fn run() -> Result { let mut res = String::with_capacity(128); writeln!(res, "part 1: {}", part1(INPUT)?)?; + writeln!(res, "part 2: {}", part2(INPUT)?)?; Ok(res) } @@ -25,6 +27,16 @@ fn part1(input: &str) -> Result { .context("inventory list was empty") } +fn part2(input: &str) -> Result { + let inventories = input + .split("\n\n") + .map(|line| line.parse::().map(|inv| inv.total_calories())) + .collect::>>()?; + + Ok(inventories.iter().take(3).sum()) +} + +#[derive(Debug)] struct Inventory(Vec); impl std::str::FromStr for Inventory { @@ -60,4 +72,14 @@ mod tests { fn part1_real() { assert_eq!(part1(INPUT).unwrap(), 68923); } + + #[test] + fn part2_provided() { + assert_eq!(part2(PROVIDED).unwrap(), 45000); + } + + #[test] + fn part2_real() { + assert_eq!(part2(INPUT).unwrap(), 200044); + } } From ed660127529aa7e76c41f4d807e39dc7b6aa62df Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 6 Dec 2022 00:01:28 +0100 Subject: [PATCH 5/5] 2022: bench: criterion 0.4 --- Cargo.lock | 145 ++++++++++++++++-- aoc2022/Cargo.toml | 7 + aoc2022/aoc2022_bench/Cargo.toml | 17 -- .../benches/aoc2022_bench.rs | 0 4 files changed, 136 insertions(+), 33 deletions(-) delete mode 100644 aoc2022/aoc2022_bench/Cargo.toml rename aoc2022/{aoc2022_bench => }/benches/aoc2022_bench.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 07ae2c3..2423e93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anyhow" version = "1.0.66" @@ -29,7 +35,7 @@ name = "aoc2015_bench" version = "0.1.0" dependencies = [ "aoc2015", - "criterion", + "criterion 0.3.6", ] [[package]] @@ -45,7 +51,7 @@ name = "aoc2018_bench" version = "0.1.0" dependencies = [ "aoc2018", - "criterion", + "criterion 0.3.6", ] [[package]] @@ -61,7 +67,7 @@ name = "aoc2019_bench" version = "0.1.0" dependencies = [ "aoc2019", - "criterion", + "criterion 0.3.6", ] [[package]] @@ -79,7 +85,7 @@ name = "aoc2020_bench" version = "0.1.0" dependencies = [ "aoc2020", - "criterion", + "criterion 0.3.6", ] [[package]] @@ -97,7 +103,7 @@ name = "aoc2021_bench" version = "0.1.0" dependencies = [ "aoc2021", - "criterion", + "criterion 0.3.6", ] [[package]] @@ -106,14 +112,7 @@ version = "0.1.0" dependencies = [ "anyhow", "aoc", -] - -[[package]] -name = "aoc2022_bench" -version = "0.1.0" -dependencies = [ - "aoc2022", - "criterion", + "criterion 0.4.0", ] [[package]] @@ -214,6 +213,33 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "ciborium" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" + +[[package]] +name = "ciborium-ll" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "clap" version = "2.34.0" @@ -221,10 +247,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "bitflags", - "textwrap", + "textwrap 0.11.0", "unicode-width", ] +[[package]] +name = "clap" +version = "3.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +dependencies = [ + "bitflags", + "clap_lex", + "indexmap", + "textwrap 0.16.0", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "criterion" version = "0.3.6" @@ -233,8 +280,8 @@ checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", "cast", - "clap", - "criterion-plot", + "clap 2.34.0", + "criterion-plot 0.4.5", "csv", "itertools 0.10.5", "lazy_static", @@ -251,6 +298,31 @@ dependencies = [ "walkdir", ] +[[package]] +name = "criterion" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" +dependencies = [ + "anes", + "atty", + "cast", + "ciborium", + "clap 3.2.23", + "criterion-plot 0.5.0", + "itertools 0.10.5", + "lazy_static", + "num-traits", + "oorandom", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + [[package]] name = "criterion-plot" version = "0.4.5" @@ -261,6 +333,16 @@ dependencies = [ "itertools 0.10.5", ] +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools 0.10.5", +] + [[package]] name = "crossbeam-channel" version = "0.5.6" @@ -373,6 +455,12 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -382,6 +470,16 @@ dependencies = [ "libc", ] +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "itertools" version = "0.9.0" @@ -521,6 +619,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + [[package]] name = "plotters" version = "0.3.4" @@ -679,6 +783,9 @@ name = "serde" version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055" +dependencies = [ + "serde_derive", +] [[package]] name = "serde_cbor" @@ -738,6 +845,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "tinytemplate" version = "1.2.1" diff --git a/aoc2022/Cargo.toml b/aoc2022/Cargo.toml index 9fe9672..1f0e257 100644 --- a/aoc2022/Cargo.toml +++ b/aoc2022/Cargo.toml @@ -10,9 +10,16 @@ edition = "2021" aoc = { path = "../aoc" } anyhow = "1.0" +[dev-dependencies] +criterion = { version = "0.4", default-features = false, features = [ "rayon" ] } + [lib] path = "src/lib.rs" [[bin]] name = "aoc2022" path = "src/main.rs" + +[[bench]] +name = "aoc2022_bench" +harness = false diff --git a/aoc2022/aoc2022_bench/Cargo.toml b/aoc2022/aoc2022_bench/Cargo.toml deleted file mode 100644 index e5ef4bc..0000000 --- a/aoc2022/aoc2022_bench/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "aoc2022_bench" -version = "0.1.0" -authors = ["Antoine Martin "] -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aoc2022 = { path = "../" } - -[dev-dependencies] -criterion = "0.3" - -[[bench]] -name = "aoc2022_bench" -harness = false diff --git a/aoc2022/aoc2022_bench/benches/aoc2022_bench.rs b/aoc2022/benches/aoc2022_bench.rs similarity index 100% rename from aoc2022/aoc2022_bench/benches/aoc2022_bench.rs rename to aoc2022/benches/aoc2022_bench.rs