commit 1a536e08d9b7cd194b3745a2d7c151542455a9c4
parent 21f409f22902654682d5e3852ddeffa0e700bd38
Author: Shimmy Xu <shimmy.xu@shimmy1996.com>
Date: Thu, 2 Dec 2021 20:47:22 -0600
Add 2021 day 01
Diffstat:
2 files changed, 2020 insertions(+), 0 deletions(-)
diff --git a/2021/day01/input.txt b/2021/day01/input.txt
@@ -0,0 +1,2000 @@
+169
+150
+158
+163
+167
+151
+152
+153
+154
+159
+168
+176
+182
+183
+188
+182
+183
+184
+185
+195
+199
+198
+196
+211
+212
+202
+203
+208
+205
+204
+205
+226
+208
+191
+193
+195
+199
+200
+198
+200
+199
+214
+241
+247
+242
+238
+227
+228
+236
+238
+242
+246
+248
+236
+243
+259
+261
+262
+265
+264
+273
+277
+279
+275
+279
+295
+290
+296
+288
+285
+297
+296
+311
+321
+346
+351
+361
+391
+395
+401
+397
+410
+415
+417
+422
+400
+396
+425
+421
+426
+427
+429
+430
+462
+461
+462
+467
+475
+479
+481
+483
+487
+494
+496
+511
+510
+511
+514
+524
+530
+532
+522
+505
+516
+502
+489
+488
+501
+503
+479
+500
+503
+507
+514
+522
+532
+533
+535
+540
+541
+545
+530
+526
+520
+521
+522
+530
+525
+511
+525
+528
+525
+528
+530
+534
+536
+563
+565
+577
+578
+586
+596
+598
+601
+593
+618
+619
+615
+612
+621
+623
+619
+622
+623
+618
+634
+640
+647
+639
+662
+679
+680
+673
+676
+664
+653
+652
+653
+656
+671
+674
+682
+684
+688
+689
+691
+687
+695
+692
+701
+699
+700
+704
+708
+706
+734
+733
+732
+722
+734
+733
+739
+738
+757
+743
+747
+759
+755
+754
+767
+774
+772
+771
+789
+803
+819
+821
+831
+827
+830
+833
+836
+808
+806
+809
+827
+834
+844
+873
+883
+875
+874
+875
+876
+874
+875
+864
+861
+863
+866
+878
+840
+851
+862
+880
+881
+882
+894
+893
+905
+902
+912
+927
+922
+900
+920
+909
+910
+909
+907
+908
+912
+942
+941
+944
+945
+939
+961
+965
+933
+935
+934
+933
+912
+913
+914
+919
+926
+920
+931
+932
+933
+920
+922
+921
+920
+919
+920
+923
+932
+930
+918
+914
+908
+923
+938
+952
+946
+951
+953
+952
+957
+966
+964
+963
+961
+962
+961
+991
+995
+1015
+1013
+1025
+1023
+1019
+1021
+1041
+1048
+1053
+1047
+1061
+1060
+1088
+1092
+1096
+1098
+1116
+1085
+1082
+1069
+1068
+1069
+1067
+1072
+1077
+1093
+1084
+1102
+1093
+1099
+1082
+1097
+1096
+1101
+1088
+1089
+1077
+1058
+1068
+1071
+1072
+1083
+1074
+1087
+1094
+1093
+1094
+1095
+1099
+1100
+1102
+1104
+1107
+1102
+1104
+1093
+1104
+1101
+1115
+1122
+1121
+1098
+1097
+1094
+1124
+1123
+1120
+1118
+1123
+1125
+1097
+1098
+1101
+1072
+1068
+1067
+1093
+1095
+1100
+1108
+1097
+1115
+1125
+1126
+1128
+1151
+1152
+1151
+1150
+1163
+1162
+1159
+1162
+1158
+1162
+1153
+1145
+1144
+1155
+1165
+1156
+1161
+1151
+1152
+1149
+1150
+1152
+1153
+1157
+1148
+1147
+1140
+1151
+1157
+1154
+1153
+1166
+1163
+1173
+1174
+1173
+1198
+1199
+1208
+1212
+1213
+1200
+1213
+1215
+1214
+1216
+1232
+1205
+1215
+1216
+1241
+1240
+1238
+1244
+1250
+1244
+1246
+1256
+1264
+1263
+1265
+1260
+1259
+1269
+1258
+1262
+1259
+1260
+1263
+1234
+1240
+1242
+1246
+1245
+1227
+1228
+1229
+1210
+1213
+1214
+1216
+1213
+1200
+1206
+1220
+1219
+1189
+1193
+1184
+1183
+1179
+1184
+1189
+1175
+1176
+1177
+1186
+1187
+1192
+1199
+1227
+1225
+1226
+1232
+1233
+1232
+1239
+1256
+1251
+1267
+1273
+1263
+1260
+1241
+1257
+1258
+1260
+1259
+1268
+1296
+1294
+1302
+1304
+1297
+1289
+1294
+1291
+1261
+1257
+1260
+1268
+1275
+1295
+1301
+1306
+1307
+1311
+1310
+1298
+1305
+1306
+1305
+1296
+1282
+1285
+1304
+1306
+1309
+1307
+1313
+1318
+1315
+1318
+1314
+1307
+1306
+1285
+1287
+1288
+1289
+1290
+1291
+1292
+1293
+1295
+1305
+1321
+1320
+1305
+1299
+1301
+1309
+1316
+1327
+1325
+1327
+1333
+1318
+1338
+1341
+1338
+1355
+1351
+1347
+1345
+1348
+1361
+1368
+1364
+1355
+1351
+1339
+1338
+1341
+1346
+1343
+1342
+1343
+1342
+1339
+1341
+1342
+1352
+1382
+1386
+1397
+1399
+1376
+1378
+1379
+1380
+1382
+1359
+1356
+1372
+1385
+1380
+1375
+1373
+1371
+1376
+1363
+1369
+1372
+1370
+1388
+1389
+1393
+1386
+1380
+1382
+1387
+1398
+1402
+1409
+1415
+1419
+1429
+1445
+1425
+1434
+1432
+1433
+1432
+1433
+1465
+1466
+1460
+1473
+1470
+1475
+1476
+1483
+1480
+1467
+1463
+1468
+1466
+1467
+1466
+1467
+1459
+1461
+1485
+1487
+1488
+1490
+1462
+1477
+1481
+1491
+1506
+1505
+1506
+1518
+1517
+1523
+1531
+1515
+1505
+1506
+1504
+1507
+1513
+1529
+1533
+1538
+1535
+1565
+1566
+1577
+1578
+1601
+1598
+1597
+1585
+1580
+1581
+1574
+1577
+1573
+1608
+1609
+1612
+1621
+1629
+1630
+1636
+1645
+1649
+1664
+1668
+1674
+1676
+1675
+1674
+1666
+1668
+1671
+1690
+1704
+1698
+1702
+1703
+1715
+1689
+1686
+1680
+1683
+1697
+1696
+1689
+1688
+1694
+1693
+1694
+1715
+1714
+1718
+1717
+1713
+1711
+1712
+1748
+1749
+1757
+1756
+1758
+1763
+1762
+1760
+1762
+1744
+1730
+1723
+1736
+1733
+1757
+1745
+1752
+1748
+1755
+1754
+1761
+1753
+1741
+1740
+1739
+1759
+1747
+1748
+1758
+1770
+1768
+1783
+1776
+1760
+1747
+1754
+1753
+1765
+1767
+1757
+1756
+1758
+1757
+1760
+1769
+1767
+1769
+1782
+1786
+1799
+1796
+1793
+1797
+1808
+1811
+1805
+1804
+1797
+1801
+1791
+1796
+1791
+1795
+1792
+1793
+1822
+1827
+1823
+1839
+1831
+1847
+1851
+1852
+1857
+1846
+1850
+1841
+1842
+1845
+1846
+1847
+1846
+1848
+1849
+1852
+1851
+1852
+1850
+1849
+1850
+1849
+1848
+1864
+1879
+1889
+1900
+1915
+1905
+1899
+1900
+1916
+1917
+1916
+1893
+1914
+1927
+1926
+1923
+1926
+1939
+1936
+1915
+1926
+1942
+1943
+1944
+1935
+1934
+1936
+1937
+1936
+1932
+1936
+1943
+1954
+1953
+1958
+1951
+1959
+1958
+1957
+1958
+1959
+1957
+1963
+1973
+1976
+1991
+1995
+2023
+2027
+2034
+2037
+2039
+2040
+2024
+2033
+2034
+2027
+2029
+2046
+2069
+2071
+2078
+2083
+2082
+2093
+2092
+2096
+2075
+2041
+2038
+2062
+2059
+2060
+2061
+2070
+2084
+2079
+2071
+2069
+2059
+2061
+2062
+2065
+2064
+2080
+2081
+2089
+2074
+2075
+2076
+2089
+2093
+2085
+2086
+2080
+2065
+2093
+2102
+2101
+2097
+2109
+2113
+2121
+2122
+2121
+2120
+2147
+2144
+2152
+2145
+2146
+2171
+2159
+2160
+2162
+2166
+2162
+2164
+2158
+2156
+2157
+2159
+2177
+2183
+2174
+2173
+2176
+2179
+2172
+2171
+2154
+2177
+2141
+2142
+2156
+2142
+2145
+2137
+2138
+2151
+2155
+2156
+2155
+2140
+2145
+2120
+2108
+2117
+2124
+2133
+2138
+2137
+2105
+2067
+2077
+2074
+2068
+2071
+2072
+2068
+2069
+2077
+2072
+2075
+2083
+2114
+2116
+2113
+2112
+2131
+2124
+2130
+2129
+2130
+2134
+2136
+2135
+2142
+2171
+2127
+2129
+2140
+2149
+2162
+2161
+2165
+2140
+2168
+2170
+2171
+2177
+2193
+2195
+2200
+2207
+2209
+2210
+2216
+2214
+2217
+2214
+2226
+2235
+2238
+2240
+2245
+2246
+2248
+2258
+2291
+2293
+2295
+2294
+2276
+2307
+2308
+2327
+2328
+2307
+2305
+2306
+2312
+2313
+2322
+2320
+2338
+2354
+2359
+2361
+2362
+2365
+2362
+2350
+2349
+2348
+2341
+2345
+2341
+2338
+2315
+2313
+2316
+2324
+2322
+2325
+2331
+2327
+2333
+2335
+2334
+2335
+2321
+2307
+2305
+2292
+2261
+2262
+2265
+2310
+2311
+2331
+2325
+2316
+2319
+2325
+2331
+2328
+2327
+2340
+2302
+2306
+2307
+2308
+2310
+2311
+2337
+2336
+2321
+2318
+2319
+2311
+2312
+2325
+2326
+2327
+2325
+2317
+2327
+2315
+2314
+2317
+2340
+2341
+2343
+2345
+2343
+2339
+2337
+2339
+2350
+2329
+2331
+2348
+2349
+2357
+2350
+2343
+2339
+2340
+2342
+2329
+2328
+2340
+2332
+2331
+2315
+2321
+2320
+2319
+2321
+2322
+2312
+2313
+2328
+2347
+2346
+2347
+2337
+2341
+2338
+2343
+2342
+2332
+2335
+2343
+2365
+2362
+2364
+2352
+2353
+2354
+2346
+2348
+2351
+2352
+2355
+2350
+2351
+2339
+2360
+2365
+2364
+2366
+2369
+2368
+2366
+2372
+2362
+2370
+2371
+2370
+2371
+2377
+2376
+2381
+2380
+2379
+2362
+2355
+2370
+2376
+2372
+2364
+2363
+2360
+2356
+2348
+2338
+2340
+2341
+2349
+2346
+2339
+2338
+2330
+2333
+2328
+2316
+2314
+2324
+2338
+2341
+2318
+2321
+2346
+2347
+2317
+2321
+2315
+2324
+2326
+2333
+2347
+2348
+2333
+2345
+2352
+2353
+2352
+2355
+2358
+2359
+2367
+2369
+2375
+2365
+2358
+2371
+2374
+2386
+2416
+2418
+2416
+2408
+2409
+2442
+2443
+2446
+2453
+2444
+2490
+2493
+2498
+2493
+2488
+2494
+2495
+2506
+2505
+2508
+2513
+2509
+2502
+2500
+2498
+2515
+2513
+2514
+2513
+2524
+2525
+2534
+2530
+2547
+2530
+2524
+2527
+2523
+2522
+2526
+2528
+2527
+2528
+2547
+2530
+2527
+2530
+2528
+2511
+2493
+2520
+2512
+2490
+2482
+2476
+2456
+2455
+2451
+2452
+2435
+2436
+2425
+2426
+2430
+2441
+2445
+2438
+2445
+2440
+2446
+2445
+2446
+2434
+2433
+2414
+2435
+2434
+2432
+2415
+2384
+2386
+2387
+2400
+2402
+2392
+2388
+2394
+2396
+2377
+2354
+2358
+2370
+2371
+2367
+2368
+2382
+2381
+2385
+2395
+2381
+2356
+2332
+2334
+2348
+2355
+2354
+2371
+2367
+2365
+2374
+2372
+2371
+2374
+2371
+2363
+2375
+2376
+2377
+2418
+2436
+2451
+2435
+2424
+2427
+2459
+2474
+2471
+2469
+2475
+2486
+2491
+2493
+2486
+2472
+2474
+2475
+2472
+2465
+2430
+2442
+2444
+2442
+2443
+2442
+2450
+2451
+2463
+2456
+2445
+2436
+2456
+2464
+2456
+2462
+2463
+2462
+2464
+2468
+2477
+2481
+2482
+2479
+2489
+2494
+2493
+2504
+2505
+2509
+2485
+2484
+2473
+2501
+2512
+2511
+2514
+2511
+2512
+2536
+2543
+2545
+2533
+2535
+2530
+2536
+2544
+2552
+2553
+2557
+2555
+2565
+2561
+2558
+2556
+2555
+2573
+2575
+2576
+2561
+2565
+2566
+2538
+2529
+2530
+2529
+2530
+2538
+2549
+2555
+2556
+2562
+2561
+2562
+2560
+2557
+2576
+2579
+2596
+2598
+2599
+2601
+2612
+2648
+2649
+2648
+2647
+2645
+2642
+2638
+2651
+2658
+2657
+2664
+2663
+2653
+2654
+2662
+2663
+2661
+2660
+2655
+2644
+2645
+2646
+2652
+2663
+2657
+2661
+2655
+2659
+2662
+2675
+2677
+2678
+2688
+2687
+2679
+2678
+2685
+2689
+2691
+2702
+2692
+2691
+2694
+2709
+2712
+2710
+2711
+2709
+2708
+2707
+2711
+2714
+2715
+2729
+2733
+2720
+2723
+2729
+2734
+2698
+2690
+2693
+2688
+2704
+2710
+2717
+2718
+2716
+2730
+2771
+2761
+2777
+2778
+2776
+2777
+2779
+2794
+2795
+2796
+2799
+2807
+2816
+2818
+2819
+2814
+2816
+2824
+2848
+2844
+2838
+2835
+2836
+2849
+2851
+2852
+2856
+2859
+2862
+2863
+2867
+2866
+2878
+2884
+2883
+2892
+2898
+2897
+2896
+2908
+2901
+2886
+2885
+2899
+2897
+2900
+2898
+2894
+2924
+2898
+2903
+2898
+2900
+2909
+2908
+2907
+2895
+2924
+2933
+2916
+2914
+2901
+2895
+2897
+2903
+2907
+2898
+2899
+2905
+2906
+2905
+2906
+2897
+2905
+2909
+2908
+2914
+2915
+2907
+2911
+2919
+2926
+2927
+2953
+2963
+2966
+2967
+2984
+2997
+2996
+3003
+2996
+3007
+3008
+3012
+3029
+3028
+3031
+3029
+3030
+3031
+3003
+2999
+3013
+3005
+2984
+2997
+2996
+2997
+3003
+2990
+2989
+2990
+2993
+2992
+2996
+3005
+3009
+3008
+3026
+3029
+3024
+3035
+3039
+3057
+3058
+3059
+3053
+3063
+3062
+3065
+3069
+3071
+3063
+3064
+3066
+3080
+3079
+3077
+3099
+3098
+3099
+3102
+3105
+3108
+3114
+3102
+3103
+3105
+3075
+3076
+3085
+3086
+3088
+3086
+3078
+3079
+3076
+3070
+3076
+3078
+3091
+3092
+3100
+3103
+3105
+3095
+3101
+3106
+3095
+3098
+3102
+3103
+3104
+3106
+3113
+3112
+3114
+3111
+3128
+3132
+3129
+3127
+3131
+3139
+3142
+3143
+3145
+3152
+3163
+3153
+3150
+3153
+3168
+3165
+3157
+3179
+3178
+3166
+3164
+3165
+3180
+3182
+3180
+3184
+3190
+3191
+3192
+3176
+3189
+3191
+3183
+3185
+3203
+3213
+3212
+3207
+3208
+3205
+3197
+3191
+3192
+3196
+3198
+3215
+3196
+3197
+3173
+3170
+3176
+3194
+3212
+3213
+3214
+3224
+3223
+3230
+3244
+3245
+3249
+3250
+3264
+3263
+3265
+3266
+3263
+3265
+3267
+3279
+3278
+3257
+3255
+3287
+3288
+3313
+3311
+3310
+3308
+3311
+3315
+3327
+3304
+3303
+3324
+3325
+3324
+3325
+3337
+3344
+3341
+3345
+3344
+3343
+3339
+3334
+3332
+3331
+3326
+3325
+3326
+3336
+3332
+3333
+3349
+3348
+3349
+3348
+3349
+3353
+3363
+3362
+3377
+3374
+3378
+3351
+3360
+3379
+3386
+3376
+3368
+3365
+3364
+3379
+3387
+3386
+3393
+3383
+3354
+3359
+3361
+3366
+3368
+3365
+3369
+3388
+3431
+3433
+3432
+3429
+3430
+3431
+3426
+3427
+3431
+3424
+3443
+3441
+3440
+3447
+3458
+3439
+3437
+3436
+3429
+3430
+3440
+3454
+3448
+3463
+3460
+3461
+3462
+3463
+3461
+3482
+3492
+3491
+3492
+3498
+3504
+3487
+3490
+3483
+3484
+3477
+3486
+3481
+3480
+3490
+3498
+3502
+3501
+3480
+3481
+3489
+3488
+3492
+3475
+3485
+3483
+3480
+3481
+3473
+3478
+3466
+3465
+3471
+3482
+3481
+3490
+3501
+3500
+3503
+3497
+3501
+3496
+3472
+3479
+3463
+3454
+3463
+3458
+3436
+3469
+3460
+3461
+3462
+3464
+3454
+3453
+3448
+3449
+3445
+3447
+3449
+3451
+3450
+3464
+3470
+3471
+3472
+3482
+3487
+3489
+3482
+3481
+3496
+3501
+3503
+3498
+3497
+3499
+3527
+3530
+3524
+3504
+3494
+3499
+3497
+3489
+3507
+3512
+3535
+3536
+3525
+3536
+3554
+3535
+3534
+3535
+3537
+3541
+3542
+3541
+3543
+3540
+3542
+3539
+3549
+3547
+3535
+3532
+3539
+3540
+3557
+3558
+3575
+3576
+3586
+3588
diff --git a/2021/day01/main.rs b/2021/day01/main.rs
@@ -0,0 +1,20 @@
+fn main() {
+ let input = std::fs::read_to_string("input.txt")
+ .unwrap()
+ .trim()
+ .split('\n')
+ .map(|x| x.parse().unwrap())
+ .collect::<Vec<i32>>();
+ // 1226
+ println!("Part 1: {}", part_1(&input));
+ // 1252
+ println!("Part 2: {}", part_2(&input, 3));
+}
+
+fn part_1(input: &Vec<i32>) -> i32 {
+ (1..input.len()).fold(0, |acc, i| acc + (input[i] > input[i - 1]) as i32)
+}
+
+fn part_2(input: &Vec<i32>, window_size: usize) -> i32 {
+ (window_size..input.len()).fold(0, |acc, i| acc + (input[i] > input[i - window_size]) as i32)
+}