advent-of-code

Perserverance, or the lack thereof

git clone git://git.shimmy1996.com/advent-of-code.git
commit 5aa3105c4741c213d3effd4e3745dd7a74e6f039
parent 200af00ec1b1ef8072e5e8f8d3466d31385d5776
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date:   Thu,  1 Dec 2022 19:51:48 -0500

Add 2022 day 01

Diffstat:
A2022/day01/input.txt | 2255+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2022/day01/main.rs | 33+++++++++++++++++++++++++++++++++
2 files changed, 2288 insertions(+), 0 deletions(-)
diff --git a/2022/day01/input.txt b/2022/day01/input.txt
@@ -0,0 +1,2255 @@
+4035
+10596
+17891
+5278
+
+11293
+8478
+10874
+10582
+10756
+6649
+
+9707
+15243
+13494
+
+18006
+15104
+9091
+
+1177
+5310
+4579
+2550
+3865
+4871
+3455
+3129
+2853
+2521
+3656
+4203
+5381
+1300
+1054
+
+8453
+7533
+2746
+6511
+6857
+1472
+3516
+6747
+
+6115
+4307
+2746
+4112
+1500
+3192
+2120
+1284
+2526
+2163
+
+8659
+9332
+7879
+8908
+8056
+6600
+1564
+9967
+
+4389
+6009
+7000
+5517
+6720
+3098
+1783
+1027
+6354
+
+22457
+2465
+16768
+
+3285
+6524
+8742
+3578
+5079
+3779
+7510
+9892
+
+5190
+13534
+4975
+4413
+16343
+
+10400
+5755
+8526
+1798
+4659
+11774
+3356
+
+1909
+3639
+3302
+4197
+3963
+2013
+3719
+7930
+7479
+6438
+5547
+
+8542
+8392
+3688
+9810
+4397
+8426
+10284
+4884
+
+2837
+2535
+2733
+8792
+4029
+3922
+4486
+7059
+3064
+6332
+
+5596
+3353
+4145
+5423
+1987
+4009
+1102
+5239
+5145
+2961
+5568
+4582
+6212
+4586
+
+21171
+29197
+
+8684
+3218
+8869
+2592
+8356
+3713
+3298
+8868
+8956
+
+4969
+10004
+7890
+3033
+
+5989
+4739
+4049
+7048
+6549
+5914
+1795
+2148
+7478
+4858
+6431
+2075
+
+7914
+10022
+7407
+6983
+5584
+7742
+7695
+
+2599
+5810
+5476
+4347
+4001
+4867
+6097
+4083
+3671
+5553
+2729
+2669
+2070
+3679
+3569
+
+54097
+
+6364
+4797
+2809
+5158
+2008
+1346
+1041
+5413
+3540
+2512
+3919
+4364
+5697
+5282
+
+5144
+7149
+9290
+2218
+10025
+7634
+6597
+10745
+
+69849
+
+2236
+19046
+17965
+17958
+
+6656
+15791
+
+7882
+4654
+4178
+5451
+9287
+4983
+4158
+
+1242
+6119
+2387
+3307
+2665
+3315
+4926
+6423
+1026
+3269
+2858
+1306
+5531
+2806
+
+1173
+1937
+4604
+3826
+3450
+2588
+5029
+1383
+3008
+4414
+1357
+1003
+2359
+6031
+4250
+
+2469
+5917
+5754
+3765
+3024
+3507
+4326
+4688
+5340
+1519
+4031
+4831
+5701
+2673
+3580
+
+7800
+3225
+7566
+6135
+7154
+5718
+9496
+3208
+3800
+
+13234
+11815
+1004
+8035
+2370
+1662
+
+5536
+1638
+4084
+5245
+2793
+5414
+3959
+3095
+2641
+1607
+6890
+
+2081
+7031
+6733
+4355
+6465
+3975
+3141
+5078
+6347
+6375
+2205
+3024
+
+5423
+9379
+8400
+2413
+7323
+
+11650
+4103
+2180
+2761
+14826
+
+22137
+18830
+8552
+
+24584
+32789
+
+5392
+2612
+4328
+4594
+1511
+6128
+5562
+6285
+5492
+5194
+5749
+5623
+5971
+2513
+
+11531
+1312
+7341
+10793
+7781
+8586
+11981
+
+2072
+1131
+1074
+3128
+5630
+6869
+6018
+1202
+6248
+6274
+6550
+6062
+5444
+
+10089
+9731
+4320
+8372
+2486
+9573
+11238
+
+3309
+2170
+1866
+3852
+1351
+5133
+2672
+3281
+2385
+2844
+2992
+4763
+4608
+5465
+4365
+
+2094
+17679
+20013
+
+8407
+23397
+5451
+
+6063
+2853
+3852
+3164
+4162
+1577
+4931
+3401
+5071
+5657
+3304
+3312
+2523
+4764
+2944
+
+11987
+3387
+13532
+6199
+1643
+3456
+
+5246
+2338
+6657
+3260
+2599
+1013
+4483
+2374
+3097
+5435
+3773
+1609
+
+7965
+1088
+5221
+2514
+8357
+2404
+9126
+1073
+8421
+
+45752
+
+17545
+18097
+6577
+9017
+
+3862
+6026
+6218
+6280
+5914
+3626
+5579
+1047
+5713
+6274
+5699
+3988
+4775
+1284
+
+3713
+1799
+2273
+5852
+2935
+5121
+5000
+4557
+2094
+2846
+2049
+5431
+4391
+2748
+3853
+
+10070
+10215
+9246
+2092
+5734
+8240
+6141
+9907
+
+9918
+9015
+1599
+1994
+3571
+5545
+2236
+
+5521
+6200
+3032
+2190
+8668
+7320
+10651
+3569
+
+9931
+9096
+5350
+7715
+7828
+2810
+5180
+
+7833
+12311
+14716
+13631
+
+4773
+3967
+2439
+3464
+10079
+2382
+1176
+3248
+
+4731
+2213
+7008
+8050
+1311
+2314
+1079
+7387
+2361
+3189
+4563
+
+5529
+1503
+2420
+4149
+4115
+2897
+2446
+5165
+2798
+5622
+2979
+4426
+3064
+2603
+
+3391
+8069
+9138
+8121
+6898
+3295
+11444
+
+2671
+7559
+8704
+9139
+7932
+3497
+8208
+10454
+
+8211
+3807
+5333
+3866
+1683
+3289
+6027
+8381
+1008
+
+3498
+3521
+3490
+3116
+4541
+1720
+3073
+4096
+6375
+4114
+1597
+3122
+5783
+2400
+
+4369
+1172
+2835
+5571
+2268
+5441
+3154
+1209
+5294
+2307
+4100
+5305
+3038
+3619
+5243
+
+7721
+6992
+2315
+7827
+3866
+1087
+2190
+3008
+4604
+
+5125
+3583
+5554
+5925
+3641
+2878
+2901
+3259
+1495
+6062
+2437
+
+4582
+1857
+5060
+1159
+4940
+4668
+2676
+4575
+3929
+2410
+1684
+5043
+4925
+3013
+1605
+
+2051
+2233
+6506
+3049
+6416
+6112
+2864
+6016
+5710
+5056
+4629
+5557
+4502
+5667
+
+3805
+8345
+6042
+7823
+1349
+8979
+1853
+3122
+
+19474
+4674
+8654
+16839
+
+1268
+1111
+5234
+1092
+1708
+4410
+7309
+9232
+
+22189
+17935
+
+5756
+1673
+1582
+5633
+1766
+3084
+1270
+2620
+1856
+5259
+2368
+1518
+5713
+3409
+5494
+
+7392
+5170
+5153
+6898
+4324
+1989
+
+13924
+10998
+4781
+1961
+8574
+
+3850
+5824
+2060
+7001
+7952
+7847
+7830
+6570
+7224
+5290
+6421
+
+11418
+1666
+12598
+11712
+2284
+4411
+
+60042
+
+3120
+2901
+1877
+4117
+3651
+2177
+5708
+1267
+5727
+1887
+5133
+2013
+4505
+4919
+
+28576
+21040
+
+7464
+2194
+1882
+6432
+5015
+8638
+6232
+3488
+
+3476
+1479
+5623
+1252
+2665
+4905
+6106
+2020
+6038
+6176
+
+9492
+9535
+17296
+5004
+
+7075
+1568
+8929
+6224
+7247
+5291
+10705
+
+13520
+5594
+9651
+3872
+
+4537
+4904
+5203
+5726
+1844
+1223
+2359
+2210
+2839
+5001
+2675
+6338
+6021
+6027
+
+12582
+2396
+8529
+16218
+
+4909
+6794
+17806
+18041
+
+3715
+2120
+4863
+7324
+8733
+5560
+2512
+8639
+3042
+5419
+
+10514
+4911
+9680
+8309
+2553
+3973
+1823
+6907
+
+9773
+4861
+3646
+7379
+9084
+9720
+4886
+
+8432
+6757
+7571
+6055
+1853
+4975
+
+1769
+4548
+1332
+1178
+2031
+2090
+1091
+3050
+4290
+4701
+1042
+3414
+2785
+1019
+2507
+
+5211
+6276
+4790
+1412
+6761
+3267
+5635
+6262
+2555
+4165
+6452
+5939
+6060
+
+19615
+12726
+12026
+
+1101
+7685
+4004
+3560
+4254
+4802
+4188
+3687
+2020
+
+3955
+2505
+3834
+1753
+3254
+6981
+3367
+2516
+2131
+2212
+5844
+2783
+
+51115
+
+4361
+9019
+5980
+8485
+2671
+1413
+3370
+8113
+8466
+
+6394
+6423
+5860
+6275
+8182
+7807
+9480
+4247
+1428
+
+4185
+6265
+6366
+1530
+1547
+8496
+2473
+6734
+3453
+
+26029
+1693
+20862
+
+1786
+5044
+4252
+4862
+6044
+4164
+4881
+1304
+7796
+4287
+2023
+
+8927
+6171
+1979
+1750
+5562
+3747
+10354
+6631
+
+4859
+8724
+1971
+7487
+7271
+2801
+3151
+9374
+
+4855
+1366
+1585
+4901
+1066
+5433
+1829
+1954
+4614
+5334
+5164
+2335
+1859
+1833
+1234
+
+3491
+5377
+7766
+4047
+1352
+9597
+7208
+5633
+
+6077
+4535
+3656
+8001
+1394
+7926
+4334
+5329
+3032
+3689
+5634
+
+2664
+13685
+2572
+6294
+7476
+
+4009
+4443
+6839
+2894
+4743
+4275
+5073
+5840
+2480
+1026
+2335
+1557
+1341
+
+5481
+4806
+2159
+1503
+1567
+2764
+1682
+5762
+5275
+4808
+3545
+2066
+3437
+1202
+4291
+
+1283
+1134
+4795
+7056
+1640
+
+8139
+
+11134
+6405
+12135
+12327
+5661
+2203
+
+14804
+9628
+14050
+
+8571
+3990
+5019
+3187
+5787
+3271
+7819
+2165
+3275
+7852
+
+6605
+3587
+2880
+2457
+1124
+1123
+4380
+3038
+5805
+4547
+4672
+4988
+4183
+
+5762
+5586
+5109
+5779
+6009
+2987
+1775
+2125
+1166
+3576
+4080
+1235
+1692
+4746
+1027
+
+24787
+3445
+
+7179
+7478
+11402
+12927
+5762
+
+16532
+1833
+13640
+2596
+
+6181
+8594
+12084
+10425
+10938
+
+15032
+13087
+15206
+12255
+16354
+
+6414
+5724
+6304
+2513
+5758
+6202
+6693
+1603
+2248
+4001
+6102
+3039
+2483
+
+4669
+6524
+5685
+6943
+6024
+1634
+1993
+3353
+5656
+4038
+2535
+1998
+6588
+
+44479
+
+3576
+2866
+11483
+
+2220
+11778
+12712
+16032
+5381
+
+6133
+1872
+1028
+4806
+3205
+5039
+5106
+1650
+4705
+2664
+1721
+2381
+4039
+1866
+
+2839
+2547
+2051
+4297
+3302
+5651
+4544
+2250
+5290
+1523
+2096
+3682
+2003
+4259
+1237
+
+6288
+2767
+7442
+4861
+3758
+2997
+2894
+4698
+3561
+3442
+
+2034
+2180
+4415
+6606
+4001
+2580
+6334
+4285
+5479
+7151
+3374
+5188
+
+67988
+
+5837
+5102
+9652
+1818
+1667
+8376
+1224
+6716
+2202
+
+54373
+
+2953
+7171
+3686
+3564
+5415
+4882
+3382
+1979
+2023
+3392
+3600
+7166
+
+6030
+5694
+6367
+6072
+3646
+2180
+1192
+4978
+1327
+6309
+6667
+3521
+4067
+
+4608
+7087
+3651
+2210
+3620
+8598
+3152
+9190
+1827
+
+7252
+6027
+2179
+6061
+7522
+6459
+6133
+1013
+
+21723
+19327
+23711
+
+10818
+28857
+
+41068
+
+11370
+7072
+2597
+3110
+5323
+1334
+
+9984
+
+6652
+6251
+7017
+2951
+5314
+1965
+6150
+1043
+3903
+2473
+2936
+
+13356
+3221
+23201
+
+5630
+4861
+2777
+5780
+5094
+2110
+6734
+4453
+3640
+6598
+4235
+
+2327
+5608
+9553
+4949
+8648
+7987
+5270
+1005
+6280
+
+2339
+8733
+10908
+10607
+11068
+2433
+
+7816
+17236
+5806
+
+27546
+17531
+
+5284
+2879
+10330
+13263
+6379
+2933
+
+15917
+11337
+25331
+
+4269
+10474
+4156
+8433
+11933
+13079
+
+2976
+7106
+3245
+3271
+6849
+7350
+3569
+6160
+5537
+5029
+2029
+
+18465
+16997
+
+24818
+18709
+23767
+
+10958
+7559
+6668
+10588
+5137
+8061
+6069
+
+1071
+3677
+3952
+2756
+2358
+3395
+1118
+2673
+4542
+1284
+3370
+4650
+5364
+
+7370
+2515
+4973
+6875
+6571
+6791
+5157
+4080
+7268
+6951
+3918
+7195
+
+5408
+3624
+4665
+2662
+1871
+4535
+2561
+1891
+2986
+1338
+1302
+2181
+5523
+3561
+2570
+
+2759
+5343
+7896
+5956
+3581
+3244
+1733
+1337
+6891
+7361
+7294
+
+1427
+4043
+9976
+7066
+4381
+1323
+6703
+9098
+
+3367
+8080
+4302
+4715
+5162
+7230
+4807
+3341
+
+4314
+6212
+4229
+5261
+2889
+1238
+1206
+6465
+4928
+6946
+2902
+5743
+5392
+
+3635
+3552
+5467
+3129
+2108
+5754
+2660
+3097
+5180
+3717
+1652
+2002
+4540
+5044
+4226
+
+1646
+3610
+7127
+8110
+4566
+1660
+3760
+6180
+9501
+
+7205
+5346
+6573
+7013
+5586
+1981
+3263
+5406
+4317
+1931
+3710
+1129
+
+2978
+3849
+1893
+5619
+5070
+5368
+5825
+3991
+4214
+7234
+
+19852
+11454
+1055
+6801
+
+2210
+3827
+2033
+3654
+7319
+2808
+3446
+1232
+4175
+3277
+4038
+
+27351
+7226
+
+1245
+3956
+2861
+5428
+4027
+2450
+5874
+1800
+5302
+3945
+3331
+1335
+2820
+3860
+
+2168
+3430
+7820
+2275
+6332
+5255
+3125
+2998
+6941
+3390
+4608
+
+2220
+2893
+4203
+9372
+7617
+7100
+2663
+8125
+
+9494
+5534
+9483
+8529
+4694
+6055
+9133
+3843
+
+1733
+1283
+8246
+12464
+
+6547
+5856
+6842
+9342
+5011
+1495
+2729
+9315
+
+1061
+9241
+9821
+1979
+8533
+4728
+
+10223
+8439
+8906
+10493
+10069
+6049
+5587
+9797
+
+2037
+4599
+1348
+6106
+1668
+6129
+5040
+5549
+3641
+4774
+3098
+1279
+6079
+5229
+
+10484
+9329
+5372
+10742
+4439
+10635
+6644
+7357
+
+6756
+3765
+4560
+4160
+1631
+5694
+2063
+8210
+2359
+3886
+
+1480
+4725
+5680
+1368
+2851
+3137
+2264
+4499
+5284
+5923
+3066
+5767
+6017
+5280
+6055
+
+1283
+11656
+
+10098
+5166
+15150
+9218
+
+11481
+19384
+1448
+4513
+
+4496
+3007
+3780
+3562
+1584
+3068
+2946
+5243
+1561
+3964
+4547
+3294
+5404
+1365
+5990
+
+13838
+8317
+5337
+9987
+8872
+12505
+
+8025
+2877
+5874
+4382
+3905
+2708
+6752
+3089
+
+8862
+8320
+4422
+1032
+4443
+3054
+9017
+7062
+4596
+
+3248
+6977
+13007
+10728
+13252
+12739
+
+5569
+3031
+1477
+6438
+1470
+4032
+2167
+2707
+1166
+4317
+2981
+1231
+4478
+
+1687
+6063
+5685
+1734
+2612
+2213
+1023
+3545
+5416
+2369
+2278
+3644
+5086
+5742
+
+5087
+1523
+4754
+1250
+6076
+2154
+1976
+6023
+4667
+3737
+6198
+2897
+3697
+6102
+
+1083
+9556
+7768
+7302
+9285
+9476
+7582
+3599
+4470
+
+13953
+5065
+
+32505
+32663
+
+9994
+4416
+1453
+13593
+1716
+11008
+
+65929
+
+52792
+
+4699
+3579
+5890
+1492
+7209
+6675
+1426
+2483
+5747
+4554
+4997
+
+5249
+5008
+3748
+7118
+5008
+2895
+6364
+1579
+1266
+2916
+5563
+6892
+
+3744
+1194
+6049
+10444
+9323
+9537
+9298
+
+5171
+6578
+3323
+2882
+3884
+6906
+4548
+5539
+4342
+5517
+6171
+1446
+3022
+
+19947
+11767
+17832
+1823
+
+4678
+1475
+4114
+14286
+3508
+
+18025
+18490
+13102
+18525
+
+8696
+7700
+6666
+4138
+4032
+5363
+7794
+5823
+5653
+
+11729
+11945
+5718
+4352
+10824
+9480
+
+25908
+12963
+8454
+
+1506
+5211
+3517
+8055
+5527
+2987
+1734
+2008
+1581
+2934
+1274
+
+12194
+11951
+17710
+5381
+
+46202
+
+4767
+13013
+1556
+9778
+11988
+3500
+
+1438
+11354
+21346
+
+1323
+3209
+10897
+
+8243
+
+3876
+5544
+2933
+3110
+3168
+3353
+1519
+1710
+3209
+1588
+2974
+3069
+3150
+2470
+2608
+
+5072
+3247
+2314
+1597
+2203
+5325
+5308
+4281
+3136
+2048
+5421
+2313
+1324
+5345
+
+8890
+6546
+2633
+7485
+4412
+7858
+5326
+5052
+
+4922
+7043
+3308
+3794
+2048
+4624
+3093
+4530
+1534
+4619
+1916
+
+2582
+4476
+2949
+1444
+4567
+4903
+3983
+5592
+1014
+4744
+4488
+5930
+6081
+2638
+3704
+
+4258
+4934
+6025
+1474
+1533
+5345
+6367
+2140
+3377
+1970
+2756
+5653
+3015
+2379
+
+5909
+1572
+4805
+3237
+10573
+5689
+4786
+8213
+
+7709
+10645
+1935
+10378
+3964
+3257
+3166
+10152
+
+21539
+23243
+1220
+
+5505
+2570
+9862
+2799
+
+5631
+4665
+3067
+2376
+5174
+2191
+5466
+4285
+3448
+5647
+5676
+2408
+5250
+5040
+2786
+
+4785
+2699
+5313
+6423
+6941
+1720
+2175
+5572
+1407
+7206
+7001
+4747
+
+13534
+11997
+2579
+1370
+8863
+
+3117
+2505
+4550
+5786
+2754
+1081
+5513
+2703
+4851
+3010
+2277
+4310
+1995
+4859
+
+3098
+10737
+9148
+4205
+3168
+5815
+
+24466
+11453
+
+11075
+2307
+4451
+8040
+2823
+1511
+2199
+
+9249
+7619
+10603
+10410
+2879
+3137
+4180
+1117
+
+5318
+31966
+
+2253
+4304
+1764
+4286
+2565
+6037
+1889
+2801
+2604
+1826
+2382
+3893
+2637
+5868
+1702
+
+1051
+3794
+5326
+8736
+11783
+7745
+9739
+
+11430
+6028
+3640
+11298
+6637
+7012
+
+18452
+
+6838
+2890
+7111
+5244
+1308
+3316
+4583
+3594
+3786
+7871
+4496
+
+5362
+1161
+6049
+2095
+1899
+2440
+2899
+1399
+5217
+3531
+4248
+5083
+1377
+3671
+4222
+
+13935
+5676
+14362
+15773
+11473
+
+8266
+8005
+6767
+8825
+6432
+6358
+1952
+5685
+5867
+
+6249
+6107
+4509
+6066
+6204
+4054
+1040
+4447
+1325
+5283
+4176
+2281
+1895
diff --git a/2022/day01/main.rs b/2022/day01/main.rs
@@ -0,0 +1,33 @@
+use std::cmp::Reverse;
+use std::collections::BinaryHeap;
+
+fn main() {
+    let input = std::fs::read_to_string("input.txt")
+        .unwrap()
+        .trim()
+        .split("\n\n")
+        .map(|x| x.split('\n').map(|x| x.parse::<i32>().unwrap()).collect())
+        .collect::<Vec<Vec<i32>>>();
+    // 71934
+    println!("Part 1: {}", part_1(&input));
+    // 211447
+    println!("Part 2: {}", part_2(&input, 3));
+}
+
+fn part_1(input: &Vec<Vec<i32>>) -> i32 {
+    (1..input.len())
+        .map(|i| input[i].iter().sum())
+        .max()
+        .unwrap()
+}
+
+fn part_2(input: &Vec<Vec<i32>>, top_count: usize) -> i32 {
+    let mut top = BinaryHeap::new();
+    for s in (1..input.len()).map(|i| input[i].iter().sum::<i32>()) {
+        top.push(Reverse(s));
+        while top.len() > top_count {
+            top.pop();
+        }
+    }
+    top.iter().map(|r| r.0).sum()
+}