summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--1.in2000
-rw-r--r--1.py5
-rw-r--r--utils.py15
3 files changed, 2020 insertions, 0 deletions
diff --git a/1.in b/1.in
new file mode 100644
index 0000000..94adc1c
--- /dev/null
+++ b/1.in
@@ -0,0 +1,2000 @@
+173
+179
+200
+210
+226
+229
+220
+221
+228
+233
+237
+238
+249
+261
+284
+285
+287
+289
+291
+284
+285
+279
+295
+313
+314
+315
+317
+318
+316
+344
+345
+347
+352
+356
+352
+379
+384
+389
+392
+394
+395
+401
+424
+429
+432
+446
+454
+464
+459
+455
+467
+501
+509
+523
+526
+529
+535
+557
+559
+562
+564
+572
+573
+576
+584
+586
+588
+587
+588
+594
+598
+599
+600
+602
+604
+609
+626
+633
+641
+642
+649
+655
+658
+661
+681
+683
+685
+684
+685
+687
+691
+694
+696
+697
+705
+706
+710
+740
+741
+749
+740
+744
+749
+750
+753
+759
+754
+736
+731
+732
+722
+720
+732
+745
+754
+769
+771
+772
+766
+768
+778
+780
+768
+771
+775
+804
+809
+810
+806
+808
+818
+813
+801
+804
+813
+817
+836
+827
+833
+836
+840
+860
+865
+877
+843
+845
+871
+872
+874
+885
+900
+904
+906
+909
+911
+910
+919
+932
+938
+954
+961
+962
+964
+979
+980
+992
+997
+1000
+1012
+1017
+1025
+1027
+1028
+1035
+1036
+1052
+1053
+1057
+1068
+1092
+1093
+1104
+1106
+1107
+1112
+1121
+1123
+1126
+1127
+1126
+1132
+1135
+1136
+1138
+1143
+1146
+1148
+1149
+1154
+1172
+1173
+1174
+1175
+1176
+1182
+1183
+1188
+1194
+1195
+1199
+1204
+1208
+1211
+1210
+1190
+1197
+1209
+1210
+1211
+1221
+1240
+1241
+1240
+1244
+1247
+1245
+1249
+1266
+1272
+1280
+1285
+1305
+1308
+1315
+1325
+1328
+1357
+1362
+1363
+1365
+1368
+1366
+1376
+1359
+1378
+1380
+1381
+1375
+1376
+1374
+1375
+1377
+1379
+1380
+1376
+1377
+1391
+1393
+1399
+1412
+1416
+1420
+1427
+1428
+1432
+1434
+1435
+1436
+1439
+1440
+1464
+1458
+1461
+1465
+1467
+1502
+1503
+1500
+1514
+1516
+1533
+1535
+1536
+1517
+1547
+1531
+1532
+1543
+1544
+1546
+1519
+1521
+1522
+1529
+1510
+1518
+1520
+1511
+1486
+1489
+1501
+1484
+1479
+1481
+1485
+1493
+1497
+1498
+1500
+1505
+1512
+1534
+1535
+1539
+1522
+1523
+1531
+1548
+1549
+1550
+1576
+1586
+1583
+1584
+1585
+1599
+1606
+1607
+1609
+1625
+1638
+1643
+1681
+1680
+1688
+1702
+1703
+1705
+1706
+1717
+1716
+1711
+1708
+1719
+1721
+1716
+1728
+1729
+1739
+1765
+1769
+1778
+1779
+1781
+1785
+1786
+1783
+1786
+1787
+1778
+1776
+1797
+1802
+1808
+1811
+1816
+1819
+1818
+1830
+1837
+1839
+1842
+1843
+1845
+1846
+1854
+1842
+1815
+1816
+1829
+1831
+1836
+1842
+1845
+1868
+1869
+1870
+1877
+1879
+1897
+1896
+1897
+1899
+1909
+1912
+1913
+1920
+1919
+1921
+1902
+1921
+1923
+1928
+1935
+1936
+1941
+1944
+1964
+1962
+1971
+1983
+1985
+1987
+2000
+2002
+2005
+2006
+2026
+2024
+2025
+2027
+2029
+2026
+2028
+2029
+2044
+2043
+2047
+2055
+2056
+2068
+2085
+2086
+2096
+2097
+2108
+2105
+2106
+2103
+2098
+2101
+2102
+2107
+2127
+2128
+2131
+2132
+2123
+2126
+2141
+2160
+2163
+2167
+2171
+2179
+2184
+2187
+2198
+2209
+2218
+2219
+2221
+2236
+2239
+2245
+2249
+2268
+2272
+2269
+2270
+2262
+2261
+2263
+2260
+2263
+2265
+2270
+2285
+2286
+2290
+2272
+2259
+2267
+2268
+2283
+2286
+2289
+2290
+2300
+2304
+2305
+2306
+2294
+2295
+2324
+2331
+2345
+2352
+2356
+2357
+2362
+2369
+2377
+2398
+2405
+2397
+2398
+2391
+2394
+2399
+2400
+2411
+2412
+2415
+2416
+2421
+2417
+2395
+2397
+2404
+2414
+2432
+2405
+2406
+2423
+2425
+2427
+2436
+2442
+2443
+2451
+2450
+2451
+2479
+2484
+2491
+2494
+2491
+2480
+2485
+2486
+2487
+2497
+2499
+2526
+2525
+2526
+2528
+2526
+2528
+2532
+2536
+2563
+2566
+2580
+2584
+2595
+2603
+2615
+2620
+2627
+2641
+2645
+2643
+2659
+2664
+2665
+2669
+2671
+2678
+2687
+2688
+2713
+2717
+2729
+2732
+2733
+2732
+2734
+2735
+2737
+2718
+2719
+2720
+2727
+2736
+2738
+2740
+2749
+2743
+2785
+2799
+2800
+2821
+2828
+2829
+2832
+2834
+2852
+2853
+2850
+2863
+2866
+2867
+2865
+2860
+2861
+2869
+2862
+2864
+2862
+2868
+2873
+2881
+2887
+2888
+2891
+2898
+2892
+2901
+2903
+2901
+2906
+2910
+2911
+2922
+2919
+2918
+2912
+2910
+2924
+2921
+2923
+2924
+2931
+2945
+2946
+2918
+2946
+2947
+2951
+2937
+2938
+2940
+2941
+2945
+2960
+2965
+2964
+2965
+2966
+2967
+2979
+3000
+3006
+3008
+3010
+3003
+3009
+3003
+3012
+3026
+3032
+3036
+3041
+3046
+3058
+3059
+3070
+3059
+3056
+3060
+3070
+3078
+3084
+3085
+3089
+3092
+3095
+3078
+3113
+3107
+3109
+3121
+3129
+3118
+3128
+3130
+3131
+3132
+3133
+3132
+3128
+3130
+3149
+3159
+3162
+3172
+3180
+3195
+3196
+3197
+3209
+3214
+3216
+3217
+3218
+3221
+3234
+3236
+3238
+3246
+3212
+3205
+3214
+3243
+3245
+3250
+3252
+3268
+3271
+3270
+3258
+3253
+3264
+3273
+3281
+3282
+3288
+3291
+3300
+3310
+3312
+3331
+3329
+3330
+3331
+3344
+3366
+3367
+3381
+3385
+3386
+3395
+3396
+3397
+3433
+3422
+3433
+3426
+3421
+3422
+3427
+3433
+3439
+3443
+3445
+3442
+3447
+3446
+3449
+3458
+3470
+3473
+3479
+3478
+3480
+3482
+3484
+3495
+3494
+3492
+3499
+3491
+3495
+3506
+3512
+3518
+3523
+3538
+3546
+3554
+3559
+3565
+3580
+3583
+3584
+3591
+3592
+3607
+3609
+3633
+3636
+3634
+3637
+3638
+3642
+3643
+3652
+3653
+3655
+3657
+3656
+3657
+3656
+3677
+3678
+3716
+3727
+3730
+3751
+3752
+3776
+3778
+3775
+3779
+3782
+3783
+3817
+3819
+3822
+3824
+3826
+3841
+3842
+3843
+3864
+3868
+3875
+3880
+3896
+3898
+3899
+3900
+3901
+3907
+3914
+3904
+3908
+3917
+3918
+3919
+3926
+3939
+3945
+3938
+3956
+3967
+3968
+3972
+3975
+3974
+3975
+3976
+3981
+3982
+3983
+3977
+3982
+3987
+3995
+4012
+4025
+4021
+4046
+4048
+4053
+4069
+4078
+4083
+4081
+4080
+4082
+4091
+4099
+4100
+4097
+4109
+4112
+4126
+4127
+4128
+4129
+4130
+4133
+4132
+4136
+4156
+4160
+4161
+4159
+4160
+4161
+4178
+4180
+4197
+4195
+4197
+4199
+4201
+4200
+4196
+4219
+4220
+4221
+4205
+4219
+4224
+4257
+4262
+4263
+4266
+4267
+4266
+4271
+4272
+4273
+4285
+4286
+4285
+4266
+4242
+4248
+4270
+4271
+4293
+4309
+4314
+4340
+4343
+4348
+4347
+4348
+4351
+4352
+4364
+4365
+4388
+4390
+4417
+4410
+4426
+4431
+4429
+4434
+4424
+4432
+4421
+4440
+4441
+4428
+4438
+4456
+4457
+4460
+4468
+4471
+4473
+4490
+4477
+4478
+4486
+4475
+4487
+4490
+4497
+4524
+4533
+4537
+4541
+4545
+4548
+4552
+4556
+4558
+4571
+4573
+4578
+4580
+4581
+4542
+4545
+4548
+4549
+4536
+4551
+4557
+4556
+4547
+4548
+4567
+4552
+4554
+4552
+4576
+4577
+4603
+4616
+4633
+4634
+4639
+4642
+4651
+4656
+4657
+4659
+4663
+4667
+4673
+4695
+4712
+4713
+4720
+4718
+4721
+4737
+4743
+4746
+4778
+4779
+4793
+4768
+4773
+4776
+4778
+4796
+4798
+4800
+4802
+4803
+4822
+4823
+4831
+4836
+4831
+4833
+4840
+4842
+4847
+4868
+4870
+4869
+4875
+4876
+4879
+4881
+4891
+4892
+4909
+4903
+4901
+4902
+4930
+4933
+4932
+4933
+4936
+4937
+4943
+4945
+4948
+4949
+4943
+4963
+4956
+4967
+4969
+4961
+4966
+4970
+4974
+4961
+4964
+4952
+4953
+4981
+4984
+4966
+4970
+4971
+4975
+4966
+4968
+4966
+4968
+4974
+4971
+4988
+4989
+4995
+4996
+5001
+5004
+5005
+5008
+5016
+5018
+5007
+5010
+5011
+5024
+5027
+5032
+5037
+5033
+5034
+5045
+5071
+5068
+5069
+5070
+5088
+5086
+5088
+5114
+5133
+5144
+5145
+5152
+5161
+5154
+5155
+5156
+5159
+5170
+5176
+5189
+5190
+5200
+5204
+5205
+5206
+5221
+5222
+5223
+5224
+5217
+5218
+5219
+5225
+5203
+5210
+5212
+5213
+5215
+5214
+5215
+5221
+5222
+5233
+5242
+5256
+5258
+5256
+5281
+5286
+5315
+5336
+5337
+5345
+5348
+5341
+5336
+5341
+5344
+5350
+5341
+5342
+5337
+5339
+5346
+5347
+5364
+5366
+5368
+5361
+5362
+5365
+5358
+5370
+5376
+5377
+5380
+5381
+5382
+5383
+5388
+5396
+5405
+5396
+5410
+5431
+5432
+5436
+5447
+5456
+5457
+5462
+5475
+5476
+5490
+5493
+5503
+5504
+5512
+5513
+5527
+5542
+5546
+5545
+5547
+5555
+5558
+5577
+5613
+5614
+5620
+5623
+5636
+5651
+5660
+5665
+5668
+5672
+5676
+5687
+5712
+5707
+5708
+5709
+5711
+5712
+5714
+5715
+5717
+5727
+5731
+5746
+5754
+5755
+5758
+5759
+5770
+5775
+5799
+5789
+5794
+5800
+5802
+5813
+5808
+5812
+5832
+5830
+5839
+5842
+5825
+5830
+5835
+5836
+5847
+5851
+5849
+5855
+5816
+5818
+5829
+5830
+5829
+5830
+5858
+5859
+5860
+5862
+5867
+5868
+5863
+5864
+5869
+5872
+5878
+5885
+5888
+5890
+5884
+5875
+5876
+5880
+5886
+5889
+5890
+5892
+5895
+5896
+5895
+5896
+5897
+5895
+5907
+5906
+5908
+5897
+5900
+5913
+5915
+5914
+5917
+5915
+5916
+5920
+5923
+5929
+5931
+5936
+5944
+5929
+5932
+5934
+5945
+5948
+5949
+5951
+5957
+5967
+5968
+5969
+5974
+5975
+5982
+5983
+5990
+5994
+5989
+5993
+5996
+5986
+5987
+5990
+5991
+5993
+5995
+5998
+5999
+5990
+5994
+5996
+6010
+6016
+6032
+6039
+6041
+6044
+6057
+6058
+6059
+6060
+6061
+6063
+6064
+6067
+6073
+6074
+6075
+6070
+6071
+6076
+6077
+6071
+6083
+6088
+6096
+6095
+6100
+6101
+6106
+6109
+6111
+6112
+6121
+6143
+6151
+6175
+6179
+6174
+6175
+6185
+6186
+6184
+6195
+6196
+6197
+6188
+6195
+6196
+6197
+6198
+6204
+6209
+6222
+6233
+6231
+6222
+6223
+6224
+6233
+6235
+6239
+6229
+6259
+6286
+6295
+6269
+6273
+6274
+6265
+6266
+6264
+6259
+6260
+6265
+6268
+6280
+6281
+6283
+6277
+6279
+6311
+6340
+6342
+6345
+6353
+6375
+6399
+6425
+6423
+6428
+6448
+6449
+6456
+6460
+6465
+6470
+6477
+6493
+6494
+6499
+6521
+6522
+6524
+6525
+6536
+6537
+6538
+6526
+6550
+6551
+6552
+6559
+6561
+6563
+6564
+6584
+6585
+6588
+6600
+6610
+6612
+6616
+6619
+6639
+6644
+6646
+6647
+6644
+6629
+6635
+6646
+6648
+6659
+6662
+6641
+6637
+6626
+6627
+6630
+6632
+6643
+6644
+6645
+6656
+6658
+6663
+6680
+6675
+6678
+6681
+6682
+6680
+6692
+6702
+6707
+6708
+6709
+6717
+6719
+6733
+6734
+6730
+6751
+6757
+6766
+6770
+6810
+6812
+6816
+6810
+6817
+6821
+6823
+6828
+6844
+6838
+6841
+6846
+6843
+6844
+6848
+6851
+6853
+6868
+6870
+6884
+6886
+6896
+6886
+6887
+6891
+6896
+6905
+6902
+6903
+6902
+6911
+6951
+6955
+6958
+6940
+6943
+6945
+6946
+6945
+6943
+6944
+6949
+6950
+6952
+6953
+6958
+6962
+6970
+6974
+6977
+7018
+7023
+7027
+7029
+7031
+7033
+7035
+7057
+7058
+7060
+7071
+7072
+7087
+7102
+7111
+7138
+7118
+7136
+7142
+7143
+7162
+7163
+7166
+7153
+7152
+7151
+7154
+7156
+7178
+7177
+7184
+7188
+7193
+7198
+7205
+7217
+7248
+7247
+7249
+7251
+7253
+7254
+7255
+7263
+7265
+7280
+7287
+7315
+7323
+7332
+7333
+7323
+7324
+7332
+7334
+7338
+7339
+7341
+7347
+7346
+7347
+7365
+7370
+7372
+7373
+7374
+7376
+7381
+7383
+7401
+7402
+7421
+7433
+7438
+7439
+7440
+7476
+7484
+7504
+7510
+7526
+7527
+7531
+7532
+7539
+7542
+7553
+7555
+7560
+7558
+7560
+7562
+7578
+7581
+7587
+7599
+7600
+7616
+7627
+7645
+7658
+7659
+7646
+7648
+7652
+7650
+7651
+7667
+7671
+7675
+7682
+7683
+7684
+7687
+7686
+7688
+7699
+7710
+7699
+7698
+7699
+7706
+7724
+7725
+7740
+7741
+7740
+7741
+7747
+7742
+7749
+7758
+7769
+7770
+7785
+7793
+7794
+7797
+7805
+7806
+7826
+7827
+7828
+7826
+7827
+7837
+7843
+7852
+7867
+7874
+7881
+7875
+7874
+7873
+7887
+7890
+7919
+7918
+7926
+7935
+7936
+7935
+7941
+7942
+7940
+7949
+7958
+7960
+7963
+7961
+7963
+7965
+7960
+7983
+7980
+7984
+7986
+7988
+8000
+8009
+8014
+8013
+8014
+8015
+8022
+8023
+8020
+8035
+8046
+8053
+8050
+8046
+8057
+8056
+8085
+8086
+8087
+8088
+8092
+8094
+8095
+8094
+8096
+8099
+8128
+8159
+8167
+8185
+8200
+8212
+8214
+8219
+8246
+8248
+8261
+8262
+8242
+8236
+8237
+8247
+8243
+8242
+8244
+8256
+8268
+8270
+8311
+8323
+8324
+8325
+8327
+8349
+8347
+8348
+8347
+8353
+8366
+8384
+8386
+8389
+8404
+8405
+8408
+8411
+8415
+8428
+8437
+8423
+8427
+8455
+8463
+8466
+8470
+8471
+8475
+8476
+8479
+8484
+8483
+8486
+8485
+8498
+8502
+8503
+8507
+8517
+8518
+8531
+8532
+8545
+8548
+8561
+8569
+8573
+8575
+8580
+8581
+8585
+8589
+8598
+8604
+8630
+8628
+8625
+8620
+8625
+8626
+8627
+8620
+8631
+8643
+8645
+8669
+8673
+8674
+8679
+8687
+8698
+8731
+8738
+8746
+8785
+8760
+8764
+8760
+8761
+8767
+8768
+8769
+8771
+8773
+8768
+8766
+8767
+8785
+8789
+8790
+8802
+8801
+8802
+8809
+8820
+8823
+8824
+8829
+8830
+8836
+8835
+8834
+8828
+8829
+8833
+8844
+8852
+8857
+8863
+8862
+8863
+8853
+8858
+8859
+8860
+8845
+8844
+8823
+8822
+8850
+8851
+8852
+8863
+8879
+8881
+8882
+8889
+8892
+8894
+8910
+8908
+8912
+8933
+8932
+8911
+8906
+8908
+8909
+8919
+8920
+8921
+8933
+8935
+8945
+8947
+8948
+8951
+8961
+8962
+8972
+8989
+8990
+8999
+9000
+9018
+9028
+9029
+9035
+9031
+9043
+9044
+9049
+9078
+9074
+9078
+9081
+9074
+9077
+9071
+9054
+9055
+9060
+9062
+9065
+9094
+9099
+9108
+9125
+9136
+9137
+9143
+9147
+9150
+9162
+9166
+9170
+9171
+9174
+9188
+9198
+9204
+9207
+9217
+9230
+9243
+9256
+9264
+9273
+9275
+9286
+9293
+9299
+9300
+9317
+9320
+9324
+9348
+9351
+9356
+9372
+9380
diff --git a/1.py b/1.py
new file mode 100644
index 0000000..f439f46
--- /dev/null
+++ b/1.py
@@ -0,0 +1,5 @@
+from utils import sliding_window
+
+inp: list[int] = [int(l.strip()) for l in open('1.in')]
+print(sum(s[1] > s[0] for s in sliding_window(inp, 2)))
+print(sum(s[3] > s[0] for s in sliding_window(inp, 4)))
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..d322ed0
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,15 @@
+from collections import deque
+from collections.abc import Iterable, Iterator, Generator
+from itertools import islice
+from typing import TypeVar
+
+T = TypeVar('T')
+def sliding_window(iterable: Iterable[T], n: int) -> Generator[tuple[T, ...], None, None]:
+ # sliding_window('ABCDEFG', 4) -> ABCD BCDE CDEF DEFG
+ it: Iterator[T] = iter(iterable)
+ window: deque[T] = deque(islice(it, n), maxlen=n)
+ if len(window) == n:
+ yield tuple(window)
+ for x in it:
+ window.append(x)
+ yield tuple(window)