ojuaf
: ojuaf
ojuaf |
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
def load_input():
data = list()
with open('input') as fd:
for line in fd:
value = line.strip()
data.append(int(value))
return data
def main():
data = load_input()
# First task
count = 0
for i in range(len(data)-1):
if data[i+1] - data[i] > 0:
count += 1
result = count
print("Result 1: ", result)
# Second Task
count = 0
for i in range(len(data)-3):
if data[i+3] - data[i] > 0:
count += 1
result = count
print("Result 1: ", result)
return 0
if __name__ == '__main__':
main()
173
175
171
177
179
177
174
177
178
185
189
195
194
211
227
226
227
221
224
227
228
231
232
229
226
244
252
251
258
269
263
255
259
261
232
231
241
244
245
278
258
259
273
272
281
284
288
303
306
312
313
325
327
332
335
345
346
328
329
327
330
325
326
325
351
352
353
363
364
382
402
401
380
370
371
348
359
357
366
386
401
387
388
404
409
430
435
441
475
469
475
473
478
510
507
508
510
502
500
512
517
521
519
532
533
537
538
540
541
545
556
548
543
549
561
562
563
562
561
572
574
575
568
569
570
579
591
590
602
601
581
583
593
590
591
577
576
579
581
563
559
563
564
567
569
570
582
579
601
598
583
589
591
597
611
618
621
622
641
657
658
661
631
633
646
647
652
667
670
676
680
681
683
681
687
690
683
687
690
695
691
693
696
695
700
697
696
700
713
696
693
698
701
700
699
690
692
693
696
722
744
746
758
763
768
782
776
777
787
797
800
801
789
814
815
812
790
791
790
804
813
841
845
844
848
855
847
855
858
859
858
860
867
868
869
877
887
888
895
896
904
905
907
923
932
944
945
950
955
965
990
1019
1017
1025
1040
1041
1066
1060
1033
1034
1047
1057
1060
1061
1068
1071
1080
1081
1090
1096
1097
1098
1099
1093
1096
1100
1101
1112
1118
1119
1121
1123
1125
1126
1152
1155
1149
1161
1166
1178
1181
1182
1189
1190
1176
1169
1183
1196
1183
1205
1207
1198
1200
1186
1172
1162
1177
1179
1175
1163
1164
1170
1168
1171
1173
1172
1174
1175
1172
1173
1167
1169
1173
1176
1177
1178
1179
1181
1185
1186
1196
1183
1181
1176
1190
1200
1216
1240
1238
1234
1224
1247
1257
1258
1246
1233
1234
1223
1229
1231
1232
1231
1232
1249
1255
1254
1257
1268
1298
1300
1302
1325
1337
1339
1345
1348
1336
1341
1342
1343
1344
1343
1336
1351
1360
1362
1359
1357
1358
1364
1370
1372
1373
1374
1378
1409
1390
1398
1410
1411
1417
1418
1431
1450
1451
1452
1456
1468
1469
1472
1475
1465
1469
1453
1457
1458
1474
1464
1454
1457
1460
1467
1469
1470
1455
1456
1468
1476
1498
1502
1500
1514
1522
1529
1528
1516
1511
1516
1521
1503
1523
1498
1515
1527
1526
1527
1556
1567
1586
1607
1616
1615
1611
1612
1621
1599
1600
1601
1625
1632
1633
1628
1656
1644
1646
1669
1671
1675
1676
1682
1681
1658
1657
1671
1669
1668
1669
1670
1691
1708
1709
1708
1724
1731
1738
1748
1766
1767
1769
1756
1757
1758
1759
1760
1773
1775
1777
1780
1782
1793
1813
1795
1796
1798
1797
1804
1806
1811
1812
1813
1818
1822
1829
1824
1814
1811
1806
1825
1844
1847
1837
1841
1844
1836
1825
1828
1841
1846
1839
1840
1847
1856
1869
1870
1871
1879
1884
1890
1888
1859
1861
1873
1870
1871
1876
1885
1886
1887
1888
1887
1895
1888
1889
1891
1890
1884
1885
1854
1857
1860
1841
1837
1838
1841
1859
1863
1865
1866
1864
1853
1855
1865
1867
1875
1876
1877
1880
1877
1876
1886
1894
1901
1903
1910
1901
1903
1905
1911
1913
1928
1938
1940
1946
1956
1951
1953
1955
1961
1957
1960
1967
1966
1970
1976
1979
1980
1979
1967
1974
1980
1974
1975
1976
2005
2012
2015
2022
2023
2024
2018
2017
2024
2041
2042
2043
2074
2075
2077
2084
2090
2091
2096
2097
2100
2103
2090
2063
2081
2082
2079
2095
2093
2095
2103
2084
2093
2098
2116
2123
2124
2123
2117
2115
2120
2121
2132
2138
2146
2158
2162
2163
2167
2177
2178
2183
2178
2198
2174
2187
2196
2221
2224
2228
2232
2237
2238
2257
2262
2263
2266
2280
2287
2293
2280
2281
2289
2290
2289
2291
2307
2316
2322
2321
2320
2335
2339
2345
2348
2357
2360
2361
2367
2375
2380
2382
2389
2398
2384
2388
2390
2367
2369
2371
2366
2370
2371
2379
2364
2365
2368
2369
2370
2377
2378
2390
2392
2398
2402
2393
2404
2417
2441
2446
2453
2459
2462
2463
2464
2476
2477
2481
2482
2483
2477
2481
2489
2500
2504
2491
2490
2487
2474
2475
2476
2478
2489
2491
2498
2501
2513
2514
2532
2546
2547
2553
2559
2562
2580
2588
2590
2602
2601
2608
2613
2616
2623
2626
2651
2652
2654
2650
2651
2654
2658
2657
2660
2654
2668
2669
2662
2665
2647
2660
2670
2672
2680
2677
2678
2677
2684
2677
2678
2684
2702
2703
2707
2727
2728
2738
2739
2738
2757
2759
2766
2771
2775
2788
2790
2794
2797
2800
2798
2801
2800
2802
2803
2804
2831
2820
2821
2824
2827
2813
2816
2826
2827
2829
2834
2835
2841
2849
2854
2855
2867
2877
2894
2900
2918
2917
2898
2899
2901
2902
2903
2901
2919
2920
2931
2939
2945
2946
2934
2936
2947
2956
2955
2958
2946
2947
2951
2955
2957
2960
2964
2965
2974
2976
2992
3009
3014
3015
2997
2996
3003
3000
3006
3026
3019
3031
3012
3013
3020
3010
3014
3018
3019
3031
3007
3017
3018
3031
3033
3025
3037
3039
3033
3000
3001
3003
3014
3016
3034
3033
3035
3038
3040
3038
3020
3018
3020
3021
3039
3043
3034
3036
3043
3059
3074
3076
3090
3096
3103
3101
3102
3113
3114
3115
3119
3127
3146
3140
3145
3146
3147
3151
3152
3153
3154
3144
3149
3157
3163
3172
3175
3180
3206
3207
3212
3215
3211
3212
3220
3229
3230
3226
3227
3256
3296
3299
3301
3303
3301
3302
3308
3324
3323
3313
3314
3317
3318
3317
3330
3358
3360
3369
3363
3368
3371
3377
3381
3385
3382
3379
3381
3383
3385
3386
3389
3388
3392
3396
3393
3391
3393
3394
3398
3400
3403
3404
3408
3424
3425
3426
3424
3415
3417
3420
3439
3442
3447
3454
3478
3480
3477
3478
3470
3472
3477
3476
3477
3479
3509
3519
3542
3547
3548
3564
3565
3569
3570
3584
3591
3590
3589
3598
3603
3605
3609
3608
3628
3624
3644
3652
3654
3648
3650
3652
3659
3661
3675
3676
3690
3692
3699
3700
3702
3703
3706
3715
3719
3720
3725
3721
3730
3722
3740
3750
3751
3752
3761
3763
3778
3777
3778
3780
3777
3794
3793
3792
3802
3803
3806
3817
3814
3823
3824
3825
3826
3831
3834
3835
3844
3856
3857
3864
3879
3904
3906
3923
3933
3935
3934
3935
3937
3935
3944
3941
3936
3937
3935
3936
3935
3937
3938
3949
3950
3949
3952
3953
3980
3989
3990
3991
3992
3988
3993
4003
3969
3959
3964
3973
3981
3987
3986
3975
3982
3981
3983
3981
3984
3992
3991
3984
3999
4003
4004
3996
3992
4035
4043
4042
4034
4027
4051
4052
4048
4051
4049
4060
4059
4062
4061
4063
4062
4053
4056
4067
4055
4057
4058
4072
4077
4075
4060
4057
4058
4061
4060
4061
4060
4070
4088
4097
4093
4105
4107
4105
4103
4105
4109
4086
4111
4112
4115
4110
4118
4119
4127
4128
4129
4130
4134
4136
4135
4138
4139
4140
4135
4158
4137
4138
4158
4157
4154
4156
4175
4176
4179
4184
4198
4196
4199
4180
4188
4193
4192
4201
4200
4192
4207
4220
4218
4230
4229
4247
4248
4249
4253
4254
4256
4265
4266
4272
4268
4273
4295
4296
4305
4295
4310
4311
4312
4311
4314
4307
4305
4294
4306
4321
4316
4326
4330
4331
4337
4336
4337
4338
4340
4342
4345
4347
4345
4370
4384
4405
4406
4419
4420
4435
4439
4443
4445
4447
4431
4424
4433
4418
4417
4416
4417
4420
4424
4440
4442
4454
4461
4481
4483
4479
4480
4484
4485
4495
4498
4499
4524
4527
4528
4539
4541
4545
4543
4559
4569
4571
4568
4573
4570
4571
4580
4579
4580
4583
4588
4589
4590
4597
4632
4625
4626
4618
4621
4632
4642
4644
4647
4650
4665
4669
4666
4673
4674
4677
4681
4686
4651
4657
4658
4664
4665
4667
4685
4688
4695
4712
4714
4715
4717
4731
4734
4738
4737
4743
4745
4752
4753
4748
4763
4768
4769
4771
4774
4801
4802
4830
4845
4850
4847
4873
4883
4884
4885
4886
4887
4896
4891
4913
4914
4937
4938
4953
4959
4979
4984
4990
4982
4979
5008
5007
5008
5004
5015
5017
5038
5066
5067
5069
5078
5091
5101
5086
5088
5086
5092
5097
5098
5088
5070
5072
5083
5082
5073
5077
5080
5076
5073
5065
5066
5068
5069
5081
5082
5084
5083
5086
5089
5092
5095
5130
5133
5119
5129
5130
5138
5140
5148
5147
5150
5151
5155
5163
5188
5190
5192
5189
5196
5180
5191
5193
5197
5182
5162
5163
5147
5154
5155
5168
5207
5216
5223
5228
5227
5229
5221
5218
5221
5219
5220
5230
5259
5260
5233
5256
5258
5251
5246
5230
5234
5242
5245
5260
5261
5269
5281
5285
5296
5297
5296
5297
5298
5313
5314
5313
5319
5313
5322
5324
5325
5333
5346
5354
5355
5345
5347
5349
5350
5352
5339
5349
5345
5361
5362
5363
5404
5398
5424
5415
5420
5433
5435
5436
5437
5438
5455
5454
5460
5455
5453
5454
5466
5469
5471
5481
5482
5502
5503
5501
5484
5460
5461
5465
5466
5470
5454
5460
5486
5482
5483
5502
5512
5514
5516
5518
5525
5526
5521
5515
5518
5521
5528
5539
5557
5561
5577
5571
5572
5579
5576
5577
5589
5592
5595
5596
5595
5601
5587
5560
5563
5562
5571
5598
5606
5621
5636
5637
5663
5665
5678
5677
5678
5679
5684
5687
5684
5688
5691
5690
5693
5696
5707
5725
5727
5731
5734
5738
5748
5767
5768
5763
5767
5758
5760
5791
5777
5778
5782
5773
5776
5777
5791
5792
5793
5795
5781
5786
5793
5805
5807
5818
5822
5821
5826
5827
5846
5847
5864
5886
5878
5873
5868
5878
5876
5881
5876
5888
5890
5893
5894
5895
5900
5907
5908
5915
5916
5937
5936
5927
5938
5945
5944
5935
5942
5943
5945
5948
5977
5985
5975
5985
5998
5999
5996
6027
6047
6031
6033
6034
6022
6023
6025
6030
6029
6030
6034
6046
6055
6061
6058
6067
6070
6077
6069
6088
6084
6090
6100
6102
6107
6111
6108
6103
6104
6114
6118
6107
6114
6102
6112
6113
6115
6116
6139
6135
6143
6154
6155
6160
6163
6160
6163
6169
6184
6176
6199
6205
6204
6219
6222
6231
6207
6218
6219
6221
6222
6221
6200
6194
6203
6204
6210
6209
6210
6209
6210
6230
6238
6239
6245
6249
6264
6271
6262
6275
6252
6253
6240
6245
6219
6220
6221
6222
6225
6231
6236
6238
6267
6272
6273
6278
6287
6286
6287
6281
6264
6269
6270
6274
6247
6248
6259
6264
6267
6276
6281
6286
6284
6289
6287
6275
6247
6263
6261
6264
6265
6270
6271
6272
6271
6280
6282
6283
6291
6302
6303
6315
6335
6361
6358
6359
6362
6363
6349
6348
6355
6357
6358
6357
6375
6374
6367
6342
6350
6354
6353
6354
6357
6369
6371
6382
6384
6371
6403
6402
6412
6413
6415
6416
6417
6418
6419
6420
6438
6436
6438
6443
6454
6440
6439
6431
6442
6441
6444
6446
6450
6422
6424
6418
6426
6437
6438
6439
6449
6451
6452
6463
6464
6475
6492
6499
6506
6519
6548
6545
6543
6556
6565
6567
6564
6553
6554
6556
6564
6584
6580
6581
6582
6584
6585
6586
6595
6596
6595
6598
6575
6594
6595
6593
6591
6602
6603
6575
6573
6577
6586
6587
6615
6624
6647
6677
6678
6679
6683
6682
6684
6689
6704
6709
6723
6751
6754
6755
6757
6758
6774
6787
6791
6816
6837
6838
6846
6847
6845
6847
6850
6864
6863
6853
6874
6875
6874
6883
6891
6899
6918
6920
6921
6937
6934
6935
6951
6950
6969
6971
6976
6978
6979
6987
6989
6987
6989
6991
6990
6991
6980
6979
6963
6964
6968
6972
7000
6992
7003
7006
7019
7022
7028
7040
7035
7034
7055
7063
7065
7066
7071
7079
7092
7102
7118
7115
7121
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
def load_input():
data = list()
with open('input') as fd:
for line in fd:
value = line.strip().split()
data.append((value[0], int(value[1])))
return data
def part1():
data = load_input()
# First part
x = 0
y = 0
for cmd, value in data:
if cmd == "forward":
x += value
elif cmd == "down":
y += value
elif cmd == "up":
y -= value
else:
pass
result = x*y
print("Part 1: ", result)
def part2():
# Second part
data = load_input()
x = 0
y = 0
aim = 0
for cmd, value in data:
if cmd == "forward":
x += value
y += aim*value
elif cmd == "down":
aim += value
elif cmd == "up":
aim -= value
else:
pass
result = x*y
print("Part 2: ", result)
return 0
if __name__ == '__main__':
part1()
part2()
forward 3
down 9
forward 6
down 3
forward 8
down 3
down 4
forward 3
forward 5
up 7
forward 1
forward 1
forward 5
down 8
down 5
forward 3
forward 2
forward 4
down 7
up 2
up 2
down 5
down 5
down 8
down 2
down 4
forward 8
forward 8
up 2
down 2
up 8
up 4
forward 7
up 8
down 6
forward 9
forward 6
forward 5
up 1
forward 6
forward 8
down 4
forward 6
up 8
down 9
forward 1
down 1
up 8
down 5
down 7
forward 7
up 8
forward 4
forward 5
up 9
down 4
forward 4
up 5
down 6
forward 3
forward 2
forward 3
forward 6
up 4
up 7
forward 6
forward 2
down 1
forward 3
forward 3
forward 2
down 6
forward 2
forward 4
forward 9
forward 1
up 6
forward 7
down 6
down 7
forward 6
up 4
down 7
up 9
up 2
down 6
down 6
forward 9
down 2
forward 5
up 3
up 6
forward 3
forward 3
up 8
forward 1
forward 9
forward 9
up 6
forward 3
forward 2
forward 8
up 8
forward 5
up 6
forward 9
down 4
down 5
forward 7
down 6
forward 8
up 9
forward 2
down 8
up 4
forward 7
down 9
forward 5
forward 7
down 4
forward 3
forward 7
forward 4
forward 7
forward 4
up 1
down 1
down 6
up 4
forward 2
down 5
down 8
down 1
up 2
down 6
down 3
forward 5
forward 5
down 5
forward 3
forward 3
down 9
down 9
up 5
down 5
down 3
forward 2
down 1
up 6
down 1
down 3
down 7
forward 3
forward 5
forward 7
up 9
up 9
down 1
forward 2
up 4
down 1
up 4
forward 3
forward 5
down 2
forward 7
down 6
down 2
forward 7
forward 7
down 9
up 4
down 6
down 1
down 5
down 5
down 3
down 1
forward 9
forward 4
up 8
down 1
up 7
down 7
down 8
up 2
down 9
down 2
forward 3
forward 6
forward 5
forward 2
forward 6
down 4
forward 5
up 5
forward 3
down 4
forward 3
down 4
forward 9
forward 7
forward 9
forward 7
up 4
down 3
forward 5
forward 9
forward 9
down 5
forward 9
down 1
down 3
forward 2
forward 5
forward 8
down 6
down 4
forward 1
up 6
down 8
up 4
up 8
forward 3
down 3
down 2
forward 3
forward 4
down 9
down 4
forward 6
up 5
forward 6
up 1
down 3
forward 9
down 5
down 4
forward 9
up 6
forward 9
forward 2
down 1
forward 7
forward 5
down 4
forward 6
down 6
up 3
up 8
down 6
forward 8
forward 3
down 6
down 3
down 3
up 6
up 6
up 1
forward 7
up 2
forward 5
forward 5
up 3
forward 7
up 3
down 7
down 1
forward 9
forward 7
down 1
forward 7
forward 8
forward 2
down 1
up 3
down 6
forward 5
forward 4
forward 2
down 8
forward 3
down 9
down 4
up 9
down 2
down 6
up 2
up 9
forward 1
down 8
forward 3
down 4
down 2
forward 9
forward 2
down 3
down 8
down 7
down 7
up 2
down 7
down 2
down 4
forward 8
forward 1
down 5
forward 2
forward 1
forward 6
down 7
forward 1
down 4
forward 1
up 7
down 7
forward 2
down 4
forward 9
up 1
forward 7
forward 3
forward 3
down 2
down 6
up 1
down 1
down 7
forward 2
forward 6
down 5
up 4
down 9
up 6
forward 1
forward 4
down 9
up 7
down 8
up 6
down 8
down 5
down 5
down 2
forward 7
forward 2
up 2
up 9
forward 6
down 9
down 6
forward 3
down 8
forward 3
forward 2
down 9
forward 5
up 3
forward 5
down 1
up 1
down 3
forward 1
forward 5
down 7
forward 8
forward 6
down 4
down 9
forward 5
forward 2
down 8
down 3
down 6
down 2
down 1
forward 6
forward 1
forward 6
up 9
down 4
up 7
forward 5
up 6
down 3
forward 6
forward 3
forward 2
forward 2
up 1
down 9
forward 2
forward 3
up 1
forward 3
forward 2
down 4
down 8
up 9
up 1
forward 4
up 2
down 6
forward 3
down 5
up 5
up 7
down 1
forward 1
forward 7
down 4
forward 4
forward 2
forward 8
down 7
down 8
down 8
forward 5
forward 8
down 5
forward 3
down 3
down 1
forward 2
forward 7
forward 2
forward 6
forward 3
forward 7
up 6
down 5
forward 6
down 5
down 7
forward 6
up 5
down 9
down 3
forward 1
forward 1
forward 3
down 9
forward 1
down 9
down 9
down 4
down 2
down 5
up 6
forward 1
down 7
down 2
forward 9
down 8
down 2
forward 7
down 8
forward 2
up 8
up 6
forward 9
down 7
forward 1
down 4
down 7
forward 1
forward 4
down 1
forward 9
down 1
up 2
up 4
forward 3
down 4
forward 7
forward 1
up 7
up 4
forward 7
forward 2
forward 5
down 7
down 9
forward 4
forward 6
down 9
forward 6
up 8
forward 3
forward 2
forward 3
forward 9
down 7
down 4
down 7
down 7
down 5
forward 7
down 1
forward 3
up 3
down 1
up 7
up 7
up 4
forward 9
down 8
up 4
forward 6
forward 8
down 8
forward 1
down 6
forward 1
forward 4
up 8
forward 3
up 6
up 1
down 4
up 1
forward 8
up 1
forward 7
down 1
up 9
down 3
forward 4
down 6
down 7
forward 7
forward 4
down 1
up 3
forward 3
up 7
up 9
up 9
forward 7
down 8
forward 5
up 2
forward 7
forward 8
down 2
down 6
down 1
down 1
down 5
down 5
up 5
forward 1
forward 3
down 9
down 6
forward 9
forward 1
down 4
forward 7
forward 6
up 4
down 8
down 9
forward 3
down 9
up 5
forward 3
up 1
forward 3
forward 1
forward 8
up 6
down 6
forward 9
forward 7
forward 8
down 1
forward 9
forward 1
forward 3
forward 6
down 1
down 9
down 9
forward 1
down 2
down 5
forward 7
forward 6
down 5
forward 8
forward 1
forward 5
forward 6
down 6
down 9
down 7
forward 7
down 2
down 2
up 2
forward 9
forward 4
forward 2
up 9
forward 3
forward 1
forward 6
down 4
down 9
down 9
down 1
down 3
down 1
forward 5
down 7
forward 9
forward 7
forward 4
forward 7
forward 8
forward 5
down 8
down 1
up 1
forward 9
forward 9
down 4
up 7
up 3
down 1
forward 5
forward 2
down 6
down 6
up 3
down 6
up 7
forward 2
forward 2
forward 8
down 3
up 5
down 4
forward 5
down 4
forward 8
down 5
down 2
forward 6
down 2
down 3
down 5
up 6
down 7
forward 6
forward 2
down 8
up 1
up 1
forward 2
down 3
forward 3
down 8
down 4
forward 1
down 2
forward 6
up 3
forward 8
down 6
up 7
forward 2
forward 9
forward 4
forward 4
up 7
forward 6
up 1
forward 1
forward 3
down 4
up 7
forward 8
forward 4
down 8
forward 4
down 8
forward 9
down 3
down 4
up 6
up 1
forward 7
up 3
forward 5
forward 4
forward 5
forward 7
forward 1
down 3
up 5
forward 7
forward 4
down 9
down 6
down 7
up 3
up 7
up 8
up 9
down 4
up 1
forward 1
up 3
forward 6
down 8
forward 4
down 7
down 5
down 4
forward 7
forward 5
down 4
down 7
up 5
down 2
down 1
down 8
forward 7
down 4
forward 5
up 9
down 3
up 2
down 3
forward 2
forward 2
forward 8
down 2
down 3
forward 2
down 6
forward 9
down 6
down 1
down 8
down 3
forward 4
forward 4
forward 4
up 8
forward 8
up 4
down 1
forward 5
down 9
forward 7
up 9
up 3
down 9
down 8
forward 3
forward 4
forward 5
forward 4
up 7
down 2
up 5
forward 6
down 3
forward 6
down 8
down 3
down 3
down 4
forward 8
down 9
down 2
forward 2
down 7
forward 3
up 2
forward 4
down 8
forward 2
forward 9
forward 3
down 6
forward 9
down 7
forward 1
forward 2
forward 4
forward 4
up 4
up 2
down 7
forward 9
forward 9
forward 7
up 7
down 2
down 9
forward 8
down 5
up 2
down 6
forward 9
up 3
down 5
down 4
forward 9
forward 3
down 6
down 8
up 5
up 3
down 2
forward 9
down 3
forward 6
down 9
forward 5
down 6
up 6
down 6
forward 6
forward 1
down 3
down 3
up 8
forward 1
forward 4
up 2
forward 3
forward 1
forward 8
forward 7
down 7
down 4
down 6
down 2
forward 3
down 2
forward 6
up 3
down 9
down 2
forward 6
down 6
forward 5
forward 2
up 4
forward 5
up 5
up 5
up 3
forward 9
down 7
forward 4
down 7
up 5
down 3
forward 5
forward 3
down 7
up 2
down 5
forward 9
forward 7
up 7
forward 5
up 5
down 1
up 7
forward 9
down 8
forward 2
forward 8
down 7
down 3
down 1
up 7
forward 4
down 3
forward 1
forward 1
forward 6
up 7
up 1
forward 2
down 8
down 4
down 2
down 6
forward 5
down 7
down 8
down 7
down 5
down 5
forward 1
down 9
forward 5
down 6
down 9
up 3
down 4
forward 3
down 6
up 6
forward 8
forward 8
forward 2
down 2
up 1
forward 6
forward 6
up 9
up 4
forward 9
up 7
up 6
down 2
down 3
up 7
down 7
forward 4
forward 8
down 3
forward 1
down 2
forward 9
forward 4
forward 6
down 7
up 9
forward 9
forward 1
forward 2
down 1
down 8
down 7
forward 3
down 4
down 9
forward 2
up 2
forward 3
up 3
down 9
down 2
forward 3
down 3
forward 7
forward 6
down 6
down 7
forward 2
down 9
up 3
down 6
forward 3
down 2
down 1
up 6
down 3
down 3
down 1
down 5
down 3
up 4
down 2
forward 5
down 2
down 8
down 2
down 5
forward 9
forward 4
down 4
down 2
down 8
forward 9
down 8
forward 1
up 6
forward 6
down 7
down 1
down 2
down 8
down 8
up 8
forward 6
forward 8
forward 9
forward 2
forward 5
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
def load_input():
data = list()
with open('input') as fd:
for line in fd:
value = line.strip()
data.append(value)
return data
def find_value(data, compare):
length = len(data[0])
bins = data
for i in range(length):
least = [value for value in bins if value[i] == '0']
most = [value for value in bins if value[i] == '1']
if compare(len(most), len(least)):
bins = most
else:
bins = least
if len(bins) == 1:
break
return int(bins[0], 2)
def part1():
data = load_input()
# First part
gamma = str()
epsilon = str()
total = len(data)
length = len(data[0])
for i in range(length):
count = 0
for value in data:
count += int(value[i])
if count >= total/2:
gamma += '1'
epsilon += '0'
else:
gamma += '0'
epsilon += '1'
result = int(gamma, 2) * int(epsilon, 2)
print("Part 1: ", result)
return
def part2():
# Second part
data = load_input()
oxygen = find_value(data, lambda x, y: x >= y)
co2 = find_value(data, lambda x, y: x < y)
result = oxygen * co2
print("Part 2: ", result)
return
if __name__ == '__main__':
part1()
part2()
000001000101
101011100101
100011100110
101001111000
000001000110
000110100010
100010101110
000011001110
110001101011
101100110111
101011011110
011110010101
010011010011
111101110011
001111011001
010100101101
110110110111
011111101100
000000101011
100010010011
011010000001
111000111011
001111111100
001111110111
010100011100
001010110100
010110011000
001010011110
001110010010
110100111100
110010110000
000110111000
110011000110
010011011111
011000010101
010101010100
000010001101
011001101100
101100110011
100011110101
110010011010
000011100010
001100010001
001100011100
100010011111
000001111110
011111111000
001100010011
011011010101
111000011010
001110110111
000001101000
111011111010
000100101111
110100100100
110000110011
111100101100
101011101111
101101010111
011111001010
110010111000
110111110001
110011101000
111101011011
001001101110
110110010100
000001110111
111111010001
100101100101
100100110010
100100010010
001100111110
010110101111
110000001111
110001011001
100001011000
101101100111
101100100100
000111001100
100101101110
010010000011
100010110110
110010101101
000011011001
010011110100
101110100111
000100001001
000100010011
010111010101
011010001000
100011101100
111010101000
111101100110
100110010011
111100011000
101111111110
111001011110
010101110101
011110101100
000100101101
110100110101
100100001011
100110100110
000011010000
100011010000
000010110101
011010101110
100001001000
111011101111
001011101000
101110101110
101101000010
110100001000
001010101010
011011110101
101110110000
110011010100
010010100000
011001110001
011110111110
101100001100
100110111111
111101001000
110001001010
111000100110
000000001001
100100100011
111111000011
111001100110
110001110001
010001111011
000010110011
111011111100
011010101010
111001101001
111101100101
101100000001
000110111001
101101011001
000100110011
010010101010
110000100010
001101010100
100000010101
101011100100
000000110000
001111010110
011011100111
110010010111
101101100101
110111010110
011001100011
101100111010
100011011000
011001011001
110011001100
111111111001
101100011101
111110110101
010110010101
001110110100
111101000000
011001111100
000101100010
010100111110
000101011000
010011001110
011111111101
000000110101
100101001000
101110100110
001001010010
000001000000
000101011011
010001011111
000111111111
010100101001
100111110001
110110011110
110111010011
001010100010
101100101011
110010110101
010001100001
110110110100
111011111011
111100111100
111101111001
011000110111
111010100000
011101001100
111000011000
111100100111
110110111001
000100000111
111101100001
101010011111
011000001011
101111111000
100110101011
100111101001
110101000111
000111010000
010011011001
110101101111
000001011010
100001000110
011011101110
110100011111
000101010110
100001010100
010000101011
110111100001
010111011011
110101011110
100111010010
111000011101
100001111110
101110001100
101011110000
001110000010
010001001000
011011001001
100100110100
111111011001
100011110111
000001001001
110010000110
110001011000
000000001100
101111010101
101110011100
000000101101
100110101001
111010110010
010111010010
010101111001
100010101000
011001000111
011011110100
101010000110
011010111011
101100100001
000101001110
101110111001
000010000101
001011110110
100000101000
000010000110
001011010100
111101011000
001010111001
001111000000
000100100001
100101011000
100000010010
111101100010
000011000111
000110001000
001110101101
010011011110
011101100000
010100000001
001110010001
010000000100
000100010010
000101000011
000111100001
111010110100
100111100110
100100001001
001111111111
101010001100
110011001001
000011010101
101001001111
010010001100
001010110010
100011110110
100001111010
100100101001
111010111000
111011110111
011110100000
101110000010
111111111000
000110011010
010010000111
000111101000
010100110110
010001011010
011001101010
101010000101
011110011100
000000000110
001001000110
000001001011
100011001001
001001100011
100101001110
110110101101
001001100110
110000011111
011110101011
010111001001
101011010010
011101110000
000000011110
010000101101
001000000111
001010001010
101111100111
010111101001
101010001000
010110110001
101110100010
001001110101
011000100100
111011011110
000101110101
111010100110
100110011011
100010100010
001001111101
110110111010
101101100011
011000011000
010011010000
010000111100
110110001101
011000111101
011101010011
001000000001
101010011100
101111011100
011010101111
001110110010
001111100011
001011010011
110000001110
000000110111
110011101100
010000101100
000101001010
101010110111
011100000001
110011101111
100011111111
110100011100
111000100111
000000001000
100011011100
110010000101
100110010010
000100100000
010101100110
010100010011
000110100111
111001010001
010001011011
100011010101
000100001010
010000001000
010011101011
010100000101
001111001100
101000000001
010010100101
011001111000
000101101001
010101011110
000001010001
010110000101
010000011111
100110111011
001010010100
001100100001
011111111001
011100101001
101001111100
110100101100
010010101001
101000001010
010010010101
101000110011
011100010000
001001111010
101011010111
100100100111
110001101111
100000101101
000111110100
000010110110
010001100101
110000111111
001011000100
011010011100
011110011010
010100101111
001001010100
101111011111
000100111100
111110010011
110011010010
011100111101
001000011111
100111000101
110001100100
110000110101
011001001111
100110010101
100011001111
100010000111
111000110101
111000000000
101101010001
010001000100
010000101110
011111110001
011010101000
101101111110
100101101111
001111101100
110011100100
001011100010
001101001010
011110010011
000100011101
011000010011
111110101111
101101110010
000011101010
001010110101
111111000110
100000101011
001000111111
101011110100
001001110001
100111101010
000111110101
010110100010
110011010111
010110110111
001100100100
111000001111
011000010000
101010000111
111101111010
011101100010
011000001101
010000010010
101010110000
010000100000
111011100100
101101011000
011000010110
101111111111
000000111101
101100110110
011000110011
110111100000
010101111100
010101101011
100011001101
101100111011
111000111010
000110010111
111111001111
101010111010
111011101001
001111001110
010010001101
111110000100
100000000100
011101011101
010000011101
010001011000
000110011000
010001101011
110110000011
111110110000
101001011100
100011110010
100000010011
111011101101
000101101110
010000100111
011000000001
000111100100
110111111001
111010111001
101111100101
100110000011
110010011101
010110111010
011110001001
110000100000
001000010100
010101101001
100100011110
011000100101
010010001010
001010001111
101011001010
011110101111
110011001111
111001001011
000000111001
010010101100
100101010011
011111011000
101010100110
110101001101
011000100000
000101111011
110011100010
111011100001
010001111000
111110000101
001100000001
001101001111
110001010101
010011111001
100100101000
110011011110
100011101101
100000011011
101101101010
100111111100
100001000001
110101111111
010000100110
011010010101
110011010110
101001010011
111010000001
000100110101
001100100111
001011000011
101110010000
011010111110
110101101011
011010001110
101100101111
011111011011
101110011111
011000110101
101100001011
001010001100
110111101011
100010001100
100111100111
110000111011
011001101000
001100010111
001101001001
001111010011
100111000111
111011010100
000011101110
111101000011
010000011001
111101101000
000111011100
010100001001
110011111110
001011010010
111000010100
100001010000
101000000000
011110000000
111111110001
101010100011
001011111010
110011101110
011110001011
101011100000
010101011100
010001101101
010010110110
101011010100
010001001100
111001111010
101111111101
101000101011
010010000100
000011110001
110010001000
010111101011
111010010101
010110100111
110000100110
000011111110
001000101011
000000000010
011100100010
011110010000
000010011111
001000011000
001111000110
110110011101
010100110010
101101100110
001101100100
111000001000
001011100100
110110010001
000100101010
100100111111
000100111011
100001000011
101011001001
000110101111
010110111111
101100010011
111010110101
001010001110
111000100011
011000110001
010000110000
101001100110
011001010001
001011001111
101111111010
110111111100
010000010001
000100101011
000000011100
110010000011
111000010000
110101111011
001010100100
001001000111
110110001111
011111001111
010010111000
011010011000
111100111101
100100101011
000110001101
110011001101
000000100010
001000110100
001010110001
110001000110
111011000101
100001010011
100111011101
010101110000
110010000010
010001111010
111010111111
010110001101
110001110101
100110101100
000001011011
111111011111
011001011011
000101110011
000011110000
100100010110
100000010001
011100110110
101011101011
010100101110
010011011101
001001111000
000000011101
010101100000
001000100011
011011111001
110011100000
100000110111
010000000011
001010011010
011100010110
101010100001
001110111000
110101000110
001110011010
010100001011
001001010110
011010000110
010010101000
001110100011
110101011001
101111101001
001101110111
110101111001
011010110110
101001000101
000000100111
101011111110
111111100001
101000111111
000110100011
010001110110
000111101010
000011011101
100001101010
001011101111
111100010101
110110111000
110110011111
010110001011
011010000101
110101110011
101011101100
011101111100
000111011010
100001011101
000010001111
000110111100
000101000101
101010101010
011111001001
010111110011
111010000000
001100011101
001000101000
100101010100
010011111110
010011000001
010110100100
010011001010
010010100010
111100001011
100110100111
000010110010
101111000100
101000000011
110101011000
001000010111
100100110111
000000000011
001011111000
100101000101
101100010101
101100000101
000101001111
101111010001
111101011110
000000010001
100001110100
101111000000
101000101110
010100001110
010000110011
101101110110
001011000101
000100100010
111100010000
100000100010
011101000101
111000110111
110110001011
101101111001
011001111010
001111011010
111010101100
101110011101
100110101101
101011011011
110100000001
011001100100
000001011101
000011011110
100101101101
001110100110
110011110111
010001110000
100011100011
001110011001
011011110110
100000010100
001010101101
010110000111
010001011001
001111111000
011000011001
110101101100
110101000011
100000011101
001100001011
000011000000
111000010101
110000011010
101111000111
011101010000
011111000111
101010111000
011000110110
011101101001
111110101010
001010111000
000010011100
000100111010
000111100010
010101111110
001000011101
110110111011
011001101110
011111111100
001100100011
000100001101
011100001111
000001010011
011001111110
100001100010
010001110100
011010110001
001010101000
101100001001
101010000001
000001101100
100000000111
010100010111
110001111001
000010100111
011100101000
011010110100
100111100010
100101110011
001111010001
100111101011
101111110100
110010100111
000011110110
101100100011
111011101110
000011010110
011010000011
011001011010
001010011101
000110000101
011110101110
010110001001
101110100101
100111001110
011011111101
110010110100
101010010010
011110110000
001100110110
111001000101
110000001100
011010011011
011111010110
101010011110
101100010001
001110101001
101101010110
111110110110
000000101000
001111000001
010010001111
100011100010
011111110010
000010010001
011100000000
001001111001
100101101010
101000101101
111010011100
101001101000
101100110100
100111000011
111011100011
101100010110
010010101110
011010010011
111001011100
101100010010
101000110111
101011010001
111000110100
110000101001
000010101010
001000110000
010110010011
110110100110
111110000000
111001100101
101101110011
100001111000
100010011001
111101000101
000101010101
010110111011
111111111111
001100000000
111110001111
110001001011
010110110000
110110101111
110001101101
011111101001
011101100101
111101001100
110001101000
110001011100
101100011100
101110110101
000110110011
111110111110
011111010000
000111010100
101110001000
101111100110
000101001011
111101111011
001100100110
011110100010
010111011001
110110110011
000100100101
001101011111
011010001010
010000111110
100010111011
101000100101
111111101111
111111111110
110111100111
001011110001
001101000010
010111010011
101101101110
100110001011
111100001111
101010011010
000110111111
011110000100
111100110011
111110111101
011001101111
110110011001
111010001101
010000001101
100001111101
100101111111
100111110111
110001000001
110111001101
011001110100
010001110101
100010111110
010010010010
000010111101
101001101100
100011111100
110010111010
100101011011
110110101011
101101010000
011110100011
101100111111
110001100001
110100111010
011000100011
011000100010
011111101111
101000010110
000101000010
001000100001
111101110010
000111000001
101000111000
100110100011
001001001111
110101011010
101011101101
100011000110
100100111000
001111001111
010100010100
000100100100
010100101011
010001100000
011010110111
111110111000
110100101001
010100011000
110110101110
010000101001
000111001010
001001100111
110000110110
011000101010
000011110100
111110010000
010000101111
100111010101
110110110000
110100101110
111000110010
011110001100
000001100100
111110000111
001000011001
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
def load_input():
numbers = list()
boards = list()
board = list()
with open('input') as fd:
for i, line in enumerate(fd):
if i == 0:
numbers = list(map(lambda x: int(x), line.strip().split(',')))
elif (i - 1)%6 != 0:
board.append(list(map(lambda x: int(x), line.strip().split())))
else:
if board:
boards.append(board)
board = list()
else:
boards.append(board)
return numbers, boards
def find_pos(number, board):
for i in range(5):
for j in range(5):
if board[i][j] == number:
pos = (i, j)
return pos
return None
def check_bingo(matches):
for i in range(5):
if len([match for match in matches if match[0] == i]) == 5:
return True
if len([match for match in matches if match[1] == i]) == 5:
return True
return False
def calc_result(board, matches, number):
unmarked = 0
for i in range(5):
for j in range(5):
if (i, j) not in matches:
unmarked += board[i][j]
return number*unmarked
def part1():
numbers, boards = load_input()
positions = [[] for _ in range(len(boards))]
result = None
for number in numbers:
for i, board in enumerate(boards):
pos = find_pos(number, board)
if pos is not None:
positions[i].append(pos)
if check_bingo(positions[i]):
result = calc_result(board, positions[i], number)
break
if result is not None:
break
print("Part 1: ", result)
return
def part2():
# Second part
numbers, boards = load_input()
positions = [[] for _ in range(len(boards))]
winners = list()
result = None
for number in numbers:
for i, board in enumerate(boards):
if i not in winners:
pos = find_pos(number, board)
if pos is not None:
positions[i].append(pos)
if check_bingo(positions[i]):
winners.append(i)
if len(winners) == len(boards):
result = calc_result(board, positions[i], number)
break
if result is not None:
break
print("Part 2: ", result)
return
if __name__ == '__main__':
part1()
part2()
72,99,88,8,59,61,96,92,2,70,1,32,18,10,95,33,20,31,66,43,26,24,91,44,11,15,48,90,27,29,14,68,3,50,69,74,54,4,16,55,64,12,73,80,58,83,6,87,30,41,25,39,93,60,9,81,63,75,46,19,78,51,21,28,94,7,17,42,53,13,97,98,34,76,89,23,86,52,79,85,67,84,47,22,37,65,71,49,82,40,77,36,62,0,56,45,57,38,35,5
91 60 70 64 83
35 41 79 55 31
7 58 25 3 47
2 23 69 59 21
11 22 8 87 90
77 95 19 21 76
93 92 62 35 3
4 29 7 41 45
80 50 83 61 64
39 32 91 56 48
47 11 39 58 97
63 51 40 74 71
12 17 68 81 44
64 85 20 84 80
0 77 5 18 50
44 82 32 1 57
98 88 33 83 85
25 61 63 99 37
0 74 7 20 39
71 72 22 80 28
78 97 0 48 41
56 51 62 58 90
8 44 98 46 1
38 40 91 20 55
88 2 32 86 14
84 50 16 45 40
9 39 60 34 46
57 20 12 3 36
58 17 72 48 83
73 85 49 67 66
4 30 73 83 57
74 23 49 19 42
72 65 8 99 13
25 6 82 53 68
20 86 46 48 50
52 29 61 16 75
36 19 2 82 9
34 90 89 43 14
69 66 20 21 11
31 53 46 18 23
37 76 34 79 99
43 5 42 91 71
47 54 19 82 81
95 78 65 60 24
32 94 92 27 66
68 61 80 90 53
33 17 52 0 23
30 71 5 85 11
27 39 41 6 9
58 98 7 74 89
31 5 55 67 51
54 86 40 25 92
91 62 9 94 7
39 0 44 52 28
12 17 26 46 32
94 80 83 88 77
65 71 31 86 0
98 55 18 92 72
6 12 30 25 34
67 53 14 20 47
81 74 14 47 1
83 82 4 89 8
43 93 63 21 44
92 61 25 77 97
12 72 35 78 52
26 39 13 37 46
87 6 58 47 19
24 35 45 95 52
5 27 42 96 0
23 64 8 29 83
53 58 18 96 93
57 90 35 88 68
91 89 7 80 47
59 86 81 24 31
43 8 66 17 94
0 97 91 67 90
93 20 36 4 42
43 64 28 94 34
31 2 7 54 71
18 35 76 86 16
55 63 26 47 0
2 23 54 25 90
36 13 85 31 15
59 51 18 88 62
44 69 9 81 58
26 97 98 42 27
3 53 91 89 93
87 57 12 18 5
29 99 86 47 64
6 28 92 79 67
4 35 45 79 16
33 95 99 80 9
60 78 57 51 50
27 5 48 21 46
19 70 32 58 18
94 82 61 66 31
14 56 76 37 28
42 81 50 10 40
2 98 47 29 62
69 90 46 44 18
87 3 8 50 17
15 90 54 45 21
6 28 43 51 32
97 84 69 30 38
98 44 88 55 83
34 19 27 43 92
81 62 52 32 39
50 29 83 25 82
60 55 49 41 97
75 94 22 69 66
59 39 96 87 65
33 18 4 71 15
22 27 92 8 29
19 5 32 85 45
91 79 35 9 3
41 53 51 68 85
72 71 94 82 81
60 38 13 16 7
49 80 10 0 54
20 39 59 64 99
37 21 90 40 73
85 75 16 34 99
84 15 25 18 27
77 32 0 76 36
13 50 68 91 12
24 26 0 14 12
89 4 15 95 73
54 2 55 84 42
30 50 81 60 87
37 94 71 91 53
52 1 81 44 34
27 60 36 19 69
98 11 49 67 56
77 72 40 48 66
84 9 37 32 51
58 15 7 36 55
94 49 69 89 87
79 70 30 77 19
68 31 56 41 53
47 85 74 54 46
64 87 23 66 0
29 98 72 82 80
70 45 46 30 37
53 54 33 86 76
6 75 71 68 2
12 31 43 80 41
37 15 13 2 3
86 61 9 17 59
55 68 72 8 1
96 26 44 73 47
67 39 95 84 10
5 88 13 81 99
68 15 98 6 17
47 85 74 32 97
58 8 16 56 42
82 31 42 84 17
25 28 2 6 12
78 57 16 97 18
87 64 54 30 65
3 77 29 49 81
24 1 43 89 46
29 78 57 14 85
9 58 53 83 35
96 42 62 68 74
67 2 39 37 51
72 26 46 52 3
91 27 41 32 53
25 36 7 63 22
56 38 93 65 9
95 19 77 64 44
21 71 13 99 39
47 17 80 85 64
5 18 48 27 81
82 23 45 57 12
83 55 26 31 32
57 13 86 69 65
42 76 35 18 39
17 91 95 43 6
55 97 22 54 14
56 0 5 60 92
87 12 46 42 35
44 6 95 30 67
51 21 68 37 59
77 65 50 69 63
33 56 24 57 28
82 87 42 99 39
38 55 74 28 6
77 66 9 80 10
47 90 32 3 98
92 52 5 94 51
16 1 87 57 66
41 70 58 31 5
71 88 17 42 76
81 40 25 89 63
92 4 61 77 64
70 28 56 51 66
44 60 25 0 45
91 78 81 95 88
75 43 57 67 32
58 27 20 82 22
16 98 82 79 90
96 4 80 69 19
9 28 33 40 94
2 99 14 73 43
76 68 74 42 30
29 42 94 45 2
25 81 46 54 26
75 99 51 58 23
76 72 71 64 63
66 70 92 44 13
2 71 39 49 95
19 84 1 7 96
9 6 60 93 78
38 91 55 36 41
64 3 10 20 74
79 80 15 69 89
36 76 83 7 72
87 34 48 0 93
5 84 77 20 75
46 27 11 55 3
82 34 4 14 74
40 39 7 6 95
11 51 78 80 29
97 81 38 9 71
22 62 19 72 68
54 70 90 43 98
12 27 57 96 62
32 76 0 86 42
88 68 81 91 50
10 94 18 71 2
90 41 29 53 58
59 62 14 85 66
25 82 68 44 93
73 32 76 67 18
94 71 83 34 37
6 72 69 33 90
87 60 66 85 16
59 80 86 47 89
32 98 17 29 5
48 27 18 57 81
10 22 98 86 82
8 66 71 14 93
87 79 40 78 49
84 63 17 54 94
35 39 47 1 96
58 60 52 6 86
41 20 66 59 2
92 79 88 40 71
96 9 25 36 17
91 32 43 38 8
74 3 64 66 68
69 37 22 76 33
17 67 29 32 27
63 49 46 21 60
35 73 9 52 50
0 91 8 26 9
3 98 79 97 7
37 61 1 60 47
86 17 11 70 15
66 53 2 90 54
68 42 0 78 16
83 88 21 87 12
50 2 29 14 63
72 90 81 71 91
54 79 94 10 4
28 63 97 31 4
50 52 43 24 16
36 77 0 9 75
83 94 69 68 27
93 82 42 56 34
24 52 66 51 82
50 30 34 93 67
56 70 53 13 78
4 84 88 57 81
80 74 5 95 98
56 64 53 52 72
51 48 50 60 49
8 46 84 95 43
91 21 7 88 33
94 57 80 25 54
70 57 62 20 18
86 45 41 76 32
87 35 52 5 2
16 77 25 39 22
38 10 6 29 98
89 54 57 80 65
0 38 94 15 6
85 76 16 83 59
92 5 53 14 95
47 35 73 98 34
64 24 90 71 69
55 35 20 98 41
94 70 10 73 16
65 84 60 7 72
83 2 22 78 99
31 81 74 56 98
13 97 95 49 67
9 47 42 99 60
38 22 65 58 21
82 45 2 28 68
90 88 28 85 51
23 93 13 55 50
63 22 3 30 39
5 71 82 95 81
57 76 12 92 56
78 12 28 6 73
59 24 43 29 31
30 34 75 52 48
62 57 23 74 50
91 92 5 95 38
95 88 13 22 10
16 4 19 37 91
50 52 60 46 77
45 55 49 41 26
21 7 67 48 18
51 79 44 16 71
6 13 12 41 97
50 25 19 63 4
98 0 23 77 31
27 57 52 99 3
86 95 7 54 84
50 33 48 16 9
82 32 38 6 34
43 80 27 37 11
89 70 41 22 45
24 3 47 68 35
85 76 8 29 4
2 10 5 28 73
92 89 50 25 56
99 57 79 19 37
0 46 72 5 20
62 28 24 53 44
84 25 63 34 9
75 1 65 59 10
95 29 97 77 45
87 90 1 17 67
57 73 35 10 30
65 14 46 60 6
70 66 56 69 92
3 27 21 64 88
20 58 53 29 66
27 6 67 89 33
88 60 79 69 97
90 3 47 68 25
48 59 42 98 39
65 90 45 97 87
75 98 7 58 42
51 4 95 88 47
94 6 11 53 63
49 80 2 48 68
3 77 42 97 82
70 58 81 18 47
78 96 62 39 56
22 87 71 31 94
34 48 57 38 88
70 36 65 33 45
71 0 59 44 1
42 37 7 5 9
11 12 91 43 27
60 21 57 61 99
76 75 56 49 2
36 57 39 64 77
95 19 35 43 97
82 34 50 44 55
45 74 15 66 29
0 75 1 78 79
13 37 48 27 14
90 50 26 92 67
89 62 87 69 33
29 47 4 2 12
74 42 24 86 61
92 66 3 65 75
7 1 77 63 64
39 91 87 28 5
30 35 41 73 96
0 81 41 15 66
62 19 86 31 40
23 94 98 82 24
61 99 1 5 60
80 64 91 33 47
16 61 56 77 57
28 59 71 45 92
53 20 35 66 73
99 3 86 31 74
94 69 84 96 90
71 56 23 76 42
90 44 58 27 15
46 18 86 63 24
69 49 82 38 43
33 51 60 66 39
75 78 38 25 76
67 3 83 90 10
40 89 47 23 88
34 21 46 16 33
9 79 50 0 26
81 75 80 23 41
62 4 76 1 63
56 39 57 28 61
20 6 79 92 84
88 3 90 16 12
87 78 3 34 63
98 21 24 9 99
62 29 57 65 27
47 52 67 76 71
11 17 93 23 82
53 68 70 38 56
62 54 25 43 35
9 3 13 15 75
59 27 26 33 83
93 40 11 64 76
27 83 26 48 77
51 20 65 18 35
80 30 60 44 89
84 82 62 91 63
12 97 11 19 34
31 28 92 48 34
9 93 61 71 60
52 18 97 81 62
80 64 57 22 30
11 88 74 29 56
57 34 90 46 73
31 0 70 66 82
45 12 40 19 87
91 24 59 83 14
80 21 13 86 89
9 8 64 48 30
6 62 28 99 41
79 45 83 7 55
15 14 54 88 12
90 74 97 96 50
50 73 58 26 12
96 98 56 34 7
51 92 14 89 16
41 70 80 55 13
37 47 2 64 99
98 9 70 17 18
39 15 88 16 47
80 41 8 51 21
54 42 31 10 59
37 92 33 62 68
60 72 51 63 29
83 39 41 24 14
34 5 94 90 56
75 80 67 17 20
47 11 58 93 42
97 7 27 42 67
12 30 91 45 52
62 50 87 92 71
99 84 33 6 46
29 55 86 47 60
25 49 55 98 22
66 9 61 59 90
45 74 77 88 5
6 76 0 36 93
23 70 33 95 2
53 92 27 86 55
66 52 26 58 38
2 78 69 62 65
30 5 1 25 99
76 43 4 13 8
18 72 51 48 39
62 19 28 44 82
54 22 38 55 83
86 93 42 9 32
11 89 27 34 68
85 99 35 88 76
10 25 33 83 70
54 81 77 73 66
4 74 96 41 86
49 3 68 65 39
71 0 70 14 31
28 23 17 43 75
13 40 38 87 97
63 93 92 89 27
58 76 24 53 54
55 58 11 38 16
98 86 13 12 8
22 10 77 61 90
37 76 2 62 45
44 30 52 70 82
89 55 12 90 63
40 88 91 22 74
8 0 25 6 79
53 23 87 77 20
11 38 78 43 94
21 14 37 8 16
29 73 67 91 56
5 90 12 92 59
64 1 42 72 94
98 86 18 69 49
79 71 82 1 77
96 39 24 60 81
49 16 12 63 14
0 32 78 37 8
92 33 15 99 65
54 11 40 55 33
58 47 4 83 94
46 96 16 28 5
0 62 95 71 39
93 59 7 75 64
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
pattern = re.compile('(\d*),(\d*) -> (\d*),(\d*)')
def load_input():
data = list()
with open('input') as fd:
for line in fd:
match = pattern.search(line)
data.append([(int(match.group(1)), int(match.group(2))), (int(match.group(3)), int(match.group(4)))])
return data
def find_hor_and_vert(data, task):
coords = list()
kind = None
for el in data:
dist = None
if el[0][0] == el[1][0]:
dist = range(min(el[0][1], el[1][1]), max(el[0][1], el[1][1]) + 1)
for i in dist:
coords.append((el[0][0], i))
if el[0][1] == el[1][1]:
dist = range(min(el[0][0], el[1][0]), max(el[0][0], el[1][0]) + 1)
for i in dist:
coords.append((i, el[0][1]))
if task == 2:
if abs(el[0][0] - el[1][0]) == abs(el[0][1] - el[1][1]):
a = None
b = None
if el[0][0] < el[1][0]:
a = range(el[0][0], el[1][0] + 1)
else:
a = range(el[0][0], el[1][0] - 1, -1)
if el[0][1] < el[1][1]:
b = range(el[0][1], el[1][1] + 1)
else:
b = range(el[0][1], el[1][1]-1, -1)
for i in zip(a, b):
coords.append(i)
return coords
def calc_number(coords):
# coords.sort()
i = 0
count = 0
overlaps = dict()
for coord in coords:
if coord not in overlaps:
overlaps[coord] = 1
else:
overlaps[coord] += 1
for value in overlaps.values():
if value > 1:
count += 1
return count
def part1():
data = load_input()
coords = find_hor_and_vert(data, 1)
result = calc_number(coords)
print("Part 1: ", result)
return
def part2():
# Second part
data = load_input()
coords = find_hor_and_vert(data, 2)
result = calc_number(coords)
print("Part 2: ", result)
return
if __name__ == '__main__':
part1()
part2()
242,601 -> 242,18
938,357 -> 938,128
920,574 -> 750,574
804,978 -> 804,813
955,932 -> 68,45
232,604 -> 232,843
69,570 -> 467,968
355,432 -> 611,688
945,19 -> 700,19
904,932 -> 904,918
455,65 -> 516,65
571,485 -> 588,485
717,142 -> 217,142
377,344 -> 66,344
510,818 -> 132,818
848,709 -> 848,950
785,50 -> 785,857
23,981 -> 971,33
938,45 -> 938,327
212,402 -> 601,13
749,142 -> 651,240
94,930 -> 22,930
436,467 -> 820,851
544,265 -> 458,265
517,708 -> 517,785
957,893 -> 957,22
684,610 -> 526,452
713,687 -> 526,687
220,781 -> 988,13
12,45 -> 912,945
854,677 -> 646,677
382,498 -> 382,64
676,879 -> 148,351
809,52 -> 336,525
959,951 -> 41,33
943,162 -> 132,973
897,732 -> 897,308
21,196 -> 702,877
938,972 -> 656,972
798,139 -> 90,847
213,597 -> 582,966
248,955 -> 973,230
985,606 -> 985,885
166,693 -> 804,693
807,897 -> 28,118
433,306 -> 433,447
899,61 -> 60,900
984,582 -> 691,582
803,583 -> 910,583
348,142 -> 348,244
352,775 -> 352,430
240,285 -> 240,406
394,541 -> 394,655
887,622 -> 298,33
62,37 -> 861,836
819,136 -> 29,926
717,332 -> 717,408
709,63 -> 276,496
384,441 -> 150,441
292,251 -> 557,516
518,311 -> 52,777
50,735 -> 479,306
932,865 -> 139,72
43,21 -> 982,960
63,927 -> 796,194
958,351 -> 958,623
643,451 -> 35,451
534,14 -> 459,14
20,649 -> 924,649
983,18 -> 35,966
84,668 -> 203,668
40,654 -> 748,654
474,760 -> 85,371
512,431 -> 272,431
588,93 -> 112,569
648,687 -> 832,687
988,867 -> 116,867
979,46 -> 94,931
242,307 -> 800,865
100,204 -> 807,911
890,962 -> 88,962
273,510 -> 273,201
184,748 -> 813,119
214,915 -> 950,179
960,975 -> 89,104
853,347 -> 853,79
853,308 -> 884,308
245,394 -> 245,640
850,554 -> 604,800
141,159 -> 141,378
635,632 -> 897,894
352,182 -> 550,182
748,613 -> 748,887
531,664 -> 255,388
785,414 -> 432,767
374,457 -> 653,736
451,535 -> 444,535
600,179 -> 434,13
489,605 -> 845,961
658,786 -> 658,196
305,556 -> 305,914
820,368 -> 204,984
903,70 -> 548,425
840,450 -> 796,494
289,183 -> 768,662
21,54 -> 950,983
765,294 -> 209,850
467,511 -> 703,747
354,645 -> 730,645
176,30 -> 964,818
290,259 -> 345,259
868,945 -> 96,173
536,884 -> 536,94
415,177 -> 415,99
250,140 -> 466,140
900,107 -> 900,249
74,394 -> 137,394
364,957 -> 364,81
718,477 -> 718,227
27,14 -> 988,975
491,956 -> 154,956
289,283 -> 289,225
479,583 -> 604,583
581,406 -> 23,964
837,526 -> 732,526
417,435 -> 417,206
502,184 -> 20,666
903,754 -> 817,668
381,284 -> 967,870
31,17 -> 176,17
225,377 -> 179,377
316,932 -> 358,890
605,841 -> 559,841
865,193 -> 865,827
836,834 -> 142,140
229,610 -> 232,610
26,13 -> 872,859
26,444 -> 26,79
272,690 -> 531,949
964,954 -> 331,954
545,91 -> 335,91
906,942 -> 906,301
608,778 -> 608,364
475,723 -> 475,710
454,207 -> 614,207
200,180 -> 917,897
966,44 -> 71,939
288,252 -> 288,413
795,791 -> 66,62
81,39 -> 588,546
249,244 -> 892,244
483,579 -> 853,579
220,921 -> 220,286
917,834 -> 675,834
569,692 -> 569,521
344,586 -> 835,95
116,153 -> 888,925
681,52 -> 871,242
980,976 -> 27,23
828,567 -> 482,567
660,432 -> 660,441
826,379 -> 280,379
42,839 -> 259,622
743,23 -> 91,23
318,400 -> 318,528
539,745 -> 734,940
831,194 -> 831,210
582,630 -> 361,851
284,900 -> 213,829
52,855 -> 763,855
215,753 -> 452,753
290,187 -> 417,187
69,48 -> 69,126
76,628 -> 76,365
257,694 -> 54,694
755,713 -> 556,912
519,265 -> 342,265
193,319 -> 193,651
496,231 -> 900,231
83,942 -> 83,524
524,59 -> 989,524
288,800 -> 907,181
458,138 -> 586,138
338,244 -> 934,840
843,728 -> 843,476
42,634 -> 657,19
827,634 -> 369,176
779,900 -> 779,503
20,20 -> 870,870
467,241 -> 467,142
677,483 -> 501,483
10,989 -> 989,10
11,989 -> 989,11
244,750 -> 244,607
479,497 -> 48,928
372,341 -> 615,341
817,941 -> 339,941
352,67 -> 352,581
590,747 -> 590,405
524,26 -> 524,37
501,300 -> 117,300
265,194 -> 491,420
397,891 -> 983,305
423,717 -> 423,922
197,863 -> 197,217
12,91 -> 379,91
364,426 -> 364,185
649,835 -> 649,309
517,380 -> 485,380
328,469 -> 568,469
781,298 -> 781,264
25,794 -> 25,197
570,744 -> 570,544
664,352 -> 632,320
528,944 -> 528,696
242,44 -> 900,702
486,775 -> 486,556
608,245 -> 788,245
114,11 -> 114,508
751,560 -> 751,884
211,513 -> 448,513
389,219 -> 308,300
638,200 -> 105,200
258,243 -> 365,243
120,558 -> 556,122
787,166 -> 274,166
617,666 -> 185,234
537,172 -> 808,172
633,980 -> 282,980
270,150 -> 270,225
925,32 -> 48,909
979,14 -> 891,102
98,278 -> 98,485
333,771 -> 119,771
132,673 -> 132,189
416,470 -> 482,404
762,151 -> 925,151
148,721 -> 378,491
255,576 -> 255,474
21,48 -> 938,965
876,615 -> 777,615
713,209 -> 209,209
250,474 -> 271,453
684,71 -> 451,71
406,614 -> 519,501
479,252 -> 112,252
721,768 -> 284,331
290,344 -> 290,111
359,934 -> 544,934
754,976 -> 726,976
358,544 -> 358,904
597,344 -> 597,581
915,222 -> 915,255
931,160 -> 135,956
160,657 -> 348,657
35,942 -> 949,28
298,837 -> 298,356
540,195 -> 540,119
29,140 -> 29,955
118,117 -> 980,979
240,384 -> 464,608
677,667 -> 361,351
982,987 -> 11,16
638,770 -> 95,227
135,285 -> 135,349
843,313 -> 843,529
208,220 -> 945,957
450,889 -> 977,362
876,69 -> 283,69
57,586 -> 57,231
602,78 -> 602,564
708,704 -> 267,704
697,336 -> 697,264
564,522 -> 519,567
195,217 -> 274,138
35,885 -> 116,804
680,28 -> 148,28
736,34 -> 736,616
918,454 -> 52,454
143,40 -> 415,40
985,469 -> 985,282
804,703 -> 107,703
707,59 -> 296,470
37,935 -> 931,41
45,723 -> 45,531
897,959 -> 165,227
691,948 -> 523,948
545,560 -> 545,45
251,24 -> 748,521
625,506 -> 625,626
302,702 -> 989,15
489,926 -> 489,507
405,830 -> 405,871
736,851 -> 19,134
712,848 -> 48,184
925,914 -> 33,22
593,254 -> 369,478
965,691 -> 155,691
758,931 -> 349,522
64,135 -> 820,891
79,933 -> 79,683
609,454 -> 233,454
617,853 -> 309,545
695,130 -> 695,578
508,198 -> 363,198
184,414 -> 275,505
627,901 -> 519,901
765,715 -> 213,715
445,134 -> 669,134
785,33 -> 302,516
563,218 -> 470,125
136,461 -> 264,461
523,643 -> 674,643
473,695 -> 473,235
616,835 -> 757,976
406,763 -> 406,224
483,111 -> 203,111
70,863 -> 922,11
738,141 -> 738,54
146,697 -> 332,883
939,16 -> 23,932
836,15 -> 317,534
853,586 -> 853,596
733,377 -> 733,461
378,597 -> 378,640
522,225 -> 522,78
875,886 -> 875,130
302,83 -> 771,83
969,588 -> 419,38
268,159 -> 585,476
658,955 -> 33,330
940,149 -> 492,149
157,254 -> 962,254
265,778 -> 265,365
414,494 -> 608,494
27,959 -> 948,38
220,160 -> 220,891
836,316 -> 836,179
843,727 -> 163,47
225,695 -> 598,695
678,249 -> 892,249
938,36 -> 938,170
190,486 -> 40,336
815,256 -> 815,866
961,200 -> 961,89
67,895 -> 67,853
480,727 -> 852,727
334,94 -> 334,452
67,622 -> 987,622
48,29 -> 982,963
90,29 -> 963,902
859,739 -> 338,739
869,254 -> 474,649
196,43 -> 69,43
336,439 -> 336,837
248,387 -> 587,48
378,729 -> 162,513
699,658 -> 513,844
447,410 -> 670,410
739,593 -> 889,443
83,970 -> 964,89
276,406 -> 276,191
860,75 -> 247,688
435,858 -> 435,905
691,893 -> 691,757
136,896 -> 611,421
693,211 -> 477,427
181,793 -> 181,717
674,326 -> 664,336
938,826 -> 164,52
833,380 -> 833,753
833,349 -> 230,952
662,870 -> 662,23
974,511 -> 145,511
38,579 -> 57,579
966,965 -> 966,498
641,217 -> 240,618
418,986 -> 834,986
971,716 -> 971,263
254,313 -> 254,823
61,790 -> 61,834
262,439 -> 262,864
345,856 -> 894,307
736,862 -> 281,862
814,636 -> 814,240
853,865 -> 853,22
792,106 -> 207,106
647,303 -> 531,303
506,706 -> 337,706
402,140 -> 402,958
899,796 -> 669,796
806,619 -> 463,276
340,347 -> 340,363
18,21 -> 979,982
395,214 -> 395,862
228,330 -> 333,330
723,950 -> 723,150
392,298 -> 36,298
916,118 -> 114,920
210,854 -> 80,724
212,206 -> 513,507
44,659 -> 161,659
771,44 -> 198,617
485,706 -> 169,706
385,455 -> 308,455
390,317 -> 390,385
492,532 -> 56,968
237,674 -> 712,674
988,909 -> 254,175
86,276 -> 448,276
688,418 -> 927,179
667,773 -> 504,610
968,974 -> 109,115
843,54 -> 843,265
19,249 -> 19,437
307,326 -> 341,360
531,891 -> 531,202
281,535 -> 270,546
503,305 -> 164,644
170,971 -> 30,971
763,247 -> 946,247
795,920 -> 623,920
673,16 -> 899,16
785,845 -> 290,845
68,614 -> 68,711
284,984 -> 67,984
787,942 -> 120,942
953,369 -> 773,549
927,727 -> 315,115
884,686 -> 254,56
432,276 -> 432,287
658,99 -> 81,676
622,917 -> 679,917
938,978 -> 938,793
945,15 -> 369,15
603,709 -> 603,74
670,422 -> 222,870
190,702 -> 190,362
354,349 -> 369,334
26,880 -> 876,30
636,31 -> 636,731
778,628 -> 778,25
23,483 -> 170,483
23,972 -> 963,32
725,308 -> 384,308
97,962 -> 620,962
136,929 -> 136,768
656,295 -> 851,295
125,801 -> 755,171
120,32 -> 553,32
698,196 -> 286,608
66,721 -> 66,836
931,680 -> 931,499
862,449 -> 862,743
71,143 -> 180,252
510,327 -> 612,225
932,874 -> 352,874
599,372 -> 583,372
821,770 -> 126,75
317,186 -> 495,186
557,710 -> 56,209
895,866 -> 306,277
571,948 -> 571,738
287,864 -> 243,864
802,728 -> 802,198
711,642 -> 983,642
969,922 -> 969,645
89,417 -> 57,385
567,967 -> 567,781
350,498 -> 142,498
92,931 -> 988,35
980,940 -> 152,112
55,944 -> 679,320
669,410 -> 669,679
151,431 -> 241,431
984,882 -> 80,882
431,374 -> 431,39
30,91 -> 765,826
730,228 -> 80,878
379,570 -> 705,570
67,398 -> 67,136
491,515 -> 491,344
396,453 -> 749,453
203,660 -> 203,579
912,900 -> 912,280
909,88 -> 367,88
41,942 -> 825,158
724,417 -> 17,417
463,536 -> 170,536
715,737 -> 715,134
627,453 -> 805,453
934,795 -> 695,556
404,729 -> 738,729
973,685 -> 973,310
563,348 -> 771,556
716,232 -> 983,232
975,183 -> 975,759
934,958 -> 117,958
538,806 -> 538,84
695,677 -> 629,677
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
def load_input():
bins = list()
with open('input') as fd:
bins = [0 for _ in range(9)]
values = [int(i) for i in fd.read().strip().split(',')]
for value in values:
bins[value] += 1
return bins
def step(bins):
temp = bins[0]
for i in range(1, 9):
bins[i-1]=bins[i]
bins[6] += temp
bins[8] = temp
return bins
def part1():
bins = load_input()
days = 80
for _ in range(days):
bins = step(bins)
result = sum(bins)
print("Part 1:", result)
return
def part2():
bins = load_input()
days = 256
for _ in range(days):
bins = step(bins)
result = sum(bins)
print("Part 2: ", result)
return
if __name__ == '__main__':
part1()
part2()
3,5,1,5,3,2,1,3,4,2,5,1,3,3,2,5,1,3,1,5,5,1,1,1,2,4,1,4,5,2,1,2,4,3,1,2,3,4,3,4,4,5,1,1,1,1,5,5,3,4,4,4,5,3,4,1,4,3,3,2,1,1,3,3,3,2,1,3,5,2,3,4,2,5,4,5,4,4,2,2,3,3,3,3,5,4,2,3,1,2,1,1,2,2,5,1,1,4,1,5,3,2,1,4,1,5,1,4,5,2,1,1,1,4,5,4,2,4,5,4,2,4,4,1,1,2,2,1,1,2,3,3,2,5,2,1,1,2,1,1,1,3,2,3,1,5,4,5,3,3,2,1,1,1,3,5,1,1,4,4,5,4,3,3,3,3,2,4,5,2,1,1,1,4,2,4,2,2,5,5,5,4,1,1,5,1,5,2,1,3,3,2,5,2,1,2,4,3,3,1,5,4,1,1,1,4,2,5,5,4,4,3,4,3,1,5,5,2,5,4,2,3,4,1,1,4,4,3,4,1,3,4,1,1,4,3,2,2,5,3,1,4,4,4,1,3,4,3,1,5,3,3,5,5,4,4,1,2,4,2,2,3,1,1,4,5,3,1,1,1,1,3,5,4,1,1,2,1,1,2,1,2,3,1,1,3,2,2,5,5,1,5,5,1,4,4,3,5,4,4
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
pattern = re.compile('(\d*),(\d*) -> (\d*),(\d*)')
def load_input():
data = list()
with open('input') as fd:
data =[int(i) for i in fd.read().strip().split(',')]
return data
def part1():
data = load_input()
min_pos = min(data)
max_pos = max(data)
fuels_list = list()
for pos in range(min_pos, max_pos + 1):
fuels = 0
for crab_pos in data:
fuels += abs(crab_pos - pos)
fuels_list.append(fuels)
least_fuel = min(fuels_list)
result = least_fuel
print("Part 1: ", least_fuel)
return
def part2():
# Second part
data = load_input()
min_pos = min(data)
max_pos = max(data)
fuels_list = list()
for pos in range(min_pos, max_pos + 1):
fuels = 0
for crab_pos in data:
dist = abs(crab_pos - pos)
fuels += dist*(dist+1)/2
fuels_list.append(fuels)
least_fuel = min(fuels_list)
result = least_fuel
print("Part 2: ", result)
return
if __name__ == '__main__':
part1()
part2()
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,3,443,2,394,403,176,454,60,126,959,781,426,212,194,65,26,100,1047,718,29,1124,515,723,74,969,717,228,50,39,1074,1799,1276,505,477,9,742,804,191,133,730,26,272,139,501,549,318,1164,1019,399,2,224,1807,421,191,594,168,336,13,271,571,385,1071,1316,1796,673,417,1518,1152,196,1307,262,217,167,696,64,84,844,312,1770,371,517,11,450,745,80,382,367,1527,79,1002,878,298,147,57,24,1282,291,338,911,60,622,508,513,53,404,339,672,440,168,1302,246,116,446,502,1402,398,1686,118,600,865,131,48,162,1614,255,1104,1379,85,115,38,9,483,629,28,157,238,727,27,142,766,716,393,19,115,220,1103,397,1330,1027,667,0,678,464,1431,549,976,456,1403,683,749,600,711,159,98,1000,606,478,428,612,790,1202,1461,713,533,1643,53,29,1,261,268,466,478,187,256,134,373,1239,17,727,574,1206,854,88,27,51,544,793,100,1146,49,166,317,325,506,64,3,255,951,747,274,926,664,531,72,443,1088,91,259,725,100,41,1709,239,101,119,1472,437,91,360,539,96,498,78,825,103,621,216,274,402,133,446,263,1167,212,607,1596,17,113,814,528,56,128,388,686,1179,43,886,58,633,33,186,808,220,98,15,947,1074,612,328,979,1203,562,938,207,35,484,812,616,218,207,249,117,136,39,914,951,122,252,23,1,194,132,366,1004,4,1079,832,510,103,1024,203,398,1543,17,995,961,195,79,1070,1222,53,143,91,223,6,645,175,512,424,471,829,153,126,332,586,543,460,594,105,122,220,432,197,243,73,121,454,765,99,186,35,478,113,1526,305,596,102,365,38,1053,628,24,425,962,570,170,457,268,518,339,32,78,600,8,154,530,641,1889,74,58,1047,166,100,923,687,1280,1144,1260,405,1786,22,694,243,284,1109,503,650,633,52,236,661,620,54,642,130,697,718,259,244,52,387,347,459,724,661,535,354,53,105,246,493,538,894,0,368,67,151,2,127,724,705,237,512,557,573,829,789,61,415,131,526,982,206,73,46,82,411,1670,1350,34,654,190,160,575,669,21,830,34,1233,371,819,360,271,173,420,38,112,273,115,493,40,51,634,844,281,613,193,10,111,567,52,17,1137,117,105,122,250,72,70,1038,210,1008,191,99,1123,1641,90,1306,47,385,835,395,1057,1036,4,127,103,486,205,138,929,286,46,641,1041,490,399,178,1492,421,106,275,741,1196,15,174,700,892,8,818,215,436,624,459,415,812,28,196,921,119,333,896,541,117,926,1084,276,222,361,325,23,1295,205,384,207,863,659,22,89,21,110,269,157,385,422,941,629,1511,544,701,404,489,38,495,507,238,132,753,119,459,145,120,984,313,973,1049,158,372,317,596,1024,177,256,23,6,527,1439,592,743,104,414,256,418,425,271,58,583,0,164,277,1285,809,125,391,843,70,69,194,250,611,287,2,389,1469,555,552,28,236,278,178,314,368,254,86,240,72,204,8,856,28,312,236,464,144,405,433,28,42,16,587,22,403,1234,744,484,48,180,238,47,384,1315,13,78,9,882,70,551,58,756,111,777,340,1046,185,83,412,19,527,514,355,350,1198,913,154,87,507,76,1108,392,361,1081,75,1083,201,896,1161,1267,46,420,79,702,879,348,622,68,611,180,515,37,186,435,1485,438,699,1441,1122,85,145,1372,68,2,621,147,503,156,993,496,536,359,485,657,152,585,681,908,294,398,4,190,33,197,304,157,38,77,922,1033,166,85,411,544,1688,81,192,111,561,212,176,291,44,76,465,35,6,110,1329,1702,53,70,82,4,1141,278,483,66,9,115,733,856,18,1167,282,100,11,605,673,1093,1268,1633,1632,570,847,575,160,8,335,5,27,489,3,1669,1072,571,144,460,15,200,15,108,473,527,775,818,87,359,46,665,191,635,1122,289,457,169,17,42,395,1258,189,253,1292,69,370,419,47,79,22,668,655,274,60,1012,428,246,248,1181,520,760,1274,320,608,65,137,722,386,275,252,1221,729,421,265,171,84,9,3,8,1328,86,939,890,986,34,156,245,1896,617,1733,346,751,1281,244,346,56,196,380,426,810,233,353,28,147,307,131,1529,1173,68,862,1048,774,571,699,163,306,385,368,150,651,316,517,47,508,407,452,315,257,1652,73,222,1187,1635,1268,48,301,247,308,211,149,1300,141,113,57,152,498,450,34,376,748,442,670,358,105,587,66,0,285,46
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
def get_unique_digits(data, digits):
digit_sizes = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for digit in data:
if len(digit) == digit_sizes[1]:
digits[1] = digit
if len(digit) == digit_sizes[4]:
digits[4] = digit
if len(digit) == digit_sizes[7]:
digits[7] = digit
if len(digit) == digit_sizes[8]:
digits[8] = digit
def load_input():
data = list()
with open('input') as fd:
for line in fd:
observation, output = line.strip().split('|')
data.append([observation.strip().split(), output.strip().split()])
return data
def part1():
data = load_input()
digit_sizes = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
count = 0
for observation in data:
for digit in observation[1]:
if len(digit) == digit_sizes[1]:
count += 1
if len(digit) == digit_sizes[4]:
count += 1
if len(digit) == digit_sizes[7]:
count += 1
if len(digit) == digit_sizes[8]:
count += 1
result = count
print("Part 1: ", result)
return
def part2():
# Second part: Just ugly
data = load_input()
digits = dict()
count = 0
for observation in data:
known_digits = list()
get_unique_digits(observation[0], digits)
get_unique_digits(observation[1], digits)
six_size_digits = [digit for digit in observation[0] if len(digit) == 6]
for digit in six_size_digits:
temp = set(digits[4])
temp.difference_update(set(digit))
if not temp:
digits[9] = digit
six_size_digits.remove(digits[9])
for digit in six_size_digits:
temp = set(digits[1])
temp.difference_update(set(digit))
if not temp:
digits[0] = digit
six_size_digits.remove(digits[0])
digits[6] = six_size_digits[0]
five_size_digits = [digit for digit in observation[0] if len(digit) == 5]
for digit in five_size_digits:
temp = set(digits[1])
temp.difference_update(set(digit))
if not temp:
digits[3] = digit
five_size_digits.remove(digits[3])
for digit in five_size_digits:
temp = set(digits[6])
temp.difference_update(set(digit))
if len(temp) == 1:
digits[5] = digit
five_size_digits.remove(digits[5])
digits[2] = five_size_digits[0]
rdigits = dict()
for i, digit in digits.items():
rdigits["".join(sorted(digit))] = i
value = str()
for digit in observation[1]:
value += str(rdigits["".join(sorted(digit))])
count += int(value)
result = count
print("Part 2: ", result)
return
if __name__ == '__main__':
part1()
part2()
defabc gcb dbafcg gc gcbed fbecgd begfdac fcbde cfge debag | gfce fgce bdefgca aebgd
eabdc egbda bagcef eg fdageb beg bcfdag egdf agbfd cbgdafe | fdbga bge ebg eg
gfbda feg eg afgcbe fbdcag bfedg gead ecfdabg dfecb gedafb | gedbfa dgae degbf gefdb
ecadfb edg defgcb ecbda fbagcde ge dbeag gacbed agec bdfga | debcaf geafdbc gedab egabd
gcedbf bfeag bcgfdea bcgdaf eg gfe gace cgefab gabcf edfba | gbcfa gfe gef eg
bd bcdgefa dab gcdbaf dabfec cedab gcafde bgcae cafed debf | efcdab dba ebdca edafcb
cdaef fbcedg gdaeb gedcfa cgaed bcfaed gc ceg cgaf eadfbcg | cdfae acfg adbcefg cg
cagbed fbedca cfgdabe ecbda aedfg bcge dfagbc dceag cdg cg | abdec cgd bagdecf eadbc
adbfc fdcabg bg ceabfd bfg bcefga cgbd fgaed fdbag cfbeadg | bfadg bagfcd aefbgcd bg
agbefc aebc cbg cb dafgce deafbgc ebgdf ecfga cgfeb fgdbac | bdfge gefca dgefac ecbfg
cgb cbefgd debac ceadfbg bgceaf gbecd fgdeb cg dgfeab cfdg | fbeacg eafbgcd abcde bfcgdae
aedf fcged abfdcg fcadg ef bgcde efc dgacef fcgbea acebgfd | edbgc geacdf cagdfe bgcfea
gdeba bcafed efbacgd efdacg febadg eg gacdb fadeb bgef ega | bdgae cagbfde cdgba edfbac
gdcae dab bgac cegafdb ab ebafcd gbadce dcefag gfdeb degab | fedabc bcag adceg egbfd
fgcda bgedfa abec bcedfg dgeac dagbe cdeagb ecd ec cfegdba | ecd ce acgde aecdg
dfage becg dceabf beacgf eab acfdgbe gbdcaf bafge fgcab be | dfgcba gcfab eacbfd gaebf
dfabc ecgad fcdabe gfc bedfcg cdagbf dacgf bdgfeac bfag gf | dcfab fagb cgfda agbf
gefcd fad bgfea cgfdea da fbecgd bdgafc dgbfcea cdae edagf | cgfbda gefdc cdea adf
fg efgb fga bdgea adbegf cfeadg fbdag abgdce bdaefcg afbcd | bgfe gebf afgdcbe dbegaf
cagbe dbca gcedfa cga dabfcge ac dgbace fbage cdgeb edcfbg | adfecbg cagedb abcd gbdce
eabdf efb be efcda cabgfd gedfab cdefabg eagb cfedgb gdfba | aebdfcg gecbfd efb efb
ecd fadce acgfd cdgfeb ec edbafg dfcaeb fcegabd abdef ebca | fdeac adcfe dfgeabc dfacbe
egcadbf fca cafbd dceba fa agcfbe fgcdba defgcb afdg cgdfb | gfbcd efdbgc af caf
beca ea fbdegca cafdbg ecagf fae bfgaed efagbc gbafc ecdgf | aegfc adbegcf ea ebgfca
bgacfed gbc fbdeac gc bgfae adcg ecbad begac dabcge gfcdbe | gcb bceagd agcd daebc
ba fgbcead gbaefd ebcfag dagcfe dfeag bdcfg adeb gadfb afb | deba eadb gbefda aecdfg
ab cgfdea dgcbfa aedgc agb efbcadg bagced gbdfe gabde aecb | aefbdgc bfdcag egbda agb
gfcd fecdb fdbeag dcb dgefb ecfab bdecfag bgdeac cd cfgbde | cbaef ecgdbf gdfbe cd
bae dgeabc fdgae aedfb be gfbcad dbecaf cbfda gfcedab cfeb | gfdea fdabc abfcegd gfaed
cegfd dcefba daefc agdcfe cgebfda fg edgcb dgf debgfa cgfa | cfegd debcfa gfd edgfc
dceabg bgcfae fb cfgeb bfc dfceg bcfdea dcfbaeg acebg gfab | aegbdfc bcefg egbac egbfc
ceadgfb cfgadb eagfb eagbcd gebcfa ge age eabdf bacfg gecf | abdef ecagdb bgfea adgbfec
gdcaf egc cebfa cfdaeg cgdfbe eg eagfc gaed fabgced dbcgfa | afgce dcafbeg eadg dgfac
cfdbe dfcgeab ab abgdcf ageb cba eadgc cgadef cdaeb deabcg | efagdc cadeb ab eabg
bgfaedc gcdfe gfbdc fbga cbaedg dcagb gbdcaf bf bfd dacfbe | cgaebd fdgce bf fbdeca
gdabcf acgbefd egafc cda adbe gbadec fgdecb ad cdegb edgca | ecagd ad dcebg gbced
afdebc ebgcfda fabge ecfgdb caefdg dcbg cb fgecd gbcef cfb | eagfb fedgc ebgfc cbfedg
eb fgcade debgfc ebc gadec dfacb ecadb aegb ebcdga dagcfbe | efacbdg cdbaf fdcegb cbdage
gdefac gbdefca aec ce fecagb bfcgda gcafd dceg aefdb cdeaf | cbfaedg cdefag cgdfa cegd
bdegaf fda da ceda edfacg efbacg agdcf bfdgc faecg cgebafd | fdcga daf afd cdgbf
gec fbdgc abdceg febgdc gbacfed decgf facgdb fcbe fadge ec | agdfe cegdf gadcbef cfedg
fbeag bgcea cg cabfed agebcd acgd cadeb cge bgedfc cgaebfd | dfgbce efcbad cge bdcae
gdaef gbafdc gafdce fcadg gedc efbgdca de dfe baefg bcfdae | abcdfe gaefd cgfade dfe
gbcdf gcfa bgdaf dagbe dcegfb bfedca afb cgebdaf fa bafdcg | af fbegadc aegbd gfac
dbgacef ceagfb cfbd ebfdga bd edb bcged aecdg bcgfe fdbceg | db gbeafc befgad dfbegc
bdf bfadeg dbfgeac degcf aebf cgfadb gfdeb bf gdeab bgcdae | fb bgdaec gcfed feba
bgdeaf gbafe cdfeag gecfba debca adgcebf dfe df fdgb efabd | bfdeagc gdbaef fgeabc acdeb
edfcga fdab df fcbead bcagefd dbcage fgebc dcaeb befdc dfe | afbd caedb ebdac cdagef
dcbeg bcag bdaec fcdbeg adcef dfgaeb gcbaed ba begacfd bea | febgdc dbceg agecdbf dbceg
agbc eafbd dgcefb afdbg gaf gdecfa dfgbc fbgcad defcgba ag | edcgfb fadbg dfaeb abefd
abfdcge fadcge gde dcfgb cdgafb gbefd eg fcdgeb ecbg faebd | cgfdb ge dbgafc cegb
ab fbcge fegdbc gab fegad gebaf bgacef ceab fcdbega bcafdg | dgfbac gfacbe gba ab
bed fdage bcafge afebd cdegba fabce fdecab bd dfcb aebfcgd | dbe dgbeafc adebcgf eabfd
cbfdeg gbafe egf bdfgea dfea abceg ef gbdfa daecgfb bdgafc | edaf fabdge ebgac fgaeb
dgba bdcgaf bcdfg bg cgdfe cgb afcdeb bdfcega bdfca gcbeaf | aefdcb dbga cgfed cdfge
gefda gfbed cgfdbea feb dbcgf bgecfd becd fgabec be dfgbac | fgeda agcbdf bdce be
bcfge ab cagbed bea acdeg gdab aecbg fcegbad bcefda adfcge | bgadce dcgea febcg aeb
dagc dcefg gfcdaeb da fgecdb bfeac ead dgfcae eacdf begfda | bdeagf cfedgab dcbgaef ead
dg eadcb fcgd eafgbd fcdgbe bfegc gecbd deg dgcbafe cfegba | ebcad gecfbd ebgcd gfcbeda
bc bgc edbcfg gbafd ecgbfa ebdc gdcaef dfbecag bgfdc egfdc | bgfda fcdgb cgeafb fcbgd
abgf dbfcgae adegf gdabe cbdeg ab bae dgecfa caefdb aedbgf | daefg fbag badfce gbdefac
cabed gabcdf eb cegad fabcgde ebd ebaf fcdeba badfc egdbcf | dbeac cdafb edbfacg eb
degfac adgcf fbgade fae ef egcabfd egacb decf efagc agbcdf | ef fcadeg edcf cgafdb
adcefg agbefcd acdfe cdfba ecfdbg ed eagfc aged edf cegbfa | fcdea gbafec efd fecdgb
dfeacb fge fbgca gfcbe dbeg eg cdefb fbedgc fdbcaeg adecgf | gef dbeg efg becfgd
ae fbdegc gfcdae fbgda fecabd gfecd gdafe edgfcab afe acge | facged adcgfe cgae bacdgef
gfbac cfebda dfg degfca dfgbc cbgdfe dg dcefb edagcbf gbed | caedgfb gdf gd ecgdbf
gcdfea dafbcg gadfc aecdbf cab ba gcbaf abdg cebfgad ecbgf | bca gcfad dcfbage efbcg
gbceaf baegd gab ga agcd gecdb deabgc afedb agebcdf fdbgec | cdgeb gab eagfbc aebdg
ebagcd dgacef gbc gdefcba cbeagf bfadc bedg acdeg bgcda bg | aegdbfc cbg fagecbd agfedc
fcbage dfbage acdebgf ed faed bafge fdegb dge bfdcg egcabd | deg dgfbc bgdefca abcgef
aeg acegd degb dagfcb fadec bgeafc bfagcde eg bdecag gbdac | acefd defca degb cgeabd
bfce fadeg fegdb cdgeb cfdabge bf acdfgb bfd edbcga cebgfd | begadc edfcbag dcefbg bgfed
gc gfac fegcd fedcagb gaedbc cafed edbfg gedafc fecadb gec | adcfe cgdeba egfdc cfedg
egcfb dbac beafcdg cbgea fdeabg gadecb cdgaef cga gadbe ca | dfcabeg cbdgea ca egbca
edgbc fdeb dcfegb cgeafdb dfcaeg gebfc daebcg bfagc fe fec | bgdefc ebdgc ebfd dgbec
bgacde abfgecd caedg ba ebfdc ecfadg bagc eba dbeac gdebfa | cdefag bafedg agbc bcfed
febacg fegda gdbacf ceab cfa cbfeg fgabcde cgaef dgefbc ac | gbcfe beca deafg eagbfcd
debg fgbade gecabf dfaeg fdaegbc gad eagbf fedac dfabcg dg | egbacfd cfead fegadb gd
agfeb cf gcead fgcea gfcdba edagfc bcadeg dfec fca cdfabeg | geacf fbage gdfacb cf
dbfae geacfd eabgc cebfga gd cbgd dfbaecg edbgac adgbe gda | dag gd caefgd gfdceab
edabcg dgaf cgbfe bcdfa efdabc edcfgba ga cag dbgfca gacfb | fdcbag gac ag bdaecg
bf efb efcabd gfba agebdfc deafcg afegd gfeadb gebcd gdbef | bfga bfeadc bcegd fbe
edfgbc fgdc cf bgecf dcaefb efagdcb gdecb bfage cfe dcgeab | dfcg ebgdc fgdc aecbgd
bdgea dgebf ebcdaf ebf fe fabcgd gcfe bgedcf ecgdfab bgfdc | egfc gbcdef bfe fdbcg
ca gdbaef adecg acdfbe cefadg caedbgf afedg eac afcg ecdbg | eadgf dgefab dgeac gadce
dfgecb adcf becfadg cgfdea gfdae dcgae fd dgcaeb dfe egbaf | efcdbg caedfg eacdg dgeafc
agcbe fba dfag fgbca cdagbef fgdcb gcefdb acfdeb af dcbgfa | dcbafe afbcg bfa cdbfg
cead ce dcefga fce afgedb cfebagd agfebc fecgd dafeg cbgfd | fedagb cgbaef egcfba gadfec
dfebga bcadge gdfebac ed beagf eabdf gbafce gdef bdfca ade | ade abcdf bagcde fabcd
adg fgdbce abfgcd ecdgaf cebgdaf gcbad ga bgaf fcbgd edbac | beacd dag fgdcb gda
dbeacf edfcbga bgcde edbac gbac dgb dcegf bcgdea gdafeb bg | cbdge bg cbag ebcda
gafcd dcae cd cgaef bfedcga gfdab cbgfea cdgebf dagcef gdc | afcdg gcd gafdb bgcdaef
edabfg gecfdb adcf abf cfgbade gbace bcfed af bface febdac | eadcbf efabgd fa fba
af eaf daebg fgebac dfaeg geadcfb cfad fedgc dcefgb fadcge | afdge ecgfabd fa fa
dcfga agfdbc db gcbefad baefg fdb gefadc dgabf fgcbde bcad | gdcfa adgbf fbd cgfdeb
cbega fgb agfceb dfbcage dbfca efga dbgefc bcagf bedcag fg | dafbc dbcfa fdbcge ebdgac
eac cbaeg ce acbfg daefcg abgfde bgdeca dbgaecf ebagd cbde | abcedfg cae gbdae ec
gadef daebgfc fge beagd fcebad cbfgde gf afced gfdace agfc | bedfcg geadb gdefbc gf
adbfcg cdbge cfeg beagdfc cbegfd bfdaeg eacbd eg fbgcd egd | ge gdcfab cgebd dacbe
ca cbega abcefdg bfcdea bgdcea abc dgac ebdag ecfbg aebfgd | adgebf debagc bgcae bca
bg edcbg gbd dabegfc dcgae aefdgc cbga dbaegf eadgcb dbefc | cbga cgab adcgeb bgca
egbdf becfga gdcae cdgef cf cdgfea faegcbd dacf cgadeb fcg | cdfge gcdabe befagc cgf
fbade ca eca eabcd cefbag ebacdf fdbaeg cdgbe facd dbagfce | fcbgdae dbace debfgca cbade
fbdceg fgade egfcd fbdacg dgcbf cbed gec ec dgbacef ecagfb | aegdf egdaf gecdf feagd
aef bacedf aedcg bfge efabcg fcbagd fe gfbac fegca abdfceg | cgafb agcfdb gbcafe acfge
bgfc defgbc cf deagf gbcdea baedcf ecfgd ebgdc dcagfeb cdf | fgaed fedcab cdefg dfega
afecbgd bgefca eca gbcaf cgfe bgcdfa bceadf ec cabeg dgabe | ce efbcagd aec fceg
gaeb eafcd dbeafg egf dbfag adfbcg bfcaedg aefgd eg decgfb | fegbda bgfecd adgfe gef
cgb baecd begdc cbdefa adbg ebafgc gcfbead cgfde bgdcea gb | cfedg ebdca adbg eabcd
egafc ac fecdg acfgdb aceb befgcad eadgfb fbgcea cga ebfga | daecbgf bcea fegba ac
afde cefbgda gabdfe cegdab feb bdgae dbcgfe fbgca eabfg fe | dgeba dgcbfe bafge gaecbfd
ceabgd ba cfbagde afdce dba ebcdg abcg fdaegb adbce defcgb | fdgbcea bacg dba agcb
gbcfed eag dceabgf eagfdc febgc bfag eagbcf abdec ag cgeba | gae aeg gfdbace gbfa
gb gbfeda cbead gebdcaf gbdf cgabef beg fgaed gdabe cfgeda | gdbf bgfeac bcead cdefag
bcda fabceg dfecg eadgbc dcgae dfabeg afdgebc dga ad cgbea | dbecag efagdb da fcbeag
gfcdae cf fabgd cdfabe gcdfa fecabgd gdeca fegc dacgeb caf | fegc fca cf aefdbc
efcgb decfga cfbga bfdca gcfbde ag eagb gfa bgcaef gcbfdea | ga egba bfecg gfdcbe
cabedf cedf ace bdace acdgb afgbec fgdeba ce fadbe afgedcb | aebfd ebdacf ace dcef
fecdg cgdfae gecbfa de cagdefb bfdgc egda gacfe ecd cdafbe | dcgbf fgaec facdeg gfcdb
gabfdec dabfge abdeg fa egcbda fdbgac adf efbad efcbd fage | gdabe bgade bfdega afd
cbgad fcabdg cbfdg cgfaed fdg bafg cdabge bfcde fg abfcdeg | bfdaecg cgadeb defcb gdfabc
defba fgae daegbf adfgbc bfadg fegacdb bef bedca ef fbgecd | befda bcegdfa ef badgf
fdgbea agfdcbe bgfeca dag da eacd dagcb becadg fgbdc acegb | ecda adbfeg bgedca cead
gafd cdbaef dbgcf gdeacbf fdacb bcdagf abgdce gd efgcb dbg | gd gbd egfbc gadf
de abdegf edgfb efd gcfedab dbgaf afcdbg aedb fegadc begfc | fde edf ecfgb edba
cbgefd da bdagcf cda cegfabd gfdcb dabcf cfgead dgba acbef | bdfcg bgcafde dbcfga bafdcg
aebfcg gfedabc eadgb bf cafgdb bfg fbce fgcea gcdfae gebaf | afgebc fb fb bgf
gc fgecbd egc gaebf gecbda acbed fcaebd cagd bcgae gfabdce | gacd egbacd abefg egfba
dcfab bgdc efagd acg gc aedcfb cdafg begcfad dabgcf cbefga | cdagf gcfda dbfac cdgb
bcdfea dgce cadfg dae agfde cgdeaf adfegcb bafge ed cdbfga | cgedaf bgfae gafdc fbgae
adgcfe dfagecb gfbcda ba cafegb fbdce eagb agefc cafbe cab | bcedf bac ba fbcde
bfeacd fcdebg fg dbaeg egdaf dcgfae gcfa efadc bcegdfa fge | acdef fgaed gf bdeag
dcgefa ceabfg fagbc beagd df fagcdeb dbafg fgabcd dcfb fgd | egafdc gabde beagd dfbc
ef bgdaefc cagdbe fbcda fgbade aef gfce eagbcf gcabe cfbea | fcdab fgce bcfad acebf
efagbc fbdag afdcb fg bgf begda aedfbcg deafgb gedf cdgbea | dfgab acfdb gf gf
edcagb ecfbadg ebdfg ega fbaedc fecdag ga dacef gfac gaedf | dgbfe ga dcafe ag
bedfacg acbfge cbg badfeg begfc fbcde ecag facdgb gbfea gc | fbced gcb eagc agebdfc
fdgca fbgce gfecd gdeb cdfagbe ed ecd fedacb gfabce dgfbec | afcgd deabfc dfagc begcfa
bfeg dge cgadf cgedf gedfbca cebfad dfebc cdabge cdgefb ge | dbcef ged eg ebfacd
ed cebgadf gefdca cfega dcaegb dfce cgaefb dge gbfda dfaeg | aegdf afgce egd deg
aecfgd fgd cedbag fgecd bfagdc feacbdg gceda gf bcdef eagf | dfbce agced gf geadc
gbcfdae fdgea bdgcae edb edgbfc fagdcb ebca be ebgda adgcb | be edb bed gcbaed
gdef df afdgcb fdb ebcgd begadfc gdcbef efbdc baegdc fabec | dgceab acbef fbedc cgbed
dcbgf feg edfacgb efgadc eg fdace afbced fcged eacg aefbdg | cbaedfg ecag aecfdb efdacg
fdbega gcebaf dacgeb eabdc gabcfde fcdea gcbd bd adb agbce | afced efabdcg afced bda
cd dafcbe adegcb edabfgc bdcga adfgb gabecf cdb egcd cbega | daegbfc afbdg cd debacg
bga becfdg gcbfad gcbdf ag baefcg eadbc dcgab fcgadeb afdg | gfbcead edgcbf gdcab bag
aedgfbc fe cgdaef fbec feg agecb bgadf bacefg afebg cgdeba | aebgcfd gfe aegbf efbcga
afcegd gbdec acd afcgbe ad cagfe gdcea fgbedac edaf dgbacf | cad dagec aecgdf da
gfedc eagcfd becagf cafed ace edbaf dgac feadbcg ca bfecdg | gdac gcadef ac eafdc
gab abfdeg bgdac fadbc gcdfba bfdeac bcfadeg bgfc bg gaedc | bg fcbad gb bg
bgeda agdfcb gdaec cd fcabedg cgabed fgcae bdefag dca cbde | adc baegd febdag eafgbd
gedbca dacbe efda bfd efdcba fd bfacd cgabf cbedfga bcefgd | bafcg baecd fecbgd cagfb
egdc fed ed bgfced bfacd ebagcdf dbefc ebgdfa agbefc cfgeb | bfegcd cfebd agdcbef cafdb
bdg bdfga gdfca dfbae gbafcd fbgc eacbdg aegfcd bg dgceafb | gb bgd gfacde gbcf
egdbc badfec caebg cegdab ed bcdfg aedg afdcegb gfaceb bde | agde adge de egda
adef gdcfba adgbecf af acegb fab bfadeg bfega dbgfec efdbg | bcgea fdcegb degfcb fbedag
gbfe bcdgaf edfag gae gfdeba cfdbeag fgdba gebcad ge cdfea | cgfadbe bgef agcbed cgdfab
dfeca cdbg edafbg gcfbead bcafg cfgadb fgd bfgace dg cgadf | gfcda bgfadc cbgefa gfd
fbaecd bf dacfebg dcfge ecbgf gabf cegfab caebg bfc gdbace | abcge cegab egfdabc dcfeg
cbdfag fgbec gdabfe gfdbaec bdgfc ef fbcdge fbe agceb fced | gbfdc fe cegab cgebf
fdebc adfgcbe acebf fdac df dfb bdaegf abecdf abcegf bgedc | gbcefa ecbgd bafec dbecg
fadc fgc gbcdf bcdga edgfb cegbaf fgbdca fc debgca dafcgeb | dfcbag cabdg fbcgd afcd
dgcef dcgbef afc adfce feagbdc ac deafb cdag gcdfea befagc | ca cfegdab efcda fdeca
febgad ag gdeab afdbecg dcgfbe agfbec fbegd gfad aeg dcaeb | ebgdf abedc dgaf dfbge
daegcb agbcd edg bafdgc faecg gadec bfcgde abde ed fecagdb | baegcd edba efgac cefag
adbcf gcaf bgdac gecdfba efdba fdbcga fecgbd cfd cf adgceb | dcbag abdfc fcd fcd
cfedb cfa acefbd afbdcg edcbafg bfeag acebf ac ecdbgf adec | fedcb edcfbg bfaec gecfabd
cef befdcg dafeb cefdag fbdaceg fadec fc agced bdgace acfg | agcde daefc afcg cgaf
ebagd gd gfdbace fagbde febad gfdb dcebfa dcefag edg gcbea | dageb dg gde gd
de gdecfb baefg fedbg ecdf bacdgf bgfdaec dge acdegb cgdfb | dagfcb dcfe ed de
adgfc ad dcea caefgd cgfdb bfaegc afgec egafdb fegbdca fda | da gfedab ad afd
abf cdgfae acfbg gecbadf ecba efabdg cabgfe gbcfd efagc ab | acgbf fegacd acegf abf
cgbaefd cdage dgef geacdf agfdcb dacfg gcaeb cdefba ed ead | abfgdc abdgfc dagcfeb baceg
fgdec cbfa bf gbcfeda dfb fadbge acdeb dbfce cgbdea cdefab | cfegd fdeabc badecfg dgcfe
eba dacgefb deacb gabfde ecgadb cbdef cage gcbad afbdcg ae | gdfeba ae dfbec agce
daebc gcdeabf bgcfea agfeb bdega dgbeaf dgfa gdb gd bfcged | febdcg egfdcb bdace gdfa
gcbaef fdgbea adgfce bgefacd fdbg egdab daecb gbe bg gfdea | fbdg dfbg aefdg bdfg
dbgfce ec faebg fec fagdc cefga fgecda ebfgcad cdae dgbcfa | cadgf dgbeafc cgeafd ec
gabcef edacbfg dba agecb bdce dacgbf dgcaeb eafdg gadbe bd | dfgea db adb cbdgaf
cbfdgea fbdgca bedagf ae dae bfedca dacfb feca bcged adceb | ea ae fcea ead
daebgc db bagecdf bdaec fgdbea dfeac bgfeca cgdb bed gbaec | dfecbag ebacd bed db
agdcef fdaeg fbcdaeg cbgdae afgbd fea cfde eagcfb gdace ef | bgecda afe defc daegf
dcaegbf fdgeba ad dbafe defbc faebg dacfbg daf egda cfaegb | abedf bfdaeg dbfgea cfagbed
geb bgafecd bcae fgabce aefcg be gadfec gfebc bgdfc gbfeda | ebac be fgace dfebagc
cdfegba eafdc afcgb abcfge bfgd cfagbd adg dcafg cebdga gd | adbecfg cfagb dabgce cafbg
geaf fg acbgd fgd dgfcbae dbaef fgbda ebgdfa egfcbd acefbd | gcdba edfbgc ebcadf gf
cbgfe egac ce ecf bgfeca cbdgf fgbdea fbgceda geafb eafdcb | gecbaf adebcf efc ecf
fcd gfbcd dfbge dc gcbefad dcag afebdc gfbac efabgc fadbcg | bgdfc bcfga bfgdc cd
dg dgeb acedbg bdfagc faceg cfagdbe ebadc daceg afbdce cdg | gdaec afgec gcd eacdb
badeg dfegab efgadcb ad fgcdbe egbdf gcdeaf gad dafb bgcea | dgaeb bgdfe agdbe fbaged
deag ea gabedcf decfb dcfea fcdgae fgcda dgcfab cegabf fae | dcagfbe gafcde fedbc fdbacg
eacfg bged cgdafb dg cegad dgcbea bceadf adg gbdfcea baedc | bcfadg gcfae gbed eabdgc
efdba cegafb bcgdfae gdabe cefbd aef af ebgcdf ebdcfa facd | fdabec gfbeca fea adfc
ab fdeba cgefbd fdgae bea fbdce bdafce egfacb ecbdagf dabc | eba gdafe bdaef gfbeca
feadcb dgfabec gdafb cb ebgc fdcgbe cagefd dfgcb fgedc bcd | gfcde gdcfb fgbced decbfa
fabcde cae ecbfga agbed fbacg cegf cgdabef dbagfc ce acbeg | gbdea gcebfa fdeabc baceg
gfebca cageb dbfcaeg ed aecd edg bdegca ebgafd fcbgd gbdec | fbacge dcebg acde edca
bfgedca ec gacfd gcafbe decb cef gdafeb afebdc efadc dfbea | bdec cfeabd cagfd feadc
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
pattern = re.compile('(\d*),(\d*) -> (\d*),(\d*)')
def load_input():
data = list()
data1 = dict()
with open('input') as fd:
for i, line in enumerate(fd):
data.append(list())
for j, height in enumerate(line.strip()):
data[i].append(int(height))
return data
def get_neighbours(data, point):
neighbours = list()
adjacents = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for adjacent in adjacents:
y = point[0] - adjacent[0]
x = point[1] - adjacent[1]
if y >= 0 and x >= 0 and x < len(data[0]) and y < len(data):
neighbours.append((y, x))
return neighbours
def part1():
# First part
data = load_input()
low_points = list()
for i, row in enumerate(data):
for j, height in enumerate(row):
neighbours = get_neighbours(data, (i, j))
neighbours_height = [data[neighbour[0]][neighbour[1]] for neighbour in neighbours]
if min(neighbours_height) > height:
low_points.append((i, j))
result = 0
for low_point in low_points:
result += data[low_point[0]][low_point[1]] + 1
print("Part 1:", result)
y_size = len(data)
x_size = len(data[0])
return low_points, data
def part2():
# Second part
low_points, data = part1()
basins = list()
for low_point in low_points:
basin = list()
basin.append(low_point)
last_neighbours = basin
while True:
for last_neighbour in last_neighbours:
neighbours = get_neighbours(data, last_neighbour)
basin_neighbour_found = False
for neighbour in neighbours:
if neighbour not in basin and data[neighbour[0]][neighbour[1]] != 9:
basin.append(neighbour)
basin_neighbour_found = True
last_neighbours = neighbours
if basin_neighbour_found == False:
break
basins.append(basin)
size_basins = [len(basin) for basin in basins]
size_basins.sort(reverse=True)
result = 1
for i in range(3):
result *= size_basins[i]
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
6587893456954341398543210234567899875421012578932123459998764323569999996432345899989359878998654345
5476894579873210197654328757678910976532323457891012398997653212998798789521256789879498764679795456
5345679989864321349865479869799929987643498598932923987989543209876697654320145679965987653567989767
3235678999965443567976567878999898997654587678949899876878994319965498765421236789764398532479879878
0124789339897764678987878989998767898986798989298798765756989498754349899535456899879987691298568989
1235693219799865889698989990987856789997899592139679984445678987643237998646567890998698989987457899
2348789398678976789569999921976745678998985431095459873234569998765145689987899932349579768976567978
4567899976599989895478999899875435899359876545984398765145678999843234567898976543998498657697798964
7688999875487899976789298767986546789999988769873239876234567892954345678909997659876597646579899543
9799998764325578987899109654397967999879999898764346984345678921986456789319889799989986534466989542
9989879875413467998998923993239878998758999969975899876476789210987567895498779989992395421355678954
9876569974324678959987899889101989987646489459896789976567894321297678976987667879893987510134569999
8765498765456899769996798767992493499832367999789893987678965456998989989876546758789997921235678988
9874349876567998998965689656789569989753458987678962398989879599879799992965434345678986437367889876
8765456987678987987654678945679678979768667896569541239899998989965678901977321237899876545459993998
9876567898789996796543489939798989764979778965499432345789997879974589919898934348901997668567892109
9987998999896789899755569898987897653989899012378945497899965467893469898789895459919898877679954919
9898919789965678989876798767346789762399943234569767989999854359932599787698789667899769989789899897
8759105679654569878998899856235999321239854355878979879998765567893987654589678978998953599896798786
6543214598979698968899999843123568910198765467989998767899976779964599643279567899687892498945697655
7954323497898966556789987654013467892499976589099987756789987889995798732153456789576931987432398543
9899435986577942347896598732123458999987899693239865347991298999989987643012348894345899876541239432
8798949765456891238965439653234567898976798789399876456789459999879876532145457896876789987832396543
7686799887347920145976549878347698987755679899989986567897667898965987674234668999987895498743987965
6595789998967891247897656989498999876544587999879987678998778987864398765545979998998989359654599876
5434678999298932346789767896569098987623456796567898989539899876543219876656897987889874298765678987
4323576789399543456789978998789197898212345679335679999421921988754301998767986576569763189896789198
3212345789987676577899899239899976789853458789124679878999890199865492999878975432478952076999893239
4523456897898787689998789129998765698767569991012399865788799345987989899989896543578943145698994345
5635567896789898799029569098899987999878978962193987654647678976799878799998798654567899239987989469
8756678935978999898998678987799999899989989643989996543234567897898968678987698785678998998795878978
9897889123467893967899789876678999768393498959878989654346778998987654567896539876789457789654769899
6998993234679932456999899865589996543212347898765578995487899989998785678974323987992345678943456797
4349965345789531345799987643499987664324456987654456789598999878999876789865434598943567889752589895
6459876459999910239898798101989198976535967899532345678949988767899989899989545999759878997643569994
9878987767899891398989543219879239987649898998721235789039879857999994978998769899998989498957698989
7999999878986789997679654598768945798959799987632345892129967234678943567899898798767894329878987978
6989987989345679896598995987654999899898679876543566943298654123487892389989987657656789210989876569
5978996591236798789456789998743878998786567987664689954679942012456799459876799543234568921298975497
9769889432445987679345699865432459987675478998785799895799842123867898967995698432123556932967964326
8958778956759876531256789987543579876564367899896895789998763435798957899854597543012345899859873214
7643568997969765430347893987654678976444259899987924556799878976899645798643498632124556789645995403
8532456789879876321346932398767889987320145789699012345679989987896536899854987653246787896539876912
7421345678989985442457893599898994598321237894556923966889999998998745698765698764345678954321989893
6530496989498996584668999989999213469644345892349899897899999879799656789876789875456799987553598789
7699989892397987676789998979992101278955456789498756789999898765688979897987894989667976599679699667
8987979789986599987899887968989232349866667899976546689998765544567899956598923499878987698798986545
9976867678965434598999765457678945458978878999895634578987654333456989645459012398989898789987654436
8765454567897665679998654346567896567989989998764323689999765212345678932399923987698789892498742123
6874343789799779789876543213458998678999799987653212387921976924566789543989899876554678943985431012
5432102345678989999965432102349999799987678987654501276892989896677899959876798765432567899876543243
7643412456789999989878676413456899989876469898876612345999898789998998899995439876753458976987654354
7655324577897899878989654329567988764514345789987843456798766599889987689984323987764967894398766456
8786734678976799767998765567978976543101234599998954567899954349778996569876212398876878999989877767
9897645689565698757899887679999098654332345698999875678999843234567897678965104569997889798976998978
1998756789434569943535998789899129786445689997999989899998785123456998789874315678998996567895329989
2349967896513479892124569896788939896576898786789996921989632013667899892965326679019965456996210197
3959879974323569769023456975767945987687987675678985439876543124589976920976434567997894346789321256
9899989965434679658934567894556899998999876554567976545987654565697895439876565879876543235678932345
9768999899565798747895879913445678989678965423456897656898765677796796549987676789998432126799543556
6756897788979899656789989101236789676569874312345798968999879788954789678999789899987643235689699789
4346796567898998767899894212345896545456965101276789879998999899432688989989892968998754345678988999
5657893456987899878998765523466789634349876514567892989987656999543567899876901259789895466789877889
8789932678976789989579865434567898722298765423698921291296545678957678998765432345678976989898656878
9897643789865678996469876558778969810129895434789210199986534589998989349876553499899989999986543566
8987654898754567902345998669899654323345987567994391987673323467899995456987694989999999999986432345
7898765998843236899458998789998969834589998989879989876542012456945896678998989878998788898976521289
6569976987654345678967999898587897655678999898765779765432135578935789789459976568986577667898432478
9439898998765469989998987967476789767789988766434568976543234689124678992349865457997402456789543567
8998789659989598898989876653345678978999876654323456897654345691012567891998754349876212398897654678
7987679743497697767878965422234567899999875421012698998765676789323456789876542298765435678998865789
6592578932398986656467897910123456979899986534123589239876797896454567997984321059876568789999976890
9421349890199875433356789891954569456798986546254678998987898989765679545975472347998678899897989921
8210445789987654321245898799895698969897698755378999467998949678976889439986567656999789998796597532
7421234894599943210134987688789987898987549875489312359879234567987899998797678797899899989689459843
6439345943239874321345798454698976767895434976678954598762123456899999897698989989989979876568998754
6598997894999765633466954343567895456795323987889895689953234567999898789439899879876569965457998765
7987889999889876545789875212398954346789412398998789998764348789898775678919789767996498754345689896
9895678987676987986791995101457893244898901999975698789765459898799654567997637657984349843234569987
8654567896565698997892983212346789123457899899894987699986567899654523456789521749873249654445678999
7643298789434569898939865423567891012346798798795699789297978999543312978898430123965398979966989645
8964345679323458789920977674578942199967989689589999892198989998662106899986521239877987897897895434
9876798789012345699891988795689543987899876567477899943019799987543245679199542345998976545789999321
2989899893123556798789599876897659896789765435356789942165678998765358989098993556799865434668998910
1094945943238767987699432987999798765679976321234567893234569679878767899987689698899987323457897892
9943237895445898958567941098998999654789897542348788954345689456989878999865567989989865412368956789
8832146789556999543479892129987678932396789656569899995456791349897989987654349878878954323779768999
7654258997697976432358789234987467890145698767678998789767890998756399899785498765469895965689979889
8765767989989999751234689345986358943235699898989998689878999876543268799996789874399769898789898776
9979979878879987642956796569875467894346789969799987578989998987654156678998992986987656789899787545
9898998765968899799899898679989878976459894356678965467899887598721034567899321987896545678998676434
9767897654656789988778999789398989997568999234579874356789756459842125788965439999999767899876545323
8656789843234899876567899892127898987678988946698763244578942398763236999877898999899978975975432102
6545678952123678975457989942016567898789767897987653123569321987654349989989987998799989764986548726
2135678953234567894345678932123459989894356789796542012459432798789498978990196754678997653297659645
6545699975545678943234569643234569878943234598679765423498943679899987867891985653589987654398799856
7678789987656989434126678964365798569892125679569876536567894567998766756789873542357898765989923987
9989890199788999321018999765456987456789287894379987789879976898987654347898762101237789889875210198
0198931369899998732129678976569876345994399965456998897989197899599875456999854345345679998764321239
1987642456910987654334567897679985456895679876597899956791098965431986567899965456786789459875643467
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
pattern = re.compile('(\d*),(\d*) -> (\d*),(\d*)')
def load_input():
data = list()
with open('input') as fd:
for i, line in enumerate(fd):
data.append(line)
return data
def part1():
# First part
data = load_input()
# data = ["{([(<{}[<>[]}>{[]{[(<()>"]
pairs = {
'(': ')',
'[': ']',
'<': '>',
'{': '}'
}
values = {
')': 3,
']': 57,
'}': 1197,
'>': 25137
}
errors = list()
remainings = list()
for line in data:
expected = list()
opened = list()
for i in line:
if i in pairs:
opened.append(i)
expected.append(pairs[i])
if i in pairs.values():
expect = expected.pop()
opened.pop()
if i != expect:
errors.append(i)
break
else:
expected.reverse()
remainings.append(expected)
result = 0
for error in errors:
result += values[error]
print("Part 1:", result)
return remainings
def part2():
# Second part
values = {
')': 1,
']': 2,
'}': 3,
'>': 4
}
remainings = part1()
results = list()
for remaining in remainings:
temp = 0
for i in remaining:
temp = 5*temp + values[i]
else:
results.append(temp)
results.sort()
print("Part 2:", results[len(results)//2])
return
if __name__ == '__main__':
# part1()
part2()
{{{[(<<[[[<<([[]()]<()<>>)((()()))>([(()><{}[]>]({()[]}))>{[{(<>[]){{}[]}}<({}()){{}[]}>][<<(){}>(()<>)>{[{
{<<((({{<<[<<{[]()}(())>([[]()])><[[{}{}]<[]<>>](({}())[{}<>])>][([{[]{}}](<<>{}>{()()})){({[]{}}<<><>>}{({}
(<[{<{<(<[[<<<[][]>(<>)>><{<(){}>{[]{}}}<{{}[]}{()[]}]>][<([{}<>]<[]<>>)<{[]()}[()<>]>>[{{<><>}<<>{
([{([{{{<[[{[{{}()}<{}[]>]{{<>()}<()>}}{<<{}()>{<>{}}>}]]<(<<[<><>]<<><>>>{<{}()>({}())}>){(<{()<>}><<<
{(<{[{[{([<<{<()()>((){})}[[{}{})<()[]>]>>{([<{}<>><<>[]>]<{<>[]}[{}<>]>){<[<><>]{{}{}}><(
[<([<(<{[<[{<<()[]>{()[]}>}{<[{}][[]{}]){[()()]{<>[]}}}]>{(<(<[]()><{}<>>)(<{}<>><{}()>)><<(<>())>>)
(<{<[<[(({([(([][])([]())){(()[]){[][]}}][({[][]})[[[]{}]({}[])]])}{{{[{<>()}{()[]}](<{}[]><[]<>>)}<(
<<(({([[[([{[[()()]{<>[]}]<[<>[]]({}[])>}]((<[[]())(()<>)>(<{}()>([][])))<([<>[]](()[]))>))[<[[<{}<>>([][])]
(({[{[{<(({([{[]{}}(()())]{{()()}<<>()>})([{{}{}}[{}{}]]<<(){}>[()<>]>)}<{{(()[])}}{{[[]()
[<{<<<{<[[[[(((){})(()[])){<[]{}>}](<[<>[]][<>()]><[()<>]<<>[]>>)]({{[<><>]}<<<>{}>[{}<>]>}[{{{}{}}([]{})}
{[<({<{{<([(<<<>{}>{<>[]}>{{()<>}<<>{}>})(<<[]>((){})>)][<[<()<>>[()]]<((){})<<><>>>>[<{()[]}<{}[]>>]])>}{{<
([[<{([{<<[{<[{}<>]{<>{}}>{[(){}][()()]}}<{(<>[])(<>())}([<><>])>]>{{{<([][]){<>()}>{([]()><()()>}}{{({}()
(<[[({{<([[[[{{}<>}[<>()]][(<>[])<<>()>]]]([([[]()][()()])]([[{}[]]<{}[]>]{[{}<>]{<><>}}))))>(
<<{[([(<<({{([{}[]]<<>()>)<<()[]>[{}<>]>}({(<><>)[{}()]})}[{<[(){}]>{{<>[]}[<>{}]}}[<(<><>){{}[]}>{{<>{
[<({[({[<{[(<[{}()][{}<>]>{{()[]}(<>())})({{{}<>}<[]()>}{<()<>>})]}[<<{{[]}({}{})}([[]<>][()<>])>>[[[
(<<[[<{<(<<<<[()[]]<<>()>>({[]<>}[[]()])>([<<><>>](([]()){[]()}))>{<[{{}<>}<<>[]>]<<<>><[]()>>>{
<[[{[<({{[{(<([]())<{}[]>>(<<>{}>{<>})){[{[][]}{<>[]}]{[[]{}]<[]>}}}<<(([]{})[<>{}]){[{}()](<>{})}>[[([]{})[{
([(<[<[[{([[(({}{})[(){}])([<>[]]{()[]})]([[()<>][<><>]])]{[<{[][]}[[][]]>{<[]()><()[]>}]<[(<>())<<>{}>]>})}
([([{<<{{{({<<<>[]><<><>>>[[<>[]]<[]()>]}<<{[][]}[{}<>]>{[<>()]{()[]}}>)[[[<<><>>{(){}}>[({}[
[[<[[({{(<[{<{[]{}>>({[]()}{[]<>})}{(([]{})[<>{}])[(<>{})<[][]>]}]>){{<[{<{}<>>}<([][])([]<>)>]((<(){}>(()
([[{<[<((<{([{[]<>}({}[])]){{[[]]{<><>}}[<[][]>([][])]}}{[(((){})([]())>]{{{[]()}<<>()>}}}>){<[(
{<(<{{<{[{<{{<(){}>{<><>}}}[{[{}<>][{}<>]}[[[]{}](()[])]]>}][<<<{[{}[]]<()()>}(((){})[()[]])>)((<(()
{([<{<{([(<{[{{}[]}[(){}]]<{()}<{}()>>}[[[[]{}]{<>[]}}]>{[[[<>]<<>()>]{<()<>>{[]<>}}]})<<{[{<>()}<{}<>>]
{<<(<[<[[[[{{(()())([]<>)](<<>>({}()))}<[{<>()}[()<>]]>]({[[[]()]<()<>>]}[[<[]<>><()<>>]{<{}()>[
[<{(<<[<[(<[{(<>{})<{}()>}]<[[()<>]{<>()}]>>)]](({<{<[()()]{[]()}>((<>())(<>{}))}{[<{}()>]<(<>[
[<({({[[[<{<[[()<>]<<><>>]{([]<>)([][])}>[[(<>[]){(){}}]]}{{<{<>{}}<<>>>(([]{})[[]<>])}[<(()[]){{}{}}>]}>[{
{(<<{<[{[{({{[<><>]{{}[]}}}(([{}[]]<[]<>>)})[<(<[]{}><<>()>)[<{}<>>[<>[]]]>(<((){})[{}<>]>{(
[<(({<<([{[{{{<><>}([]<>)}}]}](<(<[([][])<{}[]>]{{{}{}}[{}{}]}>{(<[][]>{{}{}})})>)){[([{{<[][]><()>}
[({[[[(<<((<(<{}()>([]<>))(<()()}<{}[]>)>(([{}[]](<>{}))[{[]<>}(<>[])])))>>)][<{({<[[<{}{}>{[]()}]{(<>{}){
{(([((([<[{[(({}[]){()<>})[[{}[]]({}())]]{<[[][]](()<>)>{[{}[]]{[]()}}}}<{(<<><>><()<>>)<({}[])
{([{{[[{<({([[<><>]<{}<>>]<[()[]]<()[]>>)}[[{[{}{}]{{}{}}}]{[{[]{}}([]{})]{(()())[<>()]})])>}]<
([<[{{{([{{<[[{}{}]]{<()()>}>{{{()[]}([]())}}}<<{<[][]>{<>{}}}>{[[{}()]([]{})]{([]{})(()())}}>}])<<<((<<{}{}
[{{[<[[[<({[[<(){}>{{}[])]{{[]<>}([])}]}<({{<>()}[{}{}]}{[()()]{[]<>}})[{[()<>][()[]]}]>)>[<(<{{
(<{{({{{[({([({}[])<{}{}>](([]{})[{}{}]))})[(<<((){}){()<>}>[[[]<>][{}[]]]>{<([]){{}<>}>([[]{}])}){[(((
<[<{{(<(<<[{([(){}][()()])((<>())]}]>>)>)}[{(({({[[{(){}}]][{(()()){{}[]}}<(()())(<>())>]}{([{[]<>}<[]<>>]
{({<[[<<{<{(({<>{}}<<>{}>))[<<{}()><<>()>><<(){}>({}())>]}<(([{}[]][{}{}]){<{}>}){[<[][]>((
(<[{{[{([<<<(((){})([][]))>([[<>{}])[<{}()>{<>{}}])>>{{{{<[]{}>[()()]}[(<>{}){<>{}}]}{([[]{
{(<[{({<<(<<<(<>())[{}[]]>>{([()()]({}{})){<[]()>[[]<>]}}>[[<[{}{}]{{}<>}>{[<>()][<><>]}]{<[<>][[]<>]>((<>{
{[<<(<<({(<<[{<>[]}]{[{}{}]<[]()>}>(((())<<><>>)((<>{})[{}[]]))>[<({<><>}[[]{}])[<()[]>{()()}]>{{({}[])({}()
<<<(<((([<{[{{{}<>}{{}[]}}[(<>)<<>[]>]]<[([])]<{()()}{<>{}}>>}><{<[[[]<>]<{}<>>]>[(({}[])<[]<>
{<(([[{{[({(([[]{}]<{}()>)<([]())[[][]}>)<<<<>>{()[]}>[<<>()>]>})<<[({[]<>}[[]<>])<<{}()>({})>]{<<()[]>(()[
([<([{<[<{<([<()>({}[])](<<>{}>{{}{}}))<<({}{}){{}()}>[([]{})[[]()]]>>{{<[()<>]{()<>}>((<>())[{}<>])}<[(<
<([{({({<({[[(()[])[[][]]][(()){()[]}]](<{()<>}(()())><[[]()]([][])>)}{[{[<><>][{}{}]}<(<>[]){{}[]}>]
(({[<<[[{{<[{{[][]}(()[])}{<()<>>}]([<[]<>><{}<>>]{<{}()>[<><>]})><{{<<>{}>[[]{}]}{<{}<>>[[]{})}}<<<{}<>>
<{{<(({{(<[<<[[][]]{[]()}>><<{()[]}{<>)>(({}{})(()()))>]{(<({})({}{})>([()()]<{}<>>)){([{}[]]([]{}))[<[]
{({[<<[[<[<(<{<>{}}{{}()]>([{}[]][()[]])){{[()[]]{<><>}}({<>()}[<>()])}><<{[()<>]<[]>}<({}[]
<{{<<{<{<([(([<>()])<({}())<{}[]>>)[[(()())[()()]]{{()()}<{}()>}]])<[([<{}{}><[][]>])[[<[]<>>{[]<>}
<{<([[<{[{([[[[][]]<[]<>>][({}()){()()}]]<(([]())[<>[]]){[()<>]}>)[[<<{}<>>([]{})>[(()<>)[[]()]]]]}((((<<>>
[[{[<<([[({{<<{}<>>{<><>}>[<(){}>([]<>)]}<{<{}[]>{()[]}}((<>{})<()[]>}>}[<([[][]]([][]))({()()}<()
[{[[{(<({(<({({}<>){{}[]}}{<<>[]>{()[]}})<(({}())[[]{}])>><[<{{}[]}>{<[][]>[()]}]{((<>{})(<>
{{<{[[[(<({<(<[][]><{}<>>)[(<>{})<<><>>]>})>)]]]}{([[<<{[{<<()[]>({}{})>({{}()})}]<{[{()()}]<[[]]<()>>
[{{[<((<<(({{[[]()]([]())}{<[]{}>[{}{}]}}<({<>{}}{()[]})<{{}}{{}[]}>>)(<<<{}[])<[]()>>({[]
([[[<(<([{(({{{}[]}[{}]}[[()()][{}{}]]}({(<>{})({}())}({()()}([]<>)))){{({()<>}(<>[]))[(()())<[][]>
{([<<{<(<((({({}[])({}[])}([<><>]([]())))<<<[]{}><<><>>>({{}[]}{()[]})>}(<[({}[]){<>[]}](<[][]>{{
{{(<{<([[<[[(((){})<{}[]>)[[[]<>][<>()]]]{((<>[])(<>())){<<>>([]{})}}]<[([[][]][{}])]>><(({{<>()}}[<[][]>])
{[[{<<<{{{[[(<(){}>{[]{}})]]}({<[[{}()][{}{}]]{({}[])[{}<>]}>{{{[]<>}[<>[]]}<{[][]}(<>[])>}})}{[<{[([][]){<
<[<{<[{<({(<<([][])<()[]>><[<>()]{{}()}>)<([()<>]<<>{}>)(({}<>)[()<>])>)})>}][(<<<[[({{}()}{{}[
<{{(<<{[{<{{{{[]<>}{()()}}{(<>()){()[]}}}[{(<>[])}(({}[])[()[]])]}<<[{<>()}]<{<>()}<{}()>>>{((<
{[<[{{[[<[{<<[[][]]<{}[]>>><<<()[]>({}[])>>}([[[[][]]]((<>())<<>()>)](<[{}()]<[][]>>({<>[]}{[]()}))>]{{<[{{}
<([[{[{<<(<{<[{}[]]{(){}}>(<{}<>>{<>()})}{(<(){}>{[]))((()<>)[{}[]])}><(<<(){}><()>>){(<()<>>(()()))<({}())[
{<(<<{<[<<<[[<[]{}><[]()>]<{{}{}}{{}<>}>]>[[(<<><>>((){}))]({<()()><{}{}>}({<>()}))]>>]([(({<{()()}[
([{[([({[[<[{(<>[])<<>()>}[[{}[]]<[][]>]]><(<<()<>>({}<>)><(()[])(()())>)({[[]{}]{<>()}}{[[]
[(({([{[<<[{{((){})({}())}}]{{{<()<>>[[]()]}((<>[])(<>()))}[[[<><>]([]())]({()[]}{()[]})]}>>({[[<<
<{{(([[[<(<(([[]()]<[]{}>))[<[{}{}](()())>[[()<>](()())]]>{<{<()<>>}(<{}<>>[[]()])>})>[({<
[<{([{{<<{{(<([]{})[<>{}]>[<()<>><()[]>])({(()<>)<<>[]>)(([]{})([]<>)))}}>[{[({({}())[(){}]}<(
<([<<[<(<<<<({()[]}<{}<>>)[[()[]][[]()]]><({{}{}}){[[][]]}>>{[((()[])[[][]]>{{()()}{()<>}}]<{<
<((<{<{<{<<[[<<>()>{<>}]{({}[])<<><>>}]([{()<>}{[][]}]([[]<>](<>())))>[<<[[]<>]<()()>>[{()()}<(){
<<{[{[{[<{{<<[<>()]<[]<>>>[[()()][{}{}]]>([{{}[]}<()<>>])}[((([]{})[[]<>])<<{}{}>{<>[]}))]}><[{(
{{{{<<[{<{(({<{}()><[]<>>})[{<[]{}><()()>}{<<>[]>[[][]]}))<{<[<>[]][[]{}]>{[(){}][[]()]}}{{
<<{([({{[{{<[<[][]>{[]<>}][<[]()>]>{{[{}][()[]]}({{}[]}[()[]])}}{[[<<>{}>](<()()>)][<[[]{}]<{}{}>>
[{{<{([[<{(({<[]{}><[]()>}<<()<>><<>()>>)<{(<>()}[{}<>]}>){(<{<>{}}({}[])><{()<>}>)}}[({(<[]()>({}<>))<[[]
{{{({({<{<{[[{[]{}}{[]()}]<{{}()}<{}[]>>]({<[]<>>[[]()]}<[<>[]}<{}<>>>)}{<<(()[])<()[]>>[(<>[])<()[]>]>(<[[](
<{[(([[[([[<[[{}()]([]<>)][(()[])[<><>]]>(([<>{}]({}()))<{{}}[[][]]>)]({{<{}[]><[]()>}({[]{})[[
{(<({({(<(<(([<>()][{}<>])<{()<>}<{}()>>)[[[()[]]<[]{}>][[()<>]<[]{}>]]>{<<<[]><[]()>><(<><>)<[]{}>>>})(([
<{<(([(<<<<<{(()<>)}{<()()>(<>[])}>>>>>){{(<<[[{<>[]}(<><>)]<{[]{}}>]>>)[([{[[<><>]<()()>]{(()[])<<><>>}
({{[(<([({((([()[]]{{}{}})[(<>{})([][])])){{({<><>}[()()]){<{}[]>[<><>]}}}}{(<[<<>[]>]>><<[{()}<()()>]
([{[[([{<[({{({}[]><[][]>}}((<()()>[<>[]])<({}())({}())>))]<[[[(<>{}){[]}]{{[][]}{()[]}}]]<{<<{}<>><<
({{<[[({{((<[{()<>}[{}[]]]([[]()](()[]))>{[{()[]}{{}[]}][{{}{}}{[]{}}]})({{[{}](<><>)}[([]()
[<<{[{({{[[{{<[]{}>[<>[]]}<({}[])[()[]]>>{[[<>()]{{}[]}][{[]{}}{[]()}]}][<<([]()){[]<>}>((<>){{}()})>[{{{}(
(<{[{<{[[[<[<{{}<>}<()>>{[<><>][()()]}][<[<>()]{{}{}}>([[]())[[]<>])]>]{[(<[()()]{<><>}>{[{}[]]<
<{[[[{(({{<({(()[])(<>{})}(<[][]>[<>]))({([]<>)<<>[]>}<[<><>][()()]>)>[<[[<><>][()()]](<()>[()<>]
[<[([[<<[{((<[<>{}][{}[]]><(<>{}){[]<>}>))}][{{<<<[][]><{}<>>>><({()[]}<()[]>)>}<([<(){}>({}())]<[{}][()]>)[
[([({{[[{{[[{{{}{}}<[]<>>}]]<{{{{}{}}<<>()>}((()())({}[]))}[[<(){}>(<>{})][[<>{}]{{}<>}]]>
<<[{<<([[({([[[][]]{{}()}])[[{{}[]}<{}()>]{[(){}]{<>[]}}]}([{{[][]}>]<{{()[]}<()[]>}<(()<>)
[[[{(<[[{(({<({}())>{{<>{}}[{}{}]]}<{{()()}[{}<>]}[<{}<>>(<><>)]>))<<<{<<>[]>}{[{}()][{}{}]}>[<[(){}][{}{}
{<([{[[([{[{(<()()><<>[]>)(({}{})[{}<>])}[<<()[]>[()<>]>{({}<>){()()}}]]<<{(<>[]){()()}}<{{}[]}(<><>)>>((
(({{<(<({[[{({{}[]}([][]))[{[]<>}<<>[]>]}[<{[]{}}([])>]]{{([<>[]]({}()))(<()<>>{[]{}})}}][{<<{<>()
{{[<[<(([<{[([()()][[]<>])[<()<>>{()[]}]]}>[{({{()()}([][])}({()}(()<>)))[[({}())]{{<>()}[<>]}]}]]{<{({({
{{([([({[<((<{<><>}>{(<>[])})([({}{}){<>()}]))<[{<{}{}>{<>[]}}]<(<(){}>{()<>}){<<><>>}>>>[{[
[<{<[(<{{[((<[<><>]{(){}}>(([]<>)[()()]))(<{{}()}[{}[]]>{<<><>>{()<>}}))({[<()()>{<><>}]<{[]<
<((([(<[{<<[<<<>()>({})>][((()[]))<{{}()><<><>>>]>>({[[[<>{}][<><>]]({{}()}<{}{}>)]}((<<[]>
[[{({[({[[[[<[<>()]{<>{}}>]{([<>{}](()<>))[[{}<>]({}[])]}]{{{(<>{})({}[]]}}[{[()<>]{()()}}]}]]<<{[((<>())<()<
{<{{{([(<([<[{<>()}{<>{}}]<([]{})<[][]>>>([<(){}>[[][]]]{<()<>><<>[]>})]<<<[()()]>>[([()()]
[([[(({[[{{<{(<>{})<(){}>}[({}{})[<><>]]>({<<>{}>[<>{}]})}}[[<{<()><{}{}>}{{<><>}}>([[()()]{{
{{[({({([([<({()}([]()))>[[(<>[]){<><>}][{[]{}]<{}>]]]{{[({}{}){<><>}][[[]<>][<>[]]]}((([]<
{{<<[<<(({[[{{{}()}({}{})}<{()[]}{()()}>][{{<>{}}[()<>]}([{}[]]{{}[]})]]<[{{[]<>}{<>{}}}{[<>[]]<[][]>}]
[{<({({<{{({{{<>{}}<{}()>}{(<>())[<>{}]}}[(<<>{}>[{}])])((<<<><>><{}()>>(<<><>>([])))(<([]<>)>{{
{[<[((<{{[{{<({}{})>}<((<>)<[]<>>)[[<>()]{{}}]>}]}}>))]({[{{([[<<<{}[]>><<<>()><<>[]>>>[{{(){}}}<[[]{}]({}
<<<[<({[(<(<<(()<>)<{}{}>>{([]<>){<>{}}}>{{<{}<>>(<>{})}<[()<>]>})<{[({}())[<>[]]]({<>()}<<>{}>)><{
({<<[{<<[{{<([(){}]<<>()>)<<<>()>[[]()]>>(<{<>()}([]())>{[[]<>](<>{})})}}]]{<(<<[<<><>>((){})]{
<([{{[{<<[[{{[{}[]][()]}<[{}()][[][]]>}}[<{[<>[]]{{}()}}>{(<()()><[][]>)({()<>})}]]<[<[<{}<>>([]<>)
([<<[[([(<<[({()<>})<{[]()}{()}>]({{()<>}})>{[([<>()]([]()))[{[]{}}]]}>{{{(<[]()><[]>)<{{}{}}[{
([[{[[{<{[{<({()()}[<>{}])<<{}{}><<>()>>><[[<>{}](<>()]]<<[][]>{<>{}}>>}][<{(<<>()>[()[]])<{<>{}}
<{<<{<((([{[<(())<{}[]>>]<(<{}()><<>{}>)<<<>{}>>>}<{{<<>()>{{}()}}<<(){}>>}[[{[]()}({}())]((<>
([[([(<[<<{[<[()<>][[]()]>[[[]<>]<()()>]][[(<><>)]<<<>>(<>[])>]}><{([(<><>)]{[()<>}})}>><<[[(<
{{(<<({<([([{{[]()}}([<>{}]{{}()})])])[[[[[[<>{}>({}())]{{[]{}}({}())}]]([{{<>}(()<>)}[{<>()}<[][]>]])](<[[[
((({{<[<<{{{<<[]()>[<>[]]>[({}[])([]{})]}<<[[]{}]<()<>>><({}())(())>>}[<<[(){}]<[]()>>[{{}<>}
[<([<{[([[[(<[<>{}]({}{})>([()[]]({})))([{()()}{()[]}]<[<><>]{()()}>)]({({(){}}{<><>})<[<>()]{{}()
<(({(<[[{[{[((<>())[{}])[[<>]{<>()}]](<{[][]}{<>()}>([<>{}>{[]<>}))}[[({<>{}}{<>()})((()[])<<>
<{{{{<{[[<[({{<>[]}(()<>)})<(<<>{}>[(){}])[{<>{}}{<>{}}]>]({[{<>()}<()<>>]{<[]()><{}()>}}([
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import numpy as np
def load_input():
data = list()
with open('input') as fd:
for i, line in enumerate(fd):
data.append([int(i) for i in line.strip()])
data = np.asarray(data)
return data
def part2():
# Second part
data = load_input()
increases = np.ones((3, 3), np.int64)
count = 0
while True:
count += 1
total_flashes = 0
data = data + 1
ready_for_flash = np.full((data.shape), True, dtype=bool)
while True:
flashes = (data > 9) == ready_for_flash
number_flashes = flashes.sum()
total_flashes += number_flashes
if number_flashes == 0:
data[data>9] = 0
break
adjacents = np.zeros((data.shape[0] + 2, data.shape[1] + 2), np.int64)
it = np.nditer(flashes, flags=['multi_index'])
for x in it:
i, j = it.multi_index
if flashes[i,j]:
ready_for_flash[i,j] = False
adjacents[i:i+3,j:j+3] += increases
data += adjacents[1:-1,1:-1]
if total_flashes == data.size:
break
result = count
print("Part 2:", result)
return
def part1():
# First Part
data = load_input()
steps = 100
increases = np.ones((3, 3), np.int64)
total_flashes = 0
for step in range(steps):
data = data + 1
ready_for_flash = np.full((data.shape), True, dtype=bool)
while True:
flashes = (data > 9) == ready_for_flash
number_flashes = flashes.sum()
total_flashes += number_flashes
if number_flashes == 0:
data[data>9] = 0
break
adjacents = np.zeros((data.shape[0] + 2, data.shape[1] + 2), np.int64)
it = np.nditer(flashes, flags=['multi_index'])
for x in it:
i, j = it.multi_index
if flashes[i,j]:
ready_for_flash[i,j] = False
adjacents[i:i+3,j:j+3] += increases
data += adjacents[1:-1,1:-1]
result = total_flashes
print("Part 1:", result)
return
if __name__ == '__main__':
part1()
part2()
8448854321
4447645251
6542573645
4725275268
6442514153
4515734868
5513676158
3257376185
2172424467
6775163586
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
from networkx import Graph
import string
lower_letters = string.ascii_lowercase
upper_letters = string.ascii_uppercase
def load_input():
g = Graph()
with open('input') as fd:
for i, line in enumerate(fd):
a, b = line.strip().split('-')
g.add_edge(a, b)
return g
def find_paths2(g, path, visited_twice):
last = path[len(path)-1]
paths = list()
neighbors = g.neighbors(last)
for neighbor in neighbors:
found_paths = list()
if neighbor == 'start':
continue
if neighbor == 'end':
paths.append([*path, neighbor])
else:
if neighbor[0] in lower_letters and neighbor in path:
if visited_twice:
continue
else:
found_paths = find_paths2(g, [*path, neighbor], True)
else:
found_paths = find_paths2(g, [*path, neighbor], visited_twice)
if found_paths:
paths.extend(found_paths)
return paths
def find_paths(g, path):
last = path[len(path)-1]
paths = list()
neighbors = g.neighbors(last)
for neighbor in neighbors:
if neighbor[0] in lower_letters and neighbor in path:
continue
if neighbor == 'end':
paths.append([*path, neighbor])
else:
found_paths = find_paths(g, [*path, neighbor])
if found_paths:
paths.extend(found_paths)
return paths
def part1():
# First Part
g = load_input()
paths = list()
paths = find_paths(g, ['start'])
result = len(paths)
print("Part 1:", result)
return
def part2():
# Second part
g = load_input()
paths = list()
paths = find_paths2(g, ['start'], False)
result = len(paths)
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
QR-da
QR-end
QR-al
start-op
zh-iw
zh-start
da-PF
op-bj
iw-QR
end-HR
bj-PF
da-LY
op-PF
bj-iw
end-da
bj-zh
HR-iw
zh-op
zh-PF
HR-bj
start-PF
HR-da
QR-bj
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
pattern = re.compile("fold along ([xy])=(\d+)")
def load_input():
data = set()
folds = list()
with open('input') as fd:
first = True
for i, line in enumerate(fd):
line = line.strip()
if line and first:
x, y = line.split(',')
data.add((int(x), int(y)))
elif not line and first:
first = False
else:
match = pattern.search(line)
folds.append([0 if match.group(1) == 'x' else 1, int(match.group(2))])
return data, folds
def parts():
# First Part
data, folds = load_input()
count = 0
for fold in folds:
count += 1
next_data = set()
for coords in data:
if coords[fold[0]] > fold[1]:
value = 2*fold[1] - coords[fold[0]]
coords = (value, coords[1]) if fold[0] == 0 else (coords[0], value)
next_data.add(coords)
data = next_data
if count == 1:
result = len(data)
print("Part 1:", result)
# Second Part
x_values = [coords[0] for coords in data]
y_values = [coords[1] for coords in data]
print("Part 2:")
for y in range(max(y_values)+1):
line = ""
for x in range(max(x_values)+1):
if (x, y) in data:
line += '#'
else:
line += '.'
print(line)
return
if __name__ == '__main__':
parts()
899,112
477,249
462,60
49,299
1097,819
890,74
477,231
1242,464
57,641
833,471
1292,784
1232,717
898,227
442,749
893,116
395,423
1304,695
211,186
1097,243
1004,46
654,361
1044,784
745,284
376,637
634,737
509,369
242,395
199,442
397,170
634,94
954,15
1019,219
798,782
340,262
1299,598
1133,23
967,5
291,675
519,119
97,698
291,107
301,592
505,537
1280,780
340,632
919,588
733,884
166,577
530,840
1197,187
1004,605
244,668
38,368
1241,170
1161,199
597,701
594,140
1161,691
505,357
666,381
947,107
1268,179
984,585
418,775
805,471
1074,455
142,245
284,403
1064,557
207,766
485,759
236,775
38,309
329,59
1169,857
791,775
1310,809
530,715
571,401
525,673
1064,701
304,110
402,350
1237,172
646,287
959,156
62,320
674,364
959,738
723,535
177,423
798,85
497,859
825,99
473,593
575,45
505,215
764,133
109,684
884,457
356,879
920,238
310,233
79,266
177,663
691,868
1290,352
714,745
493,527
1173,65
1026,520
284,473
662,647
557,522
1190,667
181,180
1178,114
990,3
798,649
428,224
428,511
254,567
574,669
468,672
324,801
1290,542
120,702
271,312
145,817
1082,187
1014,493
691,420
718,544
412,560
420,368
428,432
326,585
686,108
1297,25
1290,782
689,893
1046,798
194,588
423,873
97,876
748,634
865,887
296,493
1046,350
488,311
1048,411
344,152
962,718
410,893
986,801
527,274
798,654
736,107
462,95
999,826
1119,595
604,652
261,124
20,352
581,50
417,778
820,260
310,651
95,21
20,21
629,32
1133,471
1082,885
82,450
1079,0
798,334
420,634
1243,87
290,262
477,295
226,511
915,670
364,632
248,625
1062,269
331,324
713,193
739,65
74,667
1248,574
903,490
65,868
1250,306
149,695
574,673
246,787
570,717
1225,105
214,36
904,336
991,726
1054,661
744,765
324,353
73,546
667,150
780,179
1136,381
920,14
57,253
825,404
638,427
170,297
231,465
792,140
979,773
669,8
1216,10
1020,262
758,158
879,516
621,893
1183,172
370,25
140,446
1034,820
301,289
325,835
167,794
1293,304
58,521
108,504
718,96
621,393
890,816
977,180
236,887
1277,309
197,53
999,397
1133,599
619,26
932,746
842,149
1236,765
16,651
1216,688
1149,367
743,819
706,674
1212,259
130,623
273,54
284,25
284,491
485,411
313,248
79,406
1046,96
13,663
35,710
306,166
560,206
1168,245
460,101
363,362
505,19
1248,47
264,432
1280,767
1031,100
1158,869
48,861
334,653
1135,822
1175,595
884,885
512,85
484,745
900,449
157,852
497,266
946,632
217,236
256,661
248,558
47,570
1103,766
1215,425
842,672
947,362
996,710
1033,75
552,812
62,798
862,702
756,803
3,466
934,677
1252,521
1220,103
570,499
997,438
1245,677
30,753
900,673
1119,593
716,754
264,350
420,484
1144,87
6,695
493,504
669,231
1051,695
97,522
97,565
954,463
674,595
63,292
961,409
348,848
166,359
686,767
192,575
848,319
925,477
735,182
326,107
470,117
1183,620
370,822
349,37
957,78
209,781
30,464
62,803
94,884
542,36
1307,793
398,681
604,450
376,329
175,520
495,820
764,504
768,858
241,341
502,869
1,726
252,675
157,490
672,427
1059,355
1151,820
319,168
1016,719
726,302
895,371
527,620
1151,436
805,647
540,705
1153,547
1304,199
817,367
88,126
1074,439
1289,140
1096,702
1243,359
739,401
448,702
858,85
810,291
1120,754
1190,702
239,523
805,215
920,350
1176,211
853,221
985,661
428,670
341,438
566,129
333,714
853,124
624,767
1240,368
641,250
1236,227
1218,484
1303,840
587,871
408,892
1004,838
109,210
716,140
1093,658
773,7
654,309
1049,677
674,530
318,831
1118,767
997,456
740,717
1238,791
848,127
541,259
830,8
363,219
584,526
672,651
353,816
457,322
112,529
1004,56
161,390
900,1
169,135
25,862
584,220
872,123
893,778
186,672
341,194
303,268
992,383
465,368
13,25
1168,240
311,516
713,701
646,607
1240,526
510,558
723,359
842,558
726,880
979,757
1202,257
495,773
70,686
753,522
94,688
753,428
273,532
197,501
485,722
840,848
420,816
186,149
698,403
363,676
1262,861
512,112
1201,658
129,98
1022,309
1263,324
569,660
74,675
80,409
177,232
455,4
818,527
480,397
186,222
1114,581
783,620
1201,236
197,893
1118,95
489,728
388,140
604,242
1216,240
797,754
756,539
797,37
1173,872
622,623
489,815
117,143
291,184
863,128
730,765
73,722
892,7
488,535
813,628
940,822
552,318
273,840
1086,289
1280,464
822,311
149,295
477,697
391,588
1237,348
262,483
6,199
584,592
485,539
390,126
490,738
1170,373
1140,297
934,637
396,436
1233,385
733,765
947,219
349,485
490,746
643,338
1084,511
979,122
408,555
820,290
669,25
1253,701
813,72
999,378
1176,855
1124,745
132,780
706,204
581,157
667,556
562,410
808,869
428,383
3,101
996,632
261,746
577,10
830,886
489,838
344,742
1136,845
398,661
398,238
1019,787
142,649
584,302
438,771
288,302
1161,295
92,634
606,145
970,632
1034,74
1079,894
142,240
1275,710
820,746
1173,22
74,577
855,890
689,501
497,347
358,688
636,364
567,819
1022,302
758,736
1253,253
428,501
821,815
887,21
1213,490
764,705
60,306
1153,255
1056,327
601,168
1099,634
880,718
1146,604
1213,18
1178,780
822,535
1161,471
952,127
1201,210
688,623
574,221
890,634
170,597
157,42
1084,393
310,661
666,8
375,548
597,193
390,544
65,677
263,180
621,449
1165,714
842,745
582,473
997,472
1145,815
25,32
820,156
612,520
957,302
770,705
113,187
1114,313
825,411
698,267
813,347
1236,667
723,807
169,815
805,194
1280,114
1223,815
820,820
790,659
850,101
1250,588
955,525
676,782
1113,221
224,289
1290,649
284,421
574,787
1020,632
1026,25
961,530
858,267
1237,157
1238,439
952,206
996,184
1292,364
969,707
546,133
619,555
575,182
584,880
979,137
30,268
477,214
797,857
1039,582
1144,359
211,17
790,235
1180,623
915,224
477,471
261,665
833,295
830,662
601,138
656,361
922,688
1262,145
1231,406
858,361
616,816
1290,270
764,189
320,689
18,530
813,266
363,107
577,436
609,439
560,464
229,490
480,886
281,333
202,267
1078,10
492,527
929,362
373,781
381,586
126,150
246,109
169,68
508,691
638,243
741,234
1081,404
1290,245
1034,298
621,841
821,728
23,44
1260,674
1044,140
217,628
750,688
1140,149
552,736
261,453
192,95
452,361
1140,597
726,368
798,688
519,147
1082,707
1294,19
70,357
840,693
691,362
1148,77
311,68
654,555
90,710
1049,770
1019,184
130,271
403,707
67,87
837,593
1213,404
1294,518
162,186
893,330
698,520
87,75
976,451
157,266
758,576
719,154
903,493
822,583
594,530
70,144
1153,628
463,327
1216,884
654,533
902,709
714,597
141,485
634,112
723,87
833,231
159,325
977,714
206,285
853,572
301,414
1004,400
750,884
358,127
1046,432
520,235
594,812
801,873
1169,37
986,353
1006,110
1099,260
915,695
1062,784
410,143
1300,8
1297,259
348,737
175,822
348,157
1037,54
1014,849
785,673
518,866
716,812
418,119
497,72
1093,236
1069,553
566,765
703,801
1230,409
1029,333
1190,227
94,206
641,886
1268,161
1181,221
417,116
47,324
1124,672
870,140
159,121
440,226
169,31
428,462
440,858
395,672
348,46
236,632
184,848
735,712
470,693
243,782
940,869
154,603
935,548
1039,841
490,143
149,471
920,880
243,112
706,652
817,504
465,884
581,844
914,884
711,536
90,343
952,530
1290,21
135,595
868,749
1238,473
898,667
174,397
1078,688
990,689
1272,368
438,123
400,262
102,812
1184,150
691,666
567,371
982,107
537,887
800,110
735,180
32,623
242,110
632,334
753,789
411,65
1290,737
313,438
900,751
333,180
426,457
261,677
440,140
714,297
527,172
729,546
673,142
457,501
1168,688
1124,149
664,383
848,799
480,381
159,436
867,821
213,243
378,148
947,676
72,473
1133,645
1150,653
653,840
912,233
769,259
1133,871
913,724
22,334
fold along x=655
fold along y=447
fold along x=327
fold along y=223
fold along x=163
fold along y=111
fold along x=81
fold along y=55
fold along x=40
fold along y=27
fold along y=13
fold along y=6
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
from collections import deque
pattern = re.compile("(\w\w) -> (\w)")
def load_input():
start = ""
rules = dict()
with open('input') as fd:
first = True
for i, line in enumerate(fd):
line = line.strip()
if line and first:
start = deque(line)
elif not line and first:
first = False
else:
match = pattern.search(line)
rules[match.group(1)] = match.group(2)
return start, rules
def part1():
# First Part
start, rules = load_input()
dq = start
chars = set(rules.values())
steps = 10
for _ in range(steps):
for _ in range(len(dq)-1):
key = start[0] + start[1]
value = rules[key]
dq.rotate(-1)
dq.append(value)
else:
dq.rotate(-1)
occurrences = [dq.count(char) for char in chars]
result = max(occurrences) - min(occurrences)
print("Part 1:", result)
return
def part2():
# Second part
start, rules = load_input()
chars = set(rules.values())
counts = {k:start.count(k) for k in chars}
pairs = {k:0 for k in rules.keys()}
for i in range(len(start)-1):
pair = start[i] + start[i+1]
pairs[pair] += 1
steps = 40
for _ in range(steps):
next_pairs = {k:0 for k in rules.keys()}
for pair in pairs.keys():
counts[rules[pair]] += pairs[pair]
new_pair0 = pair[0] + rules[pair]
new_pair1 = rules[pair] + pair[1]
next_pairs[new_pair0] += pairs[pair]
next_pairs[new_pair1] += pairs[pair]
pairs = next_pairs
result = max(counts.values()) - min(counts.values())
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
CBNBOKHVBONCPPBBCKVH
FK -> O
BK -> B
PB -> N
VS -> P
OF -> H
KP -> K
PS -> K
OV -> N
FO -> H
KN -> P
HF -> K
BV -> N
OO -> B
KC -> V
CK -> H
BC -> P
VV -> S
NS -> C
SF -> O
BN -> V
NH -> N
VP -> F
KH -> S
BO -> N
VN -> K
BB -> H
CH -> H
HP -> O
KK -> O
CB -> S
VC -> P
FH -> B
SP -> C
NF -> O
HN -> N
PO -> P
PP -> C
SO -> F
FB -> B
SB -> B
SC -> B
HK -> O
BF -> V
OB -> B
NC -> V
HC -> F
KO -> C
NV -> C
HB -> H
FP -> S
OS -> O
HH -> K
OK -> B
OH -> C
NP -> V
SN -> H
SK -> B
HV -> F
VF -> P
CP -> H
FN -> H
FV -> B
CN -> H
OC -> O
KV -> P
CF -> B
OP -> B
FC -> O
PC -> B
CV -> S
PV -> H
VK -> N
SS -> C
HO -> F
VH -> C
NB -> S
NN -> F
FF -> K
CC -> H
SV -> H
CO -> K
BP -> O
SH -> H
KS -> K
FS -> F
PF -> S
BS -> H
VO -> H
NK -> F
PK -> B
KB -> K
CS -> C
VB -> V
BH -> O
KF -> N
HS -> H
PH -> K
ON -> H
PN -> K
NO -> S
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import numpy as np
from networkx import DiGraph
from networkx import shortest_path
pattern = re.compile("(\w\w) -> (\w)")
def load_input():
data = list()
with open('input') as fd:
first = True
for i, line in enumerate(fd):
line = line.strip()
data.append(list(map(int, line)))
return data
def part1():
# First Part
data = load_input()
g = DiGraph()
neighbours = [(-1, 0), (0, -1), (1, 0), (0, 1)]
max_y_pos = len(data)-1
max_x_pos = len(data[0])-1
for j in range(max_y_pos+1):
for i in range(max_x_pos+1):
for neighbour in neighbours:
y_pos = j + neighbour[0]
x_pos = i + neighbour[1]
if x_pos >= 0 and y_pos >= 0 and x_pos <= max_x_pos and y_pos <= max_y_pos:
g.add_edge((j, i), (y_pos, x_pos), weight=data[y_pos][x_pos])
shortest = shortest_path(g, (0,0), (max_y_pos, max_x_pos), weight="weight")
result = 0
for i in range(len(shortest)-1):
result += g[shortest[i]][shortest[i+1]]["weight"]
print("Part 1:", result)
return
def part2():
# Second part
data = load_input()
g = DiGraph()
neighbours = [(-1, 0), (0, -1), (1, 0), (0, 1)]
y_size = len(data)
x_size = len(data[0])
max_y_pos = y_size*5-1
max_x_pos = x_size*5-1
risks = np.zeros((y_size*5, x_size*5))
field = np.asarray(data)
for j in range(5):
for i in range(5):
risks[j*y_size:(j+1)*y_size, i*x_size:(i+1)*x_size] = (field + i + j)
indices = np.where(risks>9)
risks[indices] = risks[indices] - 9
for j in range(risks.shape[0]):
for i in range(risks.shape[1]):
for neighbour in neighbours:
y_pos = j + neighbour[0]
x_pos = i + neighbour[1]
if x_pos >= 0 and y_pos >= 0 and x_pos <= max_x_pos and y_pos <= max_y_pos:
g.add_edge((j, i), (y_pos, x_pos), weight=risks[y_pos][x_pos])
shortest = shortest_path(g, (0,0), (max_y_pos, max_x_pos), weight="weight")
result = 0
for i in range(len(shortest)-1):
result += int(g[shortest[i]][shortest[i+1]]["weight"])
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
9197799967142949711924912559857266425989892895795349989935678852856491866597249883454355721838994689
9454699428952977916248797687374199797579937166959985575934687799286278395799834599823725191768264239
1476124567678962892998242114658368169969196949893799969968932492875835669928535888516585889557294857
5791918239996678837798182119995286749674958736799996579937942199999478117296491681956799173479469697
7169635399716469741872348399984999149999916841724586589959931149912818998567241788593818767699883858
2926741911914636315187918554497249439756557979631699768168949899866796175449994999986688215771687939
5589949979145888769995885998892975199254611397986145389381187633664799879995799643887357299151772988
8889465966717911191788336792214278123584765871499472917878297279329199386164989887784939824172612679
4449128566587999796639991816798948898951855942998816126957898821255977428897977658516999988855449929
3999895395663995233116579986688778269699389615982998939659193247918999668975597863299499276267179878
9989933899158995519999896763539929676935591584991626616943495964888658981438483529376937899999918183
4829998579654495951971971638691618176277519996856988429168266495831212992486396955413697829886599968
1853513748489779798696199795337967571689486839899518982881879699995999878971985995885285319954968987
3342299981292915486979299839195993258148889649679616595927478298168379999445161915519894982439638946
5741832898766672398489974989541186971799425919242686599739939448731546446299879192192895526548848951
3898679419518979696926476691872981828746218226918199699898828285487879261678997791767663979571336987
4545997398729587476481757668995896459799851954917678912468571968713532133518634849896488769111976969
7176919181998999666976198114775775798299797193972885999975499799991922929283534929891716288936629899
9795297985299599814789928888579191456982553599491674489819963299121598519964298979361694995981918669
5647159999798466469859785261859791688182892567989542289667144152647594189396864175439725912999894891
6854155179889746985993265989674997919485741213772961693991919182852979468522779889946746945979139453
6849999911316858193858699583834199555997997298798955876892868311369313778113995754199257992891592559
1988966163847446296579892411648896918797968187847519149178391233772828798998561969939976192876594877
7445186982744995399469915773579589785637114845746289739271566921956439346833864949599959561392652394
3457499487895199558673758745718298693289788928968598234991939776753988979879884594869769919728168682
6996592996822655364687387657828999681917991869422948671996356522399889425477419816794863249587691838
6963522693998786991158579735619989997779699892985724296997797588989857395266828998498892969725581196
9859966989665161194892178862589775985492499749698891478876986292862589878985699921967994865598972548
1951799998898999888869856412883984488695132895819836992634797721986196995697288654968728619832457546
7746279941985434489778669988695998998439885687679569278711958998865855737897118129117847196853321494
9957647198999793952568873984933619771962796482459488211592975286761921259894198995991177799599947499
5957899335983477859964986862162667699875586266873467199919735154293718617894984899199896937396169696
4896218869754451981289699181969462479929965399769819937374193998929686992335854771796763991919183598
7963369964836263326663688188689148549887888951793951217896899686213646979917379984981861249989999549
5651487588851599919775191184948759985836569954819197496898639599422949846969583849582827172889781259
9235786148996892968113972727222986857799699985848999699389987299798673597919859879142818978191972699
6268697925898964971528988971776886593959277157692478749421918568187987285285135794835198267899129444
9613855792729968968874877878798998856696549799999913939938579165969969665999919899989935397982894528
4997991949899429999159159577397714989959998878621218913971667491519691231899789262795929815768874159
9965848836163359381441957989236819923219977614754398952174759999868197879998492826999779999614619568
9916479998414596768939496337988287974996399692819868258768657938573834799119189969847332997799632969
5698447299748197429895187981999374113864719439577495356699467714279996684998225889418687785989668887
9688999296549647577489651538861651536198886343717392492893999157912496817872939573767915879229444698
7945998891978892984213828992819989424969949768551929992192128218217979514375299388969726393999499369
3584919181979999899979852691745679631417252595865981248933848728931198122729313884939499699196979282
8858721793437795394466977529919919969898771537432681496711998968886579589984829981259798525932187987
9588959797973868917749898922898847727866979662399888886799981719567732464855989797669812177692858535
7988797967989166987697149888751549873389785967924498738998179527778487979748999358518578993477944998
8392255427879688981984196873699686714549989266862782196183895285962499989186484692151849999723391279
8437165279966699964797868697998719161124994112294916994518516866198924776139989889587889979986973818
9999579881886267995145198999799886398912847997191746855988699599911799599898975959729735998989189975
8878929798597768927495551149914988384939936997932243691336699915979516239489822517874899851799315136
7999937717928948478557923788987292447971689615966385935897391982999178899753365199984698878762193326
8739178873349956119674999899899922517642862785199198189839768689799987895289957563983787873796927158
3817196699929999634811599428583198399931978688187175989163313588911897784917986562919151677117114699
5998827143845268748266989727984179597967556224858671494997248677843425189898194987624713779882979969
1291199757967569999681279489899999698569168979799631778127984994974999291683887763915481598891197984
6596739399885895975872877952961612873986668999381529399939575996779494715118543849969191539989723991
6488878279986978392869749226828917999488959898183448591336188881881342378769238973895889159556799994
7789977876961783236719451481787118498693824114361919936786189899181887229316982176859199279192424145
8187849893991985235499899257668519419992986629984899637874749832449368983739929946889995497697325581
1999982976844663788727661849815985519275791155239799816978282652839694868889597292189945989632996979
5996994949412446932824171982727298987629311193781981698399298991594594318144966895296816539941754949
4499757999646423149686819991849992649795216851367986996698575817689371687185996929563284536999154386
2781727997917211978984917918358938837999218781629649869594796149935179779682659626959939761694881741
9699391853588289298623919874976619984895139963999399988216318999974869174298698357691152898189998496
4692148898295579969948321265945989989678928997293841391798864427891761873993391876712881438989147999
9385356844999749799945931891327611796839596933696939993396192727919575919518191178749822279279367589
4178987198748999878181711949999695619267692321571299944319696913971989366952788997529689965967283949
9956943168197988495985856862549149864798959861938533689969366917899972839492619882179391815935536891
9994859897582628653476292984929998647975796929748931992994879889878464879929465595995992499919947572
6499868699811766722988787191388665966891869899747691981279799666949896666275972998579926239169811939
2572961395969294529184998258989427519999852294469971796436995767291982749996658711449539791567874971
9499369277479918778697894247918649998897952638574461819998871478917181981936547491991768414982337918
9139161883819343891979967499192937131885599318821172899173915229917976858689192989939199991289159588
4587788966993732467999991118887435975882488728997989199779497777813778259387411882768829389897869948
6997871988679928999697816865977788699836897997854449113119982463997827969671859996988242232984999889
7669989748189979988148659979989987372886949695793489235995874977587946688195985837946785781783754816
9949977989988894882969918629379321181514166935688979461975779949979998632331698911979279798659979815
5739999517928987777759268697378941991838969832887199538988396198131293696546792877869527666136992871
6911198997889976167798919887987969916181719673692949986396122688692969199128693334898362117657497517
9883388858893695671398924917987816149792972888297996689846999676959672799729896341199962982814179963
1987996499791423676141938518943291126997238886492375594975195733297999897928779997671984971349299794
9797999699795947998399566993717699681855989845386398419161478733246296117437796411784118959196917998
8918619981898886893637776664327129356976966478348969779281122928599816797994927899617318362459879958
9971138998498917194898897279183767784951818668325759559698816239496896576197991168919876998549693617
8864749334257944937895657676795539372789673639872688475887819638876957529359787979549486769488261586
5675561487189788698114476929665946299225219355166913169787589274369169599695999791361786439583994855
9999956599855466924168799196849941988317721987382287618899839584541991357959855181948139679757198596
9298494784765969999565792229687116986883978789756616279977893754489916919955299588991939854273184891
1996653993894556999967399479699996198846899917783471221742335181981132427871897521999889788298436396
9758778754778989199415992499539647886721912925345489999475288846844991977933449238525898929369479361
3799665999998683118595895926116918889199463219817924394877958956698592828621676399199495183592857893
5747926316986915679999389948959192389893246767655852888242899482429279815191681819582769989759282619
8557944289929978419989549449497998796197294159289979966862799744989186832759979889797777669569898889
8887698917197579219988794948269467999589319398686198699795225872219199592696935791919185797715588919
1498696799724916519515862974893197748928697249299992999324589578163647988841492955996651937876156824
8213962617983488919185253728699798941119614245999164229898897586922898965749999199113889146668885849
9547881767999183972817991938941799195699921244999582934834983168189915191587942659337539518189911869
9958877559791958745797981284916899539983986257869698291725831953753946984998659154999916977712958828
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
from collections import deque
import math as m
pattern = re.compile("(\w\w) -> (\w)")
def load_input():
data = ""
with open('input') as fd:
temp = fd.read().strip()
# to bin
for char in temp:
data += bin(int(char, 16))[2:].zfill(4)
return data
def parse_header(value):
version = int(value[0:3], 2)
type_id = int(value[3:6], 2)
return version, type_id, 6
def parse_literal(value):
count = 0
last = False
result = ""
while True:
if value[count] == '0':
last = True
result += value[count+1:count+5]
count += 5
if last:
break
return int(result, 2), count
def parse_operator(data):
count = 0
size = 0
length = None
number_subpackages = None
if data[0] == '0':
length = int(data[1:16], 2)
size = 16
elif data[0] == '1':
number_subpackages = int(data[1:12], 2)
size = 12
else:
raise RuntimeError("Invalid Bit")
return length, number_subpackages, size
def apply_operator(type_id, inputs):
if type_id == 0:
value = sum(inputs)
elif type_id == 1:
value = m.prod(inputs)
elif type_id == 2:
value = min(inputs)
elif type_id == 3:
value = max(inputs)
elif type_id == 5:
value = 1 if inputs[0] > inputs[1] else 0
elif type_id == 6:
value = 1 if inputs[0] < inputs[1] else 0
elif type_id == 7:
value = 1 if inputs[0] == inputs[1] else 0
else:
raise RuntimeError("No proper type")
return value
def process(data, number_packages=None):
version_sum = 0
count = 0
package_count = 0
values = list()
while True:
package_count += 1
version, type_id, size = parse_header(data[count:])
version_sum += version
count += size
if type_id == 4:
lit_val, size = parse_literal(data[count:])
values.append(lit_val)
else:
length, number_subpackages, size = parse_operator(data[count:])
count += size
inputs = list()
if length is not None:
size, v_sum, inputs = process(data[count:count+length])
elif number_subpackages is not None:
size, v_sum, inputs = process(data[count:], number_subpackages)
version_sum += v_sum
value = apply_operator(type_id, inputs)
values.append(value)
count += size
if len(data[count:]) < 10:
break
if number_packages is not None and package_count >= number_packages:
break
return count, version_sum, values
def part1():
# First Part
data = load_input()
count, version_sum, values = process(data)
result = version_sum
print("Part 1:", result)
print("Part 2", values[0])
return
if __name__ == '__main__':
part1()
# part2()
4054460802532B12FEE8B180213B19FA5AA77601C010E4EC2571A9EDFE356C7008E7B141898C1F4E50DA7438C011D005E4F6E727B738FC40180CB3ED802323A8C3FED8C4E8844297D88C578C26008E004373BCA6B1C1C99945423798025800D0CFF7DC199C9094E35980253FB50A00D4C401B87104A0C8002171CE31C41201062C01393AE2F5BCF7B6E969F3C553F2F0A10091F2D719C00CD0401A8FB1C6340803308A0947B30056803361006615C468E4200E47E8411D26697FC3F91740094E164DFA0453F46899015002A6E39F3B9802B800D04A24CC763EDBB4AFF923A96ED4BDC01F87329FA491E08180253A4DE0084C5B7F5B978CC410012F9CFA84C93900A5135BD739835F00540010F8BF1D22A0803706E0A47B3009A587E7D5E4D3A59B4C00E9567300AE791E0DCA3C4A32CDBDC4830056639D57C00D4C401C8791162380021108E26C6D991D10082549218CDC671479A97233D43993D70056663FAC630CB44D2E380592FB93C4F40CA7D1A60FE64348039CE0069E5F565697D59424B92AF246AC065DB01812805AD901552004FDB801E200738016403CC000DD2E0053801E600700091A801ED20065E60071801A800AEB00151316450014388010B86105E13980350423F447200436164688A4001E0488AC90FCDF31074929452E7612B151803A200EC398670E8401B82D04E31880390463446520040A44AA71C25653B6F2FE80124C9FF18EDFCA109275A140289CDF7B3AEEB0C954F4B5FC7CD2623E859726FB6E57DA499EA77B6B68E0401D996D9C4292A881803926FB26232A133598A118023400FA4ADADD5A97CEEC0D37696FC0E6009D002A937B459BDA3CC7FFD65200F2E531581AD80230326E11F52DFAEAAA11DCC01091D8BE0039B296AB9CE5B576130053001529BE38CDF1D22C100509298B9950020B309B3098C002F419100226DC
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import math as m
from collections import deque
pattern = re.compile("target area: x=(\d+)..(\d+), y=(-\d+)..(-\d+)")
def load_input():
with open('input') as fd:
match = pattern.search(fd.read())
x = (int(match.group(1)), int(match.group(2)))
y = (int(match.group(3)), int(match.group(4)))
return x, y
def part1():
# First Part
target_x, target_y = load_input()
v_ymax = abs(min(target_y)) - 1
n_ymax = v_ymax
y_max = v_ymax*(n_ymax + 1) - (n_ymax*(n_ymax +1)/2)
result = int(y_max)
print("Part 1:", result)
return
def part2():
# Second part
target_x, target_y = load_input()
v_xmax = max(target_x)
v_xmin = m.ceil(m.sqrt(min(target_x)*2 - 0.25) - 0.5)
v_ymax = abs(min(target_y)) - 1
v_ymin = min(target_y)
n_max = 2*v_ymax+2
target_x = [x for x in range(min(target_x), max(target_x)+1)]
target_y = [y for y in range(min(target_y), max(target_y)+1)]
velocities = set()
for n in range(1, n_max+1):
for v_x in range(v_xmin, v_xmax+1):
slow = n*(n-1)//2
if n > v_x:
x_pos = v_x*(v_x+1)//2
else:
x_pos = v_x*n - n*(n-1)//2
if x_pos in target_x:
for v_y in range(v_ymin, v_ymax+1):
y_pos = v_y*n - n*(n-1)//2
if y_pos in target_y:
velocities.add((v_x, v_y))
result = len(velocities)
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
target area: x=155..182, y=-117..-67
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import math as m
stop_value = False
# from binarytree import tree, Node
class Node(object):
def __init__(self):
self.left = None
self.right = None
self.parent = None
self.value = None
pattern = re.compile("target area: x=(\d+)..(\d+), y=(-\d+)..(-\d+)")
def load_input():
data = list()
with open('input') as fd:
for line in fd:
line = line.strip()
data.append(eval(line))
return data
def _build_tree(root, data):
root.right = Node()
root.left = Node()
root.left.parent = root
root.right.parent = root
if isinstance(data[0], int):
root.left.value = data[0]
else:
_build_tree(root.left, data[0])
if isinstance(data[1], int):
root.right.value = data[1]
else:
_build_tree(root.right, data[1])
def create_tree(data):
root = Node()
_build_tree(root, data)
return root
def get_tree_str(root):
ret_val = "["
if root.left.value is not None:
ret_val += str(root.left.value)
else:
ret_val += get_tree_str(root.left)
ret_val += ','
if root.right.value is not None:
ret_val += str(root.right.value)
else:
ret_val += get_tree_str(root.right)
ret_val += ']'
return ret_val
def find_right_leave(nd):
if nd.value is not None:
return nd
else:
return find_right_leave(nd.right)
def find_left_node(nd):
ret_val = None
if nd.parent is not None:
if nd.parent.left is nd:
ret_val = find_left_node(nd.parent)
else:
ret_val = find_right_leave(nd.parent.left)
return ret_val
def find_left_leave(nd):
if nd.value is not None:
return nd
else:
return find_left_leave(nd.left)
def find_right_node(nd):
ret_val = None
if nd.parent is not None:
if nd.parent.right is nd:
ret_val = find_right_node(nd.parent)
else:
ret_val = find_left_leave(nd.parent.right)
return ret_val
def explode(root, layer):
if root.left is not None and root.left.value is not None and root.right.value is not None and layer >= 4:
right_value = root.right.value
left_value = root.left.value
left_node = find_left_node(root)
if left_node is not None:
left_node.value += left_value
right_node = find_right_node(root)
if right_node is not None:
right_node.value += right_value
root.value = 0
root.left = None
root.right = None
return True
return False
def split(root, layer):
if root.value is not None and root.value > 9:
left_value = root.value//2
right_value = int(m.ceil(root.value/2))
left_node = Node()
left_node.value = left_value
left_node.parent = root
right_node = Node()
right_node.value = right_value
right_node.parent = root
root.left = left_node
root.right = right_node
root.value = None
return True
return False
def apply_action(root, layer, func):
global stop_value
if stop_value == True:
return
stop_value = func(root, layer)
if not stop_value:
if root.left is not None:
apply_action(root.left, layer+1, func)
if root.right is not None:
apply_action(root.right, layer+1, func)
return
def calc_magnitude(root):
result = 0
if root.left is not None and root.left.value is not None:
result += root.left.value*3
else:
result += 3*calc_magnitude(root.left)
if root.right is not None and root.right.value is not None:
result += 2*root.right.value
else:
result += 2*calc_magnitude(root.right)
return result
def add_list(left_node, right_node):
root = Node()
root.left = left_node
root.left.parent = root
root.right = right_node
root.right.parent = root
return root
def part1():
# First Part
global stop_value
data = load_input()
left_node = create_tree(data[0])
for i in range(1, len(data)):
right_node = create_tree(data[i])
root = add_list(left_node, right_node)
while True:
stop_value = False
apply_action(root, 0, explode)
if stop_value:
continue
apply_action(root, 0, split)
if not stop_value:
break
left_node = root
result = calc_magnitude(root)
print("Part 1:", result)
return
def part2():
# Second part
global stop_value
data = load_input()
results = list()
for i in range(0, len(data)):
for j in range(0, len(data)):
if i != j:
left_node = create_tree(data[i])
right_node = create_tree(data[j])
root = add_list(left_node, right_node)
while True:
stop_value = False
apply_action(root, 0, explode)
if stop_value:
continue
apply_action(root, 0, split)
if not stop_value:
break
results.append(calc_magnitude(root))
result = max(results)
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
[2,[0,[9,[5,9]]]]
[[2,[1,8]],3]
[[[[7,2],6],[[7,8],3]],[9,[[6,9],2]]]
[[[[7,2],[9,8]],7],[4,[[2,2],[5,0]]]]
[[8,[2,2]],[5,[9,[4,9]]]]
[[[[6,2],[4,8]],5],0]
[[3,[3,[6,6]]],[6,9]]
[[[9,5],[[8,2],[4,0]]],[[5,5],[[5,0],[1,9]]]]
[[[[7,4],[8,1]],[2,[7,1]]],2]
[[[[9,6],3],8],[[[9,8],7],[5,[0,8]]]]
[[[4,[4,0]],[[7,3],3]],[8,[3,[8,2]]]]
[[[[8,4],1],6],[[1,[8,7]],1]]
[[[8,2],[[1,4],3]],[[4,5],[[9,1],[7,2]]]]
[[[[5,0],[8,8]],[[4,2],4]],[2,[[4,3],[3,7]]]]
[[[8,7],[2,1]],[9,3]]
[[3,[7,4]],[0,3]]
[4,[[[5,0],[5,2]],3]]
[[[[0,1],0],8],[6,3]]
[[7,[[9,8],[2,7]]],[[[8,8],[9,4]],[[0,5],[4,1]]]]
[[[[3,7],[5,4]],[8,[1,8]]],[[1,8],[[6,9],9]]]
[[[[7,4],[7,7]],7],[1,[[8,2],[1,8]]]]
[[[[6,2],8],[[1,2],3]],[[[3,6],[4,9]],[[3,1],[9,8]]]]
[[[3,[1,1]],[[6,5],[2,2]]],9]
[[[[9,1],4],1],[[[1,3],3],[0,[1,4]]]]
[[[5,0],[4,[6,8]]],[[2,4],[[0,3],[2,6]]]]
[9,[[9,[1,5]],1]]
[[1,[[6,0],[9,2]]],[[[4,2],7],[[2,9],6]]]
[[[[8,2],8],9],[[[4,9],[3,8]],2]]
[[[9,1],[6,5]],[[[9,5],5],1]]
[[[[1,3],5],2],[1,1]]
[[[[0,0],[8,1]],8],8]
[[[[3,3],5],[[9,6],9]],[[3,[0,9]],7]]
[[[6,5],1],1]
[[[4,[1,3]],[[2,2],2]],[[8,0],[[8,1],[2,6]]]]
[9,[[4,6],2]]
[[[5,[8,8]],[[1,8],[4,9]]],[9,[3,6]]]
[[[[9,3],3],0],8]
[[[5,0],[[2,8],[1,1]]],[[[5,6],9],8]]
[[[[5,0],[5,2]],[[7,0],[9,8]]],[3,[[5,7],[5,9]]]]
[[3,[5,7]],1]
[[[[2,5],[0,7]],9],[[[3,2],1],[7,1]]]
[6,[7,[6,0]]]
[[[8,5],[[1,7],[7,6]]],[[1,3],[5,[1,9]]]]
[[[[9,4],[8,3]],1],[[1,6],[[2,5],1]]]
[[[[6,5],[6,6]],[5,5]],[1,8]]
[[[[7,7],[2,2]],3],[1,[[8,6],[5,1]]]]
[[6,[2,4]],[[8,8],[[3,5],6]]]
[[1,[[6,1],[9,3]]],[[2,0],5]]
[[[5,9],[6,[1,9]]],[3,[4,[7,7]]]]
[[[[3,6],[8,5]],[[9,4],[4,1]]],[3,3]]
[[[3,9],[1,6]],2]
[[[[0,9],7],6],[7,[9,[9,9]]]]
[[[5,[6,0]],[8,[7,5]]],[[[8,8],0],[8,1]]]
[[[[6,9],[9,0]],2],[[[0,3],[1,6]],[2,4]]]
[[[[8,2],[3,0]],[[3,8],8]],[6,[[9,3],4]]]
[[[6,6],2],[5,[1,4]]]
[[1,[1,4]],[[[4,3],0],1]]
[[[[9,9],3],0],[[[3,3],[2,8]],[1,0]]]
[[[[1,1],[3,5]],[9,7]],4]
[[[9,[3,6]],5],[[4,9],[9,3]]]
[[8,7],[5,[7,[7,7]]]]
[[[[0,5],[7,3]],[[8,6],8]],[[[4,4],[5,0]],[[2,2],2]]]
[[[5,0],[[1,9],[5,8]]],[[1,5],[[9,3],[0,7]]]]
[[[1,[1,5]],[8,[2,2]]],0]
[[[6,[7,8]],[[0,2],5]],[3,[5,[8,0]]]]
[[[[1,7],2],3],[[[8,7],[7,8]],[7,[5,5]]]]
[[1,[7,[3,3]]],[8,[9,[3,0]]]]
[[5,6],[[5,[2,8]],[[5,5],[8,8]]]]
[[8,[[7,7],[4,0]]],[[5,[0,4]],[6,[6,2]]]]
[[4,[[0,0],[0,1]]],[[3,1],[[6,7],4]]]
[[[[3,2],[4,2]],[[4,4],[6,3]]],[9,[0,[1,9]]]]
[[[[4,6],2],[[9,6],4]],[[9,[9,1]],[0,[1,8]]]]
[[[5,8],[[6,5],[0,4]]],[[0,[6,3]],[2,0]]]
[[6,8],[[5,5],[5,8]]]
[[[7,3],[8,[6,7]]],[[[1,5],2],7]]
[[6,[8,[8,9]]],[[[1,1],[3,0]],[[7,2],[3,7]]]]
[[[[8,1],6],[9,[5,1]]],[[[5,9],[1,9]],5]]
[[[[3,6],[5,7]],[[0,3],8]],[3,[[2,1],0]]]
[[7,[5,1]],[[[3,6],9],[[4,0],6]]]
[[[[3,8],8],0],[[1,[1,4]],[[4,5],[8,5]]]]
[[[8,[0,6]],[4,3]],[8,[[1,5],8]]]
[2,[[1,[9,7]],[[2,0],6]]]
[[[[7,4],4],[[4,9],3]],[[[6,5],[0,5]],[[9,8],[2,6]]]]
[[[3,[7,2]],[[7,7],4]],[[[3,4],[6,0]],[6,3]]]
[[[1,9],[[9,8],9]],5]
[[[4,2],2],[[[4,4],7],5]]
[[[9,1],[2,[1,5]]],[[4,3],[4,[9,5]]]]
[2,[[[8,4],1],[[2,4],2]]]
[[[0,6],5],[1,[[2,0],6]]]
[[[[2,4],[1,7]],[1,0]],[9,5]]
[[7,[3,[2,0]]],[[7,8],8]]
[[9,[1,0]],[[0,4],[[0,1],0]]]
[0,9]
[[[[2,9],[2,4]],[[5,6],8]],[[5,[1,4]],[3,[0,6]]]]
[[5,[[5,8],0]],[[[0,6],[4,5]],[[8,9],[8,3]]]]
[[[[5,2],[7,7]],[0,[4,1]]],[[8,7],[[5,3],7]]]
[[[5,3],5],[0,0]]
[3,5]
[[2,6],5]
[[5,[[6,0],3]],[[3,[8,7]],[2,0]]]
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import math as m
from collections import deque
pattern = re.compile("target area: x=(\d+)..(\d+), y=(-\d+)..(-\d+)")
def load_input():
data = list()
with open('input_test') as fd:
temp = list()
for line in fd:
line = line.strip()
if line:
if "scanner" not in line:
temp.append(tuple(map(int, line.split(','))))
else:
data.append(temp)
temp = list()
else:
data.append(temp)
return data
def get_orientations(data):
orientations = list()
orientations.append((data[0], data[1], data[2]))
orientations.append((data[1], -data[0], data[2]))
orientations.append((-data[0], -data[1], data[2]))
orientations.append((-data[1], data[0], data[2]))
orientations.append((-data[2], data[1], data[0]))
orientations.append((data[2], data[1], -data[0]))
all_orientations = list()
for orientation in orientations:
all_orientations.extend(get_ups(orientation))
return all_orientations
def get_ups(data):
orientations = list()
orientations.append((data[0], data[1], data[2]))
orientations.append((data[0], -data[2], data[1]))
orientations.append((data[0], -data[1], -data[2]))
orientations.append((data[0], data[2], -data[1]))
return orientations
def part1():
# First Part
data = load_input()
scans = list()
beacons = list()
for l in data:
scans.append(sorted(l, key=lambda x: x[0]))
beacons.append(scans[0])
scanners = [(0,0,0)]
print(beacons)
del scans[0]
number_beacons = 1
while True:
last_beacons = number_beacons
number_beacons = 0
print("length:", len(scans))
if not scans:
break
for l in range(len(beacons)-last_beacons, len(beacons)):
for i in range(len(beacons[l])):
remove = list()
ref_beacons = set([(beacon[0]-beacons[l][i][0], beacon[1]-beacons[l][i][1], beacon[2]-beacons[l][i][2]) for beacon in beacons[l]])
for idx, scan in enumerate(scans):
orientations = list()
for beacon in scan:
orientations.append(get_orientations(beacon))
for k in range(24):
orientation = [orientation[k] for orientation in orientations]
for j in range(len(scan)):
sbeacons = set([(beacon[0]-orientation[j][0], beacon[1]-orientation[j][1], beacon[2]-orientation[j][2]) for beacon in orientation])
intersects = ref_beacons.intersection(sbeacons)
if len(intersects) > 11:
sbeacons = [(position[0]+beacons[l][i][0], position[1]+beacons[l][i][1], position[2]+beacons[l][i][2]) for position in sbeacons]
beacons.append(sbeacons)
scanners.append((-orientation[j][0]+beacons[l][i][0], -orientation[j][1]+beacons[l][i][1], -orientation[j][2]+beacons[l][i][2]))
number_beacons += 1
del scans[idx]
last_beacons = number_beacons
print(scanners)
result = set()
for l in beacons:
result = result.union(l)
print("Part 1:", len(result))
result = list()
for i in range(len(scanners)-1):
for j in range(i+1, len(scanners)-1):
distance = 0
for k in range(3):
distance += abs(scanners[i][k] - scanners[j+1][k])
result.append(distance)
print("Part 2:", max(result))
return
def part2():
# Second part
target_x, target_y = load_input()
v_xmax = max(target_x)
v_xmin = m.ceil(m.sqrt(min(target_x)*2 - 0.25) - 0.5)
v_ymax = abs(min(target_y)) - 1
v_ymin = min(target_y)
n_max = 2*v_ymax+2
target_x = [x for x in range(min(target_x), max(target_x)+1)]
target_y = [y for y in range(min(target_y), max(target_y)+1)]
velocities = set()
for n in range(1, n_max+1):
for v_x in range(v_xmin, v_xmax+1):
slow = n*(n-1)//2
if n > v_x:
x_pos = v_x*(v_x+1)//2
else:
x_pos = v_x*n - n*(n-1)//2
if x_pos in target_x:
for v_y in range(v_ymin, v_ymax+1):
y_pos = v_y*n - n*(n-1)//2
if y_pos in target_y:
velocities.add((v_x, v_y))
result = len(velocities)
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
# part2()
--- scanner 0 ---
518,781,-434
587,-467,-517
-602,676,848
411,517,775
-6,117,112
521,910,-382
-579,596,796
-670,-552,413
329,507,669
-711,621,864
-757,-373,-766
463,-496,-653
-485,-567,434
333,-451,767
-688,-551,504
489,-466,723
638,-534,-698
-933,412,-628
619,877,-351
-129,21,-2
342,541,680
-957,462,-734
-924,543,-748
-959,-404,-724
-932,-350,-707
348,-491,716
--- scanner 1 ---
416,-472,809
-731,-669,-481
508,490,518
-86,89,144
501,551,488
557,-738,-447
444,724,-450
498,-583,871
605,-729,-624
-443,-654,634
-667,-743,-581
-343,475,-367
-595,979,559
-598,956,601
-403,-697,564
-404,-702,689
385,717,-310
94,175,27
567,555,384
-455,472,-446
-689,875,526
-383,458,-391
-673,-704,-577
445,630,-450
589,-455,881
626,-628,-514
--- scanner 2 ---
-666,-416,-935
-452,-753,396
-600,-412,-831
344,793,-685
-487,-758,447
-597,722,-448
601,495,259
305,841,-630
499,-817,-718
675,-415,676
-552,537,379
-607,-351,-801
-515,611,-510
304,836,-755
-504,482,315
590,-736,-793
-688,594,-438
640,-479,786
489,-422,708
-564,634,250
-461,-836,493
617,535,319
-150,11,8
-65,83,-161
496,-840,-760
739,545,232
--- scanner 3 ---
-300,354,-552
864,-675,-477
176,-8,-142
455,648,-617
-589,-630,-578
762,-614,424
-345,468,257
-643,-690,402
897,-656,-522
759,-701,376
676,758,287
-349,537,418
764,-474,394
-638,-844,370
-681,-786,561
743,717,433
790,-721,-442
-461,368,-428
723,739,373
511,641,-834
555,627,-697
-384,437,-508
-594,-416,-504
-328,551,413
-677,-565,-496
37,-11,29
--- scanner 4 ---
-463,497,873
-727,828,-603
-358,-623,-409
-677,852,-709
470,-637,736
-622,-516,800
-229,-626,-357
195,-29,49
789,817,-463
907,694,-426
842,744,-466
791,-795,-392
503,-681,584
736,333,929
-543,474,821
-632,-434,694
-596,819,-723
473,-533,593
770,-746,-524
-518,606,889
743,324,956
-598,-447,705
119,81,172
686,497,895
-262,-724,-326
712,-823,-439
--- scanner 5 ---
824,-682,628
726,-402,-319
837,485,848
436,977,-516
-622,-630,648
-486,670,-602
-452,675,-842
416,942,-403
589,976,-482
-488,548,483
-696,-352,-691
-447,688,-793
-474,-545,636
-588,-258,-784
641,-289,-320
879,-497,655
-46,38,-28
705,495,723
45,186,111
729,492,779
-496,-510,627
890,-604,524
-702,-340,-726
-455,530,452
560,-423,-263
-441,449,595
--- scanner 6 ---
-315,309,-414
439,-612,-437
-538,-660,630
829,555,783
-499,-635,616
55,46,-63
299,441,-807
873,-452,401
-623,-573,-845
-480,-681,752
-646,448,581
-797,447,531
860,-434,387
345,358,-846
506,-632,-490
-708,561,481
-506,-651,-875
-499,-451,-871
456,-672,-587
360,339,-854
-401,407,-429
-434,416,-379
695,-414,369
807,580,760
-93,-33,11
686,444,772
--- scanner 7 ---
347,355,826
742,-400,-856
-122,-84,-57
634,-749,447
659,723,-628
-705,-466,-772
-510,627,516
-465,589,691
834,-429,-868
-540,-497,739
-646,656,640
-456,773,-879
682,736,-614
-439,719,-906
296,408,674
-708,-409,-574
683,-647,381
-742,-505,-636
355,472,731
-397,750,-704
610,-598,339
18,28,34
674,742,-845
-634,-423,616
-625,-468,570
812,-405,-882
--- scanner 8 ---
606,-636,920
343,-356,-530
557,-603,786
667,542,625
646,-610,768
-579,-623,-790
-515,874,-784
682,590,688
405,-514,-535
396,-478,-607
-492,311,478
-83,-74,132
32,14,-5
-389,319,576
-701,-639,-754
451,523,-341
420,571,-292
-566,861,-808
-908,-471,778
-440,766,-739
428,740,-309
552,658,690
-637,-611,-745
-896,-347,751
-470,377,455
-891,-489,628
--- scanner 9 ---
686,-478,-712
-832,-720,-351
-684,511,488
631,391,752
588,681,-662
911,-874,524
-780,410,405
888,-786,433
593,566,707
-513,-716,558
774,-458,-617
548,696,-713
-836,-610,-356
-539,-943,552
-426,-842,624
816,-970,449
-29,-146,-102
-410,700,-615
-420,618,-721
141,-64,-47
771,-496,-798
-444,687,-626
-788,-535,-348
563,540,-669
-813,508,436
564,442,571
--- scanner 10 ---
718,-564,500
663,813,-420
-523,-541,309
541,738,414
-477,-521,503
-357,-705,-680
481,651,274
705,-297,-719
581,-271,-841
84,152,1
-593,493,-562
-247,893,331
588,-267,-641
597,817,-524
-359,896,410
540,644,414
614,-479,444
604,878,-554
39,33,-141
-582,-489,456
-499,389,-595
-502,412,-637
-287,910,355
-424,-652,-660
-374,-555,-620
731,-501,573
--- scanner 11 ---
897,-579,604
903,560,336
466,465,-620
790,-520,-775
821,-525,561
150,-94,2
-323,440,-709
510,561,-622
900,-617,478
887,-528,-807
-334,-617,-539
-570,523,294
-412,-655,-406
-645,458,361
838,612,489
-698,468,321
-381,346,-760
-469,-594,-571
-308,-475,425
-322,-636,481
576,408,-690
-366,-593,517
48,62,-135
905,-599,-719
852,625,444
-362,287,-685
--- scanner 12 ---
526,613,-486
754,893,779
707,546,-537
845,870,691
-533,-445,-768
-789,887,514
-547,-437,-830
-12,128,37
842,-831,-603
-586,-414,-880
-294,730,-446
-665,899,487
829,798,875
654,-444,747
873,-798,-505
-526,-655,497
571,575,-661
-286,847,-351
149,30,-42
-533,-566,479
790,-702,-606
-647,882,637
726,-557,848
-500,-615,345
720,-531,621
-235,794,-503
--- scanner 13 ---
691,-768,453
-484,762,339
496,346,561
574,316,444
595,604,-518
374,320,437
-816,-765,-822
555,701,-568
-926,-701,-787
-81,-17,44
661,-829,460
-587,-422,340
-493,812,372
-848,-758,-636
-633,-344,314
795,-764,519
-386,777,253
578,-363,-646
620,-340,-643
535,754,-501
-416,337,-422
-536,-427,305
-435,345,-407
-518,384,-361
3,-112,-115
653,-444,-737
--- scanner 14 ---
243,-555,655
750,450,795
10,-110,-8
347,-522,561
-764,607,-320
365,-751,-577
-687,349,631
-635,496,572
-798,-620,730
702,361,-285
764,395,867
-701,-580,780
752,467,-309
-540,-480,-681
-817,604,-393
453,-825,-645
-667,543,677
621,347,-318
266,-597,652
-556,-434,-601
-851,-640,797
-488,-456,-717
494,-664,-588
-882,644,-443
747,371,907
-90,-34,141
--- scanner 15 ---
50,-133,85
586,615,469
-447,-636,-526
-659,400,-586
-105,22,-10
-754,493,718
-666,541,-611
-685,440,628
595,569,514
-710,385,-626
512,-575,455
680,738,543
764,-880,-727
478,-637,551
-851,-705,747
-377,-433,-510
823,-705,-704
755,690,-543
515,-773,512
781,-907,-673
574,639,-610
-771,-696,679
710,515,-581
-356,-618,-525
-727,405,550
-834,-728,495
--- scanner 16 ---
407,710,-769
-50,-11,134
-702,-757,515
619,-668,667
461,-782,-781
753,-635,716
477,585,632
601,-661,756
-774,-793,506
584,-924,-786
-697,-915,453
250,591,658
-851,487,-431
-872,322,-397
-867,415,-582
611,-800,-798
-921,-632,-591
-189,-142,64
-912,-660,-527
319,619,-792
-957,-648,-469
-460,621,745
223,694,-697
-437,798,711
351,519,545
-439,841,786
--- scanner 17 ---
-534,753,-842
-960,-235,785
-525,-322,-659
-673,-346,-721
442,-608,-483
-122,78,-121
459,471,-673
-972,-404,793
767,580,773
8,-5,17
538,398,-734
-920,-347,784
-596,662,635
-456,617,-838
625,-456,498
-512,-272,-667
-623,591,619
431,-576,-444
637,534,817
651,-368,387
439,-521,-588
-607,436,644
696,556,718
532,460,-837
-500,756,-724
638,-345,550
--- scanner 18 ---
709,-483,-367
-680,-877,-594
748,-460,-317
784,-766,592
783,420,594
-355,383,859
697,-637,581
-314,-510,851
-711,-844,-692
695,-491,-429
760,433,608
-13,-42,-54
-338,437,886
-409,529,-536
-545,500,-660
-434,-379,860
-364,567,-711
775,414,825
-328,-429,884
858,-678,524
397,748,-694
-628,-748,-591
-296,406,684
106,95,64
456,684,-751
448,801,-846
--- scanner 19 ---
548,-925,-540
766,660,842
667,528,811
640,-824,-520
20,-99,4
-749,-854,-551
-137,2,-90
-871,242,377
526,535,-322
-922,394,430
-608,729,-576
-535,687,-625
298,-798,844
356,-919,763
-579,-856,-433
-492,-596,325
539,-791,-403
-368,-623,337
-584,621,-727
-598,-851,-651
803,521,779
510,564,-330
-510,-746,342
-863,337,494
308,536,-349
290,-896,741
--- scanner 20 ---
-443,-767,-548
-507,576,850
-568,497,777
-802,816,-814
616,839,712
-813,806,-716
435,444,-575
-517,-462,492
449,489,-588
-884,717,-845
-399,-496,495
832,-741,681
819,-784,526
-359,-702,-475
777,-622,-639
-403,-418,631
821,-620,-735
104,-111,10
-404,570,788
384,336,-640
713,710,724
711,-690,-792
-449,-793,-540
767,-712,541
768,774,772
-69,15,-48
--- scanner 21 ---
396,635,755
-441,773,-515
749,-637,420
17,53,-71
800,-357,-810
744,725,-372
-408,759,-434
454,539,790
729,-777,553
784,749,-389
-763,-823,-648
-786,-771,-568
-432,653,-384
-695,-388,580
-433,732,378
717,-414,-689
-677,-479,579
686,-447,-823
735,-702,373
-608,791,401
460,535,829
-654,-839,-593
-880,-409,595
-21,-116,33
-406,749,432
672,670,-386
--- scanner 22 ---
877,813,447
-554,665,637
863,758,519
-522,712,742
-581,-368,418
-512,724,-454
439,-269,391
-534,595,-571
125,6,154
860,837,407
611,754,-380
705,754,-381
560,-326,474
-19,147,77
-741,-333,495
-760,-510,-504
-676,-524,-619
464,-571,-382
-597,668,-558
-574,859,683
-572,-343,431
426,-359,505
618,894,-321
-651,-505,-369
482,-560,-523
460,-586,-326
--- scanner 23 ---
558,412,431
78,20,44
721,-315,-843
-766,-563,-610
526,614,-815
-315,-604,563
664,514,430
-383,-472,538
604,699,-904
-745,-378,-625
637,-437,406
706,511,382
-675,-581,-609
-404,518,459
-412,440,-509
613,591,-808
802,-376,-726
732,-415,-810
-456,596,-524
-499,449,483
-463,455,-549
595,-613,336
-510,436,449
646,-570,496
-331,-495,618
--- scanner 24 ---
458,-867,457
389,654,-484
751,748,679
746,-849,-605
-715,811,897
-644,-698,-562
523,-881,504
681,545,663
772,563,664
-700,-601,-533
-640,556,-442
-773,-622,-585
-37,25,-24
-923,-584,576
-869,-626,632
383,-861,637
-147,-104,168
803,-932,-726
321,522,-509
-726,711,864
-796,750,780
713,-818,-739
-631,689,-352
-955,-481,593
337,631,-564
-589,513,-282
--- scanner 25 ---
615,532,-575
-720,-384,-668
-379,769,527
416,905,494
890,-504,-433
-471,597,-761
506,804,397
373,-513,517
-493,-833,392
-554,-745,422
-422,-749,490
835,-480,-504
406,-515,531
504,444,-549
166,54,1
-253,681,548
448,867,298
-322,814,552
5,23,-117
-327,652,-769
515,-407,510
-556,-395,-741
667,421,-562
934,-458,-563
-617,-322,-662
-366,684,-758
--- scanner 26 ---
-658,498,-926
548,-363,-518
-466,-409,-409
-646,731,402
-374,-397,-438
-549,-637,714
-662,365,-857
739,-627,532
659,527,-852
-526,-651,727
-591,770,354
651,582,-708
358,458,660
271,336,650
-716,771,359
-534,-420,733
-396,-383,-414
603,-464,-556
766,-737,531
730,-729,671
-6,-26,-17
-637,410,-800
298,474,700
537,-537,-408
648,495,-813
--- scanner 27 ---
-370,576,594
756,-745,848
331,573,-440
521,-759,-580
-641,-479,794
362,-778,-592
581,508,540
-753,386,-329
327,512,-340
684,-758,727
-746,-438,720
-667,-795,-668
-778,415,-523
648,576,476
-867,-744,-678
317,523,-223
579,507,487
804,-753,814
-796,528,-357
-3,-47,5
-460,569,490
420,-652,-617
-501,529,542
-858,-508,754
-690,-695,-617
--- scanner 28 ---
545,732,409
848,671,-609
-531,473,545
-749,-478,-674
353,-601,-696
-444,466,568
477,-404,414
827,656,-424
-10,-37,2
494,772,394
-742,-463,-770
-554,-576,736
757,672,-627
450,-572,502
538,757,550
433,-533,-687
-639,438,-361
-650,471,-461
-522,377,653
370,-349,-719
-555,-446,635
-720,555,-422
-755,-558,-611
-516,-679,627
519,-482,449
--- scanner 29 ---
-306,737,554
668,707,-658
762,-561,-580
-275,836,686
-780,-298,-597
-338,873,547
822,576,779
722,-587,-428
798,639,-660
-687,-852,420
783,591,-723
-273,368,-772
552,-554,685
767,715,674
809,700,743
-354,426,-893
544,-540,747
-740,-801,268
-623,-793,363
673,-554,-562
-792,-422,-570
-376,360,-870
-775,-440,-720
102,21,-46
521,-501,797
--- scanner 30 ---
-695,269,-473
-165,-59,-27
700,-453,443
770,-458,417
-546,-455,-391
-750,-462,725
-784,-558,663
640,683,685
-498,720,420
508,-970,-464
450,315,-737
792,-482,431
520,358,-697
-747,-519,527
-523,-654,-343
575,310,-736
-41,-184,111
529,-844,-376
617,670,671
-439,697,595
504,-901,-331
-595,343,-409
-481,666,393
632,689,454
-639,-591,-391
-691,308,-467
--- scanner 31 ---
822,509,-602
-593,-792,788
-444,772,466
753,599,-549
778,-605,620
839,548,587
-527,713,-678
-687,-555,-826
829,-505,597
795,677,-514
-559,-862,676
-633,-821,571
-566,-542,-754
-447,715,664
778,-648,-490
919,480,596
741,-541,-591
53,-135,-49
-653,-547,-874
-612,684,-847
-410,676,528
839,-556,797
753,-522,-432
902,732,619
-518,758,-724
--- scanner 32 ---
-639,-722,-652
-332,635,547
620,-713,690
-835,-591,489
-513,-602,-673
-458,357,-705
820,393,-452
688,403,-577
-491,-637,-664
378,665,460
692,-749,699
-472,438,-848
355,842,494
357,885,419
-683,-617,449
-505,456,-817
-559,629,573
-433,563,660
-701,-624,538
807,-774,-672
873,-696,-776
92,44,-88
615,-871,752
712,400,-521
862,-589,-645
--- scanner 33 ---
807,-310,365
747,802,-660
-343,494,341
787,845,-590
459,817,455
523,891,555
592,-808,-627
-648,-580,-694
735,-324,420
-705,-621,-855
595,-831,-585
-621,490,-757
10,32,-45
786,850,-715
-345,-372,331
-637,-709,-781
847,-327,341
-404,471,-772
-369,-322,437
-545,463,299
-370,440,358
517,852,551
501,-727,-552
-635,477,-780
-378,-453,317
--- scanner 34 ---
462,-498,474
452,-352,604
486,551,654
398,-507,652
391,-452,-510
-361,-360,604
450,691,662
-753,-639,-758
918,522,-549
98,73,-86
-578,-304,611
469,-395,-661
858,562,-533
477,690,552
945,572,-411
-643,451,317
-498,-404,590
-46,163,-12
-691,745,-453
-767,612,331
-617,740,-667
-673,-746,-693
-718,-713,-712
-687,535,400
-699,828,-602
501,-388,-475
--- scanner 35 ---
542,322,-585
856,657,421
470,-631,749
478,-862,755
410,-873,-387
-592,516,-331
318,-885,-416
-869,530,770
-795,-655,554
797,714,485
-604,-919,-496
-786,-553,693
493,-645,736
518,430,-736
-733,523,802
-35,-86,69
-374,515,-358
-659,-818,-534
-832,391,833
-593,-745,-386
-822,-545,553
340,-899,-392
469,364,-634
-576,487,-339
-84,28,-109
805,809,368
--- scanner 36 ---
-558,471,-344
-709,594,415
723,-703,-309
-655,370,-254
707,-771,-457
414,743,-453
-459,408,-286
401,854,-505
-13,92,44
-730,-535,-625
552,-368,785
584,-748,-326
-838,-481,-656
597,591,528
-447,-287,927
-425,-301,903
388,831,-342
-713,461,484
608,623,489
486,-441,933
-818,-559,-655
-517,-313,932
600,678,633
-120,1,147
497,-267,823
-688,506,541
--- scanner 37 ---
768,-432,-774
-809,-717,-611
662,774,-471
-632,790,746
-492,782,710
65,151,15
454,-533,727
-513,-283,251
-503,-405,338
511,-382,805
-436,704,-546
-631,680,719
-804,-718,-736
447,-347,695
411,732,744
621,717,-632
-449,690,-569
-17,40,-126
849,-523,-699
-430,473,-554
-463,-421,278
557,602,734
566,780,798
872,-526,-741
750,706,-545
-761,-678,-666
--- scanner 38 ---
-662,-665,372
643,910,848
-575,-544,-461
-694,776,-406
-737,621,-419
341,-582,619
757,819,-525
536,-493,-789
368,-637,747
408,-647,694
689,884,770
740,919,765
-638,-818,411
-828,564,788
383,-545,-854
886,807,-622
-573,-640,-417
821,867,-470
-643,-697,-527
-838,618,553
491,-480,-803
-713,-759,430
-52,73,-21
-665,636,-471
-852,712,710
--- scanner 39 ---
-827,583,978
647,521,-591
-480,-628,-720
85,-6,165
364,-715,814
-785,756,-658
662,469,-663
-763,-377,534
-526,-702,-685
571,-660,-778
-577,-384,502
719,-738,-754
464,575,831
-705,573,891
373,-798,717
-689,533,951
-728,-441,424
-571,751,-584
665,-503,-764
476,672,960
-74,20,-10
507,456,-620
416,520,895
39,156,49
399,-720,763
-545,-735,-640
-636,839,-666
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import math as m
from collections import deque
pattern = re.compile("target area: x=(\d+)..(\d+), y=(-\d+)..(-\d+)")
def load_input():
rule = ""
data = set()
j = 0
first = True
with open('input') as fd:
for line in fd:
line = line.strip()
if line and first:
rule += line
elif not line:
first = False
# rule.replace('.', '0')
# rule.replace('#', '1')
else:
for i, ch in enumerate(line):
if ch == '#':
data.add((i, j))
j += 1
return data, rule
def print_data(data):
xs = [t[0] for t in data]
ys = [t[1] for t in data]
for i in range(min(ys)-2, max(ys)+3):
line = ""
for j in range(min(xs)-2, max(xs)+3):
if (j,i) in data:
line += '#'
else:
line += '.'
print(line)
def get_number(data, pos):
number = ""
for i in range(-1, 2):
for j in range(-1, 2):
t = (pos[0]+j, pos[1]+i)
if t in data:
number += '1'
else:
number += '0'
return int(number, 2)
def fill_border(step, y_min, y_max, x_min, x_max, data):
if step%2 != 0:
for i in range(y_min-2, y_max+3):
for j in range(x_min-2, x_max+3):
if i < y_min or i > y_max or j < x_min or j > x_max:
data.add((j,i))
return
def part1():
# First Part
data, rule = load_input()
steps = 50
for step in range(steps):
next_data = set()
xs = [t[0] for t in data]
x_min = min(xs)
x_max = max(xs)
ys = [t[1] for t in data]
y_min = min(ys)
y_max = max(ys)
fill_border(step, y_min, y_max, x_min, x_max, data)
for i in range(y_min-1, y_max+2):
for j in range(x_min-1, x_max+2):
number = get_number(data, (j, i))
if rule[number] == '#':
next_data.add((j,i))
data = next_data
if step == 1:
result = len(data)
print("Part 1:", result)
result = len(data)
print("Part 2:", result)
return
def part2():
# Second part
result = 0
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
# part2()
#.#....########.......##..##.#.#####...#..#..##.###.##.#..##.....#.#....#...####.#...#.##.#.#.#....###...#.##.#...#.#....#...#.#..#....###.##.....#.######.#.##.#..####..#...#.##.##...#....###..#.##..###..#..#.....#.###.##....##...#....###.#.......#.#####...#.##..###....##.#.##..##.######...##..##.#..###.###.....###...##.##.#..#...##..#.###..#..###..##...#...#.#..#..#..##....###...........###.#....#######...#####.#..##...#..#....##.##.#.###...####...#.#..#...#.##.#.#..#.###.#.#####.#.##.###.##..#..#...###.#.
.#.#.##.#######..#..#..#.#.#...###.###.##..##..##.###..#.#...##..##....##....#..####.#.###..#.#.#..#
#..###.##.........#..#.#...#......###..##.#.####....#..#..###.#.#######...###..#.#.##.#..##.#.#.....
.###..##.##..#.#.####.#.##..##.#.##.#..#####.#..#....#....#....#...#.##..###.#.####...##..##.##.#...
##....##....#.#.#...#..####..#..#.#.#.##.#.#.##..##.#..#...#..##...##...#.#.##.....##.####....#.....
#......#....#.###.##...#.#..#.#.#.##..###..##..###.##..##...####..#.#.#..##..#..#.#.#...###.......##
##.##...###.#.##..#######..#.###.###.##.....#.#...###..#####...#.###.#.#######.##....#.#.###..##..#.
..#.###....#.#.#..##..#.###.#.##.###.#..##.#...#...#......#####......###.##..#..##....#....#...#...#
#.##.##...#.#.#.#..##..#.#.##.#...#.###..#.####.##.#.#..#####...####..##..##..#.####.###..####.#..##
#####...#.####....##....##.........#.###.#...#..###.#........#.###.#...#.#.###########..#####..##...
..#.####..##.##.#..#.#####.##.#.#.#..######..####.#.#.#.##...#.#.#.#..##..###.###...#.....#.###...##
..#.....#.#.#..##..####.###.##.#.##.#.#...#.#####.#.#....##.#.#....##.#.##.#.##.##.#.#...#.....##.##
#..##....##...##...######.####.##....#..#.#.###.#.###..#.###......##.###....######.##.#...##...###..
##..#....###.##..#.#..########......##..#.#.##...#.##.#..#..#.##.###.#...#....#.##.#..#####.#..#.#.#
..#..#..######..#.##......#....#.#.#..#.##.##..##...#....###.##..#..###.##..##......##..#.#..###.##.
....#.####.##.#####.###.##..#.#####.###.....#.#..#########.##.##..###.##.#.#..#.....#####.###.#.#..#
...#..#.#.#.#.#.#######...#.#.####.##..##.....##..#####..#..#.##.#..##...#.##.##..#..........##.#.##
...#.###.##.####...##.###.#####.####.....##.#.##...#..#..###.###.#.........###.#####.....#.##..#.#..
.##.#.#.#.....#.#.##.#.#....#.###..####...#....##.#.#####.#...##...####..#...#######...####..#....##
##.#.###.#..###..###...####.#.###.####...#..#.##.......#...#.#........#..#..##.....#.##...###.#..#..
##.#.#..#........##..######.#######.######..##.#..##.#......#.###.#..#..##..###.........#.#######.#.
#.###.###...#.#.##.#########....#..#.#####.#.##.##..#..#.#.....##.#..###.#....###.###...#.#...##..#.
#.##.####..##....##...#.#...#.##.#..##.###..##..#####.#...#.#.......#..#.###....#..#..##.....#.###..
#.###.#.#.#...##..#.#.##...###..#.##........#.##.####.#..####.#.#.###.##....#.##.######.####.###....
.####...#..#..#.#..####..##..#.#.....##.#..##...#.#.#.#...##....#......##...#..#.###.#...##..#.####.
..####...#.#....###..#.#..#....##..#..#.#..####.#.##..##.###...##..#..#######.#.#######......####...
#.#..#..###.#.##.###..###.##.#.###.#####.#..#.#####.#.##.#..#.########..###..#...#.###..##..#.#..###
######...#....#....#......#......#.##.######...#.......#..#..##..#..##.#..#..####..##....##.##..#.#.
#....###.#.######.###..##.#..###..#..#..###.#.....#.#.##..###..#.#..##.###.#..#..#.#.#..##.##.#.####
#..#..#####.##...##.#..#######.#.#.#..###.#.##.###..#....####...####..##..##..#...#...#..#..#.#..#..
...#....##...####.#.##.#.#.#.......#..##....###.##..#...##...##.#.#.#.#.###..###..##..#.....##....##
#.#.#######..###...###.##.#..#..###.#####.###.#.#..##...#.##..####...##..#.##...#.##.#####.##.......
.#...#......##..#.#.##...###.##.#.##....####.##.#####.##.#..#.#..##....#.#.#..######....#.###.#####.
#..#.##..###..#.##.#....##..#.#..#..##..##...#...####..........#...#...###.#.#..#...#..###.##.#.##..
...#...#.#...#..#.#.###.#.#.#.#..##..##.#######...#.######....#.#.###.#.#.##.#.#.###.###.##.###..###
#.##....#.#.....#..###..#####.#..#..##.###....#.###....#.#####.###.#.######.....#..#.#..###..#.....#
....#..#..#.#.....#####.....###.....##.##.#..##....#...#...###...#..##..#..#####..##.#.#..#.#...####
#.#####...#.##..#..##..#.##.#..##........#...#....#.#....###.#.#...##.##.#####..###..##.#.#.#.#.####
#.###.####.#...#..##########..#.###..#.#.###...#.##..#####.###..#..###....##.##...#..###.##.#..#.##.
##.######.###.#...##..###.#.#.#.###.#.##....####..#.#.###.#...#..##.#####...##..###.#..##..####.....
#.#.....##...#.###.#.###.#.##.#.###....#.##.....##....####.####.##.#...#.....#..#####..#.#....###.##
###..##.#....####.#####.#.#..#..#....###.###.#..####.#.####..###.#.#...###.##........#.#####.#.##..#
##.#.###.###.......###.#.##.#..#.##.####.###....#..#.#.#...##....##..#....###.#####..###...##.#.##..
.#..###.#...#...#..#..##...##.#...#######...#..#.##..####..##...##.##.##.###.####...##.....#...#.###
#.##.........##..#..###..#....#.###..##..#.##.....##.###.....##..#.#.#######...#...#.....#..##..#..#
##..#.###.#...#.##...#.#..###.##...#...#####.####...###.#..##.##..#.##.#.#..#####.#...##..####...#..
..#.#.........#####.##..###.#.#.#..#.##...##.#..##.#..####.##.#.###.#.#.###.##...#.##....#.#######.#
###..#..#.#.#...#.###.#####.#.#.######.....##.#.##.#.#...#..#.#.##..###.#..###.####...##..####......
#..#..#.#....###.#.##..#.#.#.#.##..#..##.......#..#.#.......##...####.#.#..###...........#...#.#.#.#
#....##..##..#.##...###.#..#.#####.#.#.###.#.#..######.....#.#####....#.#..####..#.##.#####..#...#..
.##.###..##......###.....#.#.##...#..####.#..#...#..###.####.#..####.#...#.######.#.#..#####.....##.
#...###.###...##.#####..###.###.#####.###.#..###.#..#######..#..#####....#..##...######...##.#....##
###.#.#.#.#####..#####.#..##.#.###...####.#.#.#..#.#......#...#....#...#.#..#..#...#...##..#..##..##
.####....##..##.###..#.######...#.#..#.##..#..##.###.#.##.#...###.#.#.#....#.####.#.#....##.#####..#
##..##...###.#.#.#####..#.##..#####.####.##.#..#..####..#..##.##..###..###.....#.#.#.#####...#.###.#
###.####.##....#.##.#....#..###..##.##..#.....#.###....#.######...##.....#.##.##..###.####.#.###.#.#
#.#....#.#.#.#.#..##.##.##..##..##..####.#.#.#..##.#####..#####...#.#..##....#######.###..##..######
.#.....#.#..####.###..###...###.##....#.#.#.#..##.##...##..#.########..#.#...#..#.#..#.##.#.#.###.#.
#..#.####..####.##..##.##..#..##.####..#..##...#.##..#..#.###.#....#####..##.#######.#.###..#.#....#
.##.#....####....#.##.###..#..#..###.#.#.##.#..##.###....#######.####..#.########.#.....##.#...##..#
#.###..#.#.........#.#.#....########.####..###......##..#.##.#.#..######.#.###..#...####...##.##.#..
#.###.#..###...##.#......##..#..##.#..###..#.####...#.#..#...#.#####..##.###..##.##.#.#...#.#...#.##
##.###..#..#.#.##.##.##...###..#..#.#.#..#...###..#.#...#..#####.####...########.#...#.#.#.###.##...
.#####..#..#..####.#..#.....##.##....###...##.####.#.####.#..#####..#.#..#.##.###.#..##..###..#..#..
.#.#....#.####.#.###.#.###.####.#.##.#......##...#...#..###.###.#..##...#.#.#..##.##.#####.##.###..#
.##..###.##..#####.##.#....###...##....##..###.##.########.#.....#..##..#...#.#.#.###..#...#.#.#...#
#.####...####.###.#.#.###.###.#####.#...###.####..#..#..####.###..#.#..#.##.###..#.......#.#..##.#..
...#.###....#...###.#.###.#.#.#...#.##......#..###..###.#.#.#..###.##..#.#.#..#..##..#.#..###.##.#.#
#..#....#..####....####...#..######.#.#..##.#.##.###.#.#..##.#.....###..#....##......##.####..#.#..#
##..##......#..##..#..##.##.##..#..#.#...####.#.##...##.#.##.#..#...##..##.##..#..####..#..#..#..##.
#.####.#######.....##.#..##....#..#.#......###..##.##..##..#.#.#.#..##..#.#.....#......#.#.#.#....#.
....##.###...#...###..#..#.##...#.#.#.##...##....####..#..##..#.##.##...##..##....#...###.#.##....#.
..#..###.#.###.#.#.#...####...###.#..#.#.#...#.#.......##..#....##..#.##.##..##..#..####.#.#.......#
##.##.##.#....#.#..###.####..##..#..######..#.###.###.#####......#.#...#.#.....#####...#....#.###...
.#...##.##.#..#.##..###..#.######...#..#....#.#....#..###....#.#.#.##...#####.#..#...#..#..###......
.#......####....#.#...#.#.##.###.#..#..####.#...####..#####.##.#...#.#.#.##.##...#.#.#.##.#.##...###
..###..#####.#....##..#..#.###...#..##..##.#......#..####.#.###.#...#....###.#.##..####.#.####.###..
..##..#.#.#.#.##.####...#..#..#..#.##..#...##.#.##.#.###.###.#.#.##...#.#######.#.#.....####........
##.###.#.#.#..#..##..##.##.##.###...#...##..#.##.....#.#..#.##.#.#.###...##.####..##..##..#.#....#..
..#.##.#.##.###...###..#..#...##....#..#......####.##...#####...#...#.####.##.###.....#..#.#..##.##.
#..######.#.#..##...##.#.#..##...##.####.#######..#..#..###.##..#..#...#....#..#.##....###...#.#.##.
..#.#.#....####.#.#.........#..#.#..##..####...#.####...#..#.#...###.####..##......#..#...#.##.##.#.
.####.##..##.####..#.#.##..####.#.#......##.##...####.####.#..#...##.#..######.#.##.#.##.##.#.#.##.#
.#....##...#..###..#.#..#.##..#.####.#..###..##..#####..#..#.#.##..#.....#..###.....###.#.##.#.##.#.
...##...#...#..#..........#######......##.##.#.##.##.#..#.##.###.###..#..#....##..#.###.#..#...#####
.#####...#.##.....####.###.#.#..#....#...##..#....###.#.##.##########.#.#...#.####.......#..#...#.#.
.#....#.####.##.#.###..#.###.#....#.###..##...###...#.....###..####...#..##.#..##.#....###.#....#.#.
.##..###........#.#.##..##.##.##..#..####.#.#.##.##.#..#.#..#######.....######.#.#..#..###....#.##.#
..#.##..#...##.######..#..##.###...#.#.####..####..#.#...#.....##...##.#..##.#..#..#.###.##..#.#....
..#.###.###.#..#####....#...#..#...#..#.##..##..#.####..#..#.##.#.##..#######...##.#.#.#..#.##..###.
###.##..#..#...#####.#....#.#...#..###..##...##...#...#...#.###.#..#..#########..##.....#....#.#...#
#..##.#....#..####..###.#.#.#.##.###.#..#.###.##....##.#.#..#..#.#.#..###..##.#.#.#..#..#.#.###..###
#.#.#.###..#.#.#.....###.#.#....#.#####....##.###.##....#.......#..###.#.#..###..####.#.....####....
#####.####.#.#..#####.#.#....#....#......####.####.#.###.##..#...#.#..##.##.#########.###.#.#.#.#.##
.....#.##.##.#####...#.##...#...##########.###....##..####...#..####.##..###.#.#######.##...##.###..
#.#..##..#..##...........####.#....##.##.#..#.##..####.#..#.#..#...#...###.###.#...##.#.#.##.#..###.
.#####.#.#.#######.##..#..#..#..###.###.#..####..#.##....#.#..#.##.##.##.#########......####..#.##.#
.#....###..#.###.##.#...#.#...#...#.####...#.......#..###..####.####..#.####.##.#.##...###.###....#.
##......##.....#####.#.#.#......#.#.#.#.###.######.....#.##.#..#.#######.###.########..####..#.###.#
###.##....###..#.#####..#..####..#.......##.##.#.##.#.#.#.#..#......####..###..####.##.#.......#.#.#
#..###.###..#..##.#####.##.#....##.###.###....#######.#...#.#.#.#..#######...#.....#..##.####.###.##
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import math as m
from collections import defaultdict
pattern = re.compile("Player (\d) starting position: (\d+)")
def load_input():
data = list()
with open('input') as fd:
for i, line in enumerate(fd):
match = pattern.search(line)
data.append(int(match.group(2))-1)
return data
def part1():
# First Part
data = load_input()
positions = data
board = list(range(1, 11))
scores = [0, 0]
dice = 1
rolls = 0
values = 0
run = True
loser = None
while run:
for i in range(2):
values = 0
for j in range(3):
values += dice
rolls += 1
dice += 1
if dice > 100:
dice = 1
positions[i] = (positions[i] + values)%10
scores[i] += board[positions[i]]
if scores[i] >= 1000:
run = False
loser = 0 if i == 1 else 1
break
result = rolls*scores[loser]
print("Part 1:", result)
return
def part2():
# Second part
data = load_input()
start = data
board = list(range(1, 11))
a = defaultdict(lambda: 0)
for i in range(1,4):
for j in range(1,4):
for k in range(1,4):
a[i+j+k] += 1
positions = [[defaultdict(lambda: 0) for _ in range(10)], [defaultdict(lambda: 0) for _ in range(10)]]
positions[0][start[0]] = {0: 1}
positions[1][start[1]] = {0: 1}
finished = [defaultdict(lambda: 0), defaultdict(lambda: 0)]
round_variants = [defaultdict(lambda: 0), defaultdict(lambda: 0)]
for player in range(2):
rounds = 0
while True:
rounds += 1
stop = True
next_positions = [defaultdict(lambda: 0) for _ in range(10)]
for pos, scores in enumerate(positions[player]):
for score, number in scores.items():
for i in range(3, 10):
next_pos = (i + pos) % 10
next_score = score + board[next_pos]
next_number = number*a[i]
if next_score < 21:
next_positions[next_pos][next_score] += next_number
round_variants[player][rounds] += next_number
stop = False
else:
finished[player][rounds] += next_number
positions[player] = next_positions
if stop:
break
wins_p1 = 0
for round_p1, number_p1 in finished[0].items():
wins_p1 += number_p1*round_variants[1][round_p1-1]
wins_p2 = 0
for round_p2, number_p2 in finished[1].items():
wins_p2 += number_p2*round_variants[0][round_p2]
result = wins_p1 if wins_p1 > wins_p2 else wins_p2
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
Player 1 starting position: 4
Player 2 starting position: 9
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import math as m
from collections import defaultdict
pattern = re.compile("(\w+) x=([^\.]+)\.\.([^\.]+),y=([^\.]+)\.\.([^\.]+),z=([^\.]+)\.\.([^\.]+)")
def load_input():
data = list()
with open('input') as fd:
for line in fd:
line = line.strip()
match = pattern.search(line)
operator = match.group(1)
x_min = int(match.group(2))
x_max = int(match.group(3))+1
y_min = int(match.group(4))
y_max = int(match.group(5))+1
z_min = int(match.group(6))
z_max = int(match.group(7))+1
data.append((operator, x_min, x_max, y_min, y_max, z_min, z_max))
return data
def part1():
# First Part
data = load_input()
coords = set()
for operator, x_min, x_max, y_min, y_max, z_min, z_max in data:
xt_min = x_min if x_min>-50 else -50
xt_max = x_max if x_max<50 else 50
yt_min = y_min if y_min>-50 else -50
yt_max = y_max if y_max<50 else 50
zt_min = z_min if z_min>-50 else -50
zt_max = z_max if z_max<50 else 50
cube = [(x, y, z) for x in range(xt_min, xt_max) for y in range(yt_min, yt_max) for z in range(zt_min, zt_max)]
if operator == 'on':
coords.update(cube)
else:
coords.difference_update(cube)
result = len(coords)
print("Part 1:", result)
return
def calc_volume(data):
xs = set()
ys = set()
zs = set()
for operator, x_min, x_max, y_min, y_max, z_min, z_max in data:
xs.add(x_min)
xs.add(x_max)
ys.add(y_min)
ys.add(y_max)
zs.add(z_min)
zs.add(z_max)
xs = sorted(list(xs))
ys = sorted(list(ys))
zs = sorted(list(zs))
grid = dict()
for operator, x_min, x_max, y_min, y_max, z_min, z_max in data:
x_start = xs.index(x_min)
y_start = ys.index(y_min)
z_start = zs.index(z_min)
for i in range(x_start, len(xs)-1):
if xs[i] >= x_max:
break
for j in range(y_start, len(ys)-1):
if ys[j] >= y_max:
break
for k in range(z_start, len(zs)-1):
if zs[k] >= z_max:
break
if operator == "on":
grid[(xs[i], xs[i+1], ys[j], ys[j+1], zs[k], zs[k+1])] = True
else:
if (xs[i], xs[i+1], ys[j], ys[j+1], zs[k], zs[k+1]) in grid:
del grid[(xs[i], xs[i+1], ys[j], ys[j+1], zs[k], zs[k+1])]
volume = 0
for cube in grid:
volume += (cube[1]-cube[0])*(cube[3]-cube[2])*(cube[5]-cube[4])
return volume
def part2():
# Second part
data = load_input()
result = 0
volume = 0
for i in range(len(data)):
cubes = list()
operator, x_min, x_max, y_min, y_max, z_min, z_max = data[i]
if operator == 'on':
volume += (x_max-x_min)*(y_max-y_min)*(z_max-z_min)
for j in range(i):
operatorj, xj_min, xj_max, yj_min, yj_max, zj_min, zj_max = data[j]
xd_min = max(xj_min, x_min)
xd_max = min(xj_max, x_max)
yd_min = max(yj_min, y_min)
yd_max = min(yj_max, y_max)
zd_min = max(zj_min, z_min)
zd_max = min(zj_max, z_max)
if xd_min < xd_max and yd_min < yd_max and zd_min < zd_max:
cubes.append((operatorj, xd_min, xd_max, yd_min, yd_max, zd_min, zd_max))
volume -= calc_volume(cubes)
result = volume
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
on x=-24..26,y=-5..40,z=-7..41
on x=-45..2,y=-46..2,z=-20..29
on x=-8..39,y=-3..44,z=-25..29
on x=-22..30,y=-17..33,z=-39..8
on x=3..48,y=-43..11,z=-3..46
on x=-40..6,y=-11..34,z=-6..42
on x=-41..12,y=-23..31,z=-11..41
on x=-38..9,y=-47..-1,z=-11..33
on x=-36..9,y=-42..12,z=-18..32
on x=-9..38,y=-4..40,z=-25..24
off x=-19..-10,y=38..47,z=23..39
on x=-16..31,y=-7..38,z=-17..35
off x=29..44,y=-30..-12,z=-34..-25
on x=-37..17,y=-12..41,z=-36..15
off x=7..24,y=-15..-4,z=-7..10
on x=-8..40,y=-28..21,z=-43..8
off x=-11..-2,y=-37..-21,z=7..22
on x=-34..10,y=-28..21,z=-24..22
off x=2..16,y=-30..-18,z=36..49
on x=-35..16,y=-49..-3,z=-22..30
on x=5609..42139,y=50616..72254,z=41186..72055
on x=8139..25638,y=13750..35548,z=-79037..-70984
on x=51479..87500,y=24707..48115,z=-35295..-18227
on x=-73373..-55575,y=-50506..-23676,z=13875..21644
on x=-607..11075,y=32563..61072,z=-73961..-60677
on x=-54644..-32648,y=36095..52276,z=35524..44082
on x=3293..21195,y=23897..37964,z=64664..86731
on x=16277..34415,y=-51093..-44153,z=-65799..-46099
on x=57734..71356,y=9270..32187,z=-47281..-41642
on x=-17556..-2370,y=-65143..-40143,z=-65900..-42874
on x=27731..54850,y=-19951..-1638,z=64477..78243
on x=-46220..-25546,y=49098..67401,z=-24289..-8395
on x=-75694..-55646,y=8031..19015,z=-63498..-35375
on x=-82098..-64478,y=-7489..10895,z=-28050..-13416
on x=-17763..619,y=-38818..-18917,z=62021..80644
on x=-4036..21697,y=63232..90278,z=9932..21454
on x=-51009..-37805,y=-48120..-12965,z=-62976..-42322
on x=-10062..13435,y=-2713..27657,z=-95464..-67967
on x=53211..73081,y=-23539..-1570,z=30720..43005
on x=-87267..-52185,y=-25633..-10717,z=-57489..-22751
on x=-32246..-14833,y=40609..75319,z=47772..65055
on x=-28576..-9217,y=-65715..-35614,z=-66074..-35414
on x=-62100..-44706,y=-57479..-35266,z=25863..59774
on x=60075..84270,y=-39918..-27513,z=20052..37583
on x=-69755..-45869,y=-53994..-23866,z=25435..41774
on x=-81219..-56849,y=34988..67299,z=-36361..-6405
on x=-34896..-20511,y=-347..23007,z=65255..91319
on x=31628..57325,y=53947..76849,z=-39280..-15147
on x=2567..24296,y=-90225..-75834,z=-9435..-5411
on x=66209..79130,y=-1616..27541,z=-28640..1210
on x=-56973..-28039,y=9052..28251,z=-82655..-45613
on x=-21899..3543,y=23278..40219,z=56829..77737
on x=-37829..-22108,y=-63324..-34494,z=49476..61540
on x=27796..45837,y=-8932..13099,z=-69432..-64995
on x=-26462..1385,y=-80972..-64977,z=23581..52939
on x=18633..28209,y=-29248..-12757,z=62374..85976
on x=-63102..-52110,y=-69518..-44021,z=5993..16383
on x=-38388..-20775,y=-73119..-59089,z=-29565..-12624
on x=54496..71150,y=-2290..27080,z=-51819..-40956
on x=-62145..-38898,y=37344..47889,z=-46932..-22048
on x=-10609..-6237,y=-2296..11308,z=75214..88196
on x=43193..64498,y=44990..67787,z=3458..13502
on x=24383..31323,y=-63066..-46002,z=-57425..-46587
on x=31586..53656,y=43699..64126,z=-70386..-49751
on x=-6151..16087,y=24273..36658,z=67208..85968
on x=-28144..-8234,y=64628..78855,z=12447..35783
on x=-27791..-7570,y=7608..33671,z=56408..76897
on x=-71639..-37867,y=4786..41009,z=-65116..-49576
on x=29202..54934,y=42169..71478,z=12165..38477
on x=50789..86692,y=-27446..-11708,z=24940..46842
on x=68399..77340,y=-42140..-5435,z=23709..40953
on x=-50452..-17475,y=-55608..-32284,z=54133..62151
on x=-4270..17413,y=-91556..-67738,z=-44049..-21075
on x=43903..60390,y=-76164..-65052,z=-13211..19384
on x=21664..34686,y=57591..78789,z=-43915..-30761
on x=18428..25188,y=43685..82567,z=28711..62777
on x=4529..25520,y=-6802..9035,z=77117..85087
on x=-74034..-47153,y=-2394..12502,z=-76632..-45849
on x=-43913..-29276,y=-54624..-37109,z=30419..58292
on x=64879..76845,y=13634..34024,z=12635..43854
on x=6776..30399,y=78355..79046,z=-5764..4016
on x=-63878..-36489,y=-40818..-12939,z=39742..75011
on x=-36585..-8062,y=6370..26056,z=-96611..-70555
on x=37751..43126,y=61066..83536,z=-36569..-16414
on x=-48606..-38344,y=-48139..-39347,z=-65833..-47665
on x=31017..41410,y=-36971..-24044,z=-71220..-57847
on x=49779..79602,y=44542..67326,z=1267..19402
on x=-3734..20108,y=-94944..-68655,z=15541..22442
on x=-76300..-56024,y=41858..53403,z=11257..41111
on x=-71004..-31442,y=54465..65052,z=-2000..12106
on x=-72678..-54704,y=19816..43407,z=16364..42379
on x=51009..68895,y=48481..66552,z=27724..51296
on x=34066..51509,y=-42616..-30807,z=47689..76423
on x=-77470..-45422,y=26655..43016,z=-35815..-23824
on x=-24634..-7013,y=-30296..6379,z=77946..91093
on x=-56781..-41432,y=44942..63297,z=-47009..-17985
on x=-95213..-74134,y=3343..23741,z=4229..24279
on x=61302..81326,y=-25844..-8209,z=-32882..-14100
on x=-27390..-10821,y=-51218..-44783,z=50786..68594
on x=63238..81345,y=-39734..-17596,z=22551..50195
on x=-87553..-62611,y=-42771..-24651,z=-27754..-8749
on x=-60203..-24396,y=-74674..-43580,z=31078..36420
on x=-85144..-65273,y=-18554..-5394,z=-32092..-209
on x=32349..62192,y=-61244..-32184,z=-46708..-38457
on x=-72..22257,y=61503..84258,z=-3970..29653
on x=66230..84830,y=20332..41514,z=4985..16780
on x=-58039..-36988,y=-70196..-53336,z=10247..13477
on x=-24566..-8681,y=-94004..-69717,z=-12041..9481
on x=10334..48181,y=-2471..19711,z=56585..78548
on x=10784..32229,y=-93847..-55900,z=-9229..18824
on x=49587..59448,y=-59851..-45347,z=22113..43481
on x=-87533..-53634,y=20220..49745,z=-1116..16729
on x=-58815..-32234,y=54488..66930,z=5900..28577
on x=60038..81924,y=-8318..8718,z=10223..33033
on x=1923..18495,y=-3102..10532,z=-88329..-78503
on x=59672..77715,y=-40626..-35390,z=25608..48293
on x=36297..55036,y=42437..63782,z=42407..63524
on x=-23687..-10746,y=66374..84343,z=-19848..-18228
on x=18593..52199,y=59997..81390,z=8310..28040
on x=-43261..-30680,y=49936..71924,z=15139..27826
on x=35496..47786,y=-12482..5630,z=56734..85320
on x=-11550..4633,y=22405..47480,z=65911..80353
on x=22211..55607,y=67503..76616,z=-14547..15509
on x=31740..50903,y=20939..45236,z=56027..65915
on x=-59565..-47991,y=-35634..-8161,z=-61081..-44540
on x=-38974..-22039,y=-73909..-46420,z=-56927..-23880
on x=-74964..-52180,y=-31583..-19856,z=-41266..-30469
on x=47266..62217,y=28096..50912,z=15665..51527
on x=-63614..-50704,y=-60364..-49979,z=-43673..-19528
on x=15575..36146,y=-83099..-63073,z=-42166..-25456
on x=-79690..-65131,y=-24877..-1230,z=11120..41246
on x=-4523..17702,y=-78697..-60385,z=-29305..-4029
on x=17261..34049,y=29661..58479,z=-68165..-46907
on x=-12400..-1371,y=-71489..-47076,z=35766..62650
on x=-27789..7729,y=-68135..-58589,z=-47273..-39728
on x=68157..78687,y=-1072..34504,z=21557..38840
on x=26633..53469,y=63581..81530,z=-5982..18405
on x=-14883..15553,y=-12471..-980,z=-91754..-59136
on x=-23533..8244,y=-48008..-17971,z=67528..76082
on x=15266..44665,y=17502..45948,z=-80561..-52835
on x=-31325..4257,y=-50621..-29084,z=47197..74972
on x=23948..45584,y=-36756..-13871,z=68270..72042
on x=56171..85675,y=-25761..-21142,z=-24997..-18805
on x=6696..21116,y=-50725..-36582,z=-83039..-62967
on x=-49287..-12492,y=39255..73957,z=32589..60831
on x=18208..48850,y=-64186..-49655,z=24081..57383
on x=-21089..-7291,y=-86930..-59579,z=-21635..3264
on x=-1051..21830,y=-39146..-20118,z=72471..87333
on x=30008..54632,y=-26147..-14778,z=50822..75191
on x=11924..24704,y=-75577..-56492,z=592..31488
on x=-44629..-21430,y=45361..66637,z=-51786..-41834
on x=-64884..-41525,y=29231..44102,z=37768..57059
on x=31161..50459,y=31604..48054,z=34557..64400
on x=36738..55399,y=-74618..-44434,z=20578..43396
on x=31022..53044,y=44842..70018,z=-7706..11821
on x=63243..78624,y=-39042..-14303,z=-41860..-26158
on x=-42292..-22356,y=-55239..-29985,z=-57631..-36306
on x=11253..34902,y=66292..72870,z=13002..36097
on x=-35282..-27032,y=58835..76923,z=21050..43979
on x=-84223..-62785,y=23112..43514,z=-42672..-13754
on x=-3350..478,y=-25145..-18191,z=-96080..-76187
on x=20678..58328,y=-44508..-28464,z=-79988..-46699
on x=46735..65375,y=13436..31366,z=-61282..-39841
on x=-87711..-56748,y=-28789..-19538,z=14406..28075
on x=-16659..15248,y=75705..89199,z=-15472..-7958
on x=37345..74844,y=30092..51621,z=32635..44277
on x=-64462..-53285,y=-35306..-18899,z=30878..64940
on x=-26468..9099,y=42324..54559,z=45489..65368
on x=-19257..3337,y=-92931..-57803,z=22799..39671
on x=-3207..17264,y=-82989..-76889,z=-15319..15172
on x=-41286..-18429,y=-35843..-7024,z=-82527..-54781
on x=46286..82418,y=45348..57767,z=-3147..15690
on x=-68262..-58307,y=3806..24403,z=46854..63291
on x=-130..19564,y=3660..22398,z=-85573..-60617
on x=16126..21930,y=-73316..-53369,z=41777..72710
on x=24638..46417,y=59182..72626,z=-16321..-9098
on x=-17331..13083,y=39384..61561,z=43236..71832
on x=58036..79808,y=-5373..16227,z=25801..34299
on x=-40853..-22516,y=-17119..7328,z=-74970..-62490
on x=40030..60204,y=18303..47126,z=-59685..-48847
on x=-11309..4853,y=77452..85277,z=-14797..8309
on x=50697..76119,y=-37705..-21349,z=16877..35940
on x=-48798..-34053,y=65796..89714,z=-2575..1025
on x=-16559..3651,y=-33716..-11780,z=54873..82732
on x=-53556..-39892,y=-58433..-41327,z=-66705..-42978
on x=31485..53700,y=52203..63986,z=-52967..-38293
on x=4645..34468,y=47508..65982,z=-45654..-40573
on x=-87512..-61767,y=6790..22442,z=-23374..7647
on x=59975..70806,y=15542..39573,z=35499..45575
on x=-74085..-55250,y=-47922..-36188,z=13039..30061
on x=-42528..-20698,y=41530..55735,z=48991..67104
on x=-87979..-66482,y=440..13808,z=-32465..-23642
on x=-14076..-4393,y=37994..62252,z=39287..71929
on x=-25886..-4644,y=45326..48886,z=-77379..-51968
on x=-47147..-36465,y=-74452..-48425,z=10318..29932
on x=-31507..-1301,y=-30373..-421,z=-93597..-67747
on x=-45910..-19800,y=54517..62836,z=-56562..-33021
on x=104..20657,y=17332..24054,z=76824..96308
on x=26139..40030,y=-72609..-36391,z=37678..59023
on x=46..22292,y=-824..12892,z=76343..80061
on x=-2288..34312,y=-73030..-53123,z=-38055..-18627
on x=-38406..-17990,y=-70593..-48253,z=11172..41994
on x=53817..72838,y=30506..38661,z=20182..34018
on x=23826..59739,y=27582..45188,z=-73343..-54685
on x=69351..80614,y=21219..41796,z=-12098..8356
on x=-59032..-52617,y=38452..61481,z=-36164..-11453
on x=-78661..-66064,y=-32492..-17544,z=-26945..6954
on x=10567..41318,y=-6570..16020,z=-83637..-62446
on x=9860..43000,y=59037..77653,z=28387..50945
on x=16721..53302,y=-46639..-23839,z=44059..73945
on x=-70827..-45187,y=38190..43530,z=-61084..-23749
on x=-48399..-37142,y=12255..42441,z=52908..85567
on x=53405..79594,y=-23626..611,z=40605..64733
on x=-10784..24303,y=-1626..26389,z=-92863..-74120
on x=-30008..-13275,y=17141..39972,z=-74455..-59803
on x=-6202..16746,y=-83782..-57692,z=32739..55293
on x=-45054..-17786,y=-55632..-25509,z=58440..65430
on x=49496..74995,y=-64557..-35933,z=8931..24566
on x=-13760..16677,y=41402..63662,z=-70515..-59036
on x=38379..59137,y=30491..44422,z=56353..60342
off x=-24742..2249,y=-40926..-3720,z=-79933..-68774
on x=-47325..-25534,y=-58380..-34831,z=-50258..-33652
off x=-47733..-27521,y=-27721..-13863,z=-73170..-62200
off x=-83945..-60815,y=9850..27838,z=950..11237
on x=-530..24203,y=-95800..-73924,z=5070..19491
off x=-36864..-20946,y=-81347..-61739,z=32668..38474
off x=-36656..-6098,y=72706..79591,z=-11424..15174
on x=6555..20362,y=42918..57995,z=52048..63685
on x=18067..31412,y=-58953..-36726,z=44579..70711
on x=53722..85902,y=30739..38467,z=-32023..-11344
off x=-81371..-60561,y=-65573..-46474,z=-9980..13573
off x=51596..60885,y=51447..61598,z=14876..25419
on x=9488..19184,y=-74843..-47054,z=30892..43361
off x=-61912..-42820,y=36018..62340,z=-32665..-9794
off x=-37542..-14885,y=15720..20744,z=-76697..-59487
on x=63813..83567,y=-3073..13000,z=14110..37120
off x=-49487..-22977,y=-4273..21397,z=57477..79719
off x=10818..44502,y=58900..92027,z=-39589..-17569
on x=-81807..-64293,y=-45192..-19647,z=-5341..-2784
off x=-55478..-23678,y=63712..66028,z=3567..32586
on x=-20385..-11203,y=5509..29180,z=59392..77809
on x=57144..88328,y=1538..22221,z=-4725..18757
on x=-33107..-27506,y=-78667..-64060,z=6017..36762
off x=-6314..978,y=-10623..-1488,z=60312..81937
on x=-10391..17165,y=-81923..-65966,z=12889..23243
on x=41093..62251,y=31584..32807,z=43154..52764
on x=77653..90977,y=-10639..11259,z=2453..9348
on x=7494..26381,y=69669..84849,z=32979..48213
off x=-8343..11654,y=58528..85182,z=653..27032
on x=-735..5301,y=-87893..-68784,z=24849..45135
on x=1953..3062,y=-94925..-77283,z=-22865..-4449
off x=-45826..-27171,y=-69071..-52430,z=38802..68061
on x=21665..40847,y=-54263..-28366,z=61334..76237
on x=-32924..-20574,y=47633..79790,z=-50136..-39232
on x=54685..71349,y=-62557..-33089,z=27476..42665
off x=59754..78538,y=-35932..-20483,z=-32172..-19830
off x=37861..65730,y=39985..61002,z=23504..41344
on x=-74741..-47204,y=-59872..-49002,z=-28833..-781
off x=3476..17668,y=68198..75910,z=-27254..-7235
on x=66069..82770,y=24216..49941,z=-36134..-4273
on x=48702..64171,y=-77237..-41211,z=-34982..-1805
on x=13809..37676,y=37331..63848,z=-67520..-47332
off x=-18241..-16031,y=52017..61954,z=-63105..-46761
on x=14524..47366,y=-57403..-30601,z=-75860..-50889
on x=-7270..10637,y=43987..70276,z=-66420..-39961
on x=4353..21415,y=52505..69508,z=-41724..-39623
off x=15496..27979,y=-74457..-55950,z=-40425..-18614
off x=-61972..-46394,y=-68745..-45678,z=4749..26885
on x=26688..43626,y=-60783..-36136,z=44084..65094
on x=-32202..2413,y=-80250..-61117,z=-42809..-30759
on x=-50400..-36122,y=59938..78775,z=8249..14010
off x=-11808..24477,y=51651..57523,z=-69325..-46448
on x=-72349..-50943,y=24709..44458,z=39052..45249
on x=63477..83481,y=20482..35519,z=26467..33943
on x=-53722..-28581,y=48617..72280,z=16735..47820
on x=49779..69562,y=-25355..-12335,z=50965..65593
off x=-48670..-27527,y=51878..76129,z=11927..34996
off x=-30203..-9313,y=3312..31262,z=52940..90888
off x=1812..13806,y=-17395..-3209,z=64631..87790
on x=9684..32379,y=-81732..-62642,z=-24074..-10379
off x=-75011..-65777,y=24070..39654,z=17202..40909
on x=-87679..-76918,y=-4558..8948,z=-6232..20254
off x=-55563..-46662,y=-6715..4715,z=44509..62432
off x=42661..65781,y=9857..32909,z=54272..62826
off x=71075..81678,y=-6479..-1703,z=-44516..-18005
on x=4952..26523,y=59673..90782,z=6095..15047
off x=-42384..-23511,y=-73105..-64330,z=-16602..3227
off x=-18148..-13132,y=22123..45117,z=-68689..-48648
on x=4167..36103,y=-81411..-57974,z=-16361..-4273
off x=-51893..-27570,y=8739..30622,z=-78519..-54862
on x=-40940..-11382,y=-35819..-18301,z=-79311..-70893
on x=-52365..-35244,y=-67742..-51897,z=-49275..-25507
on x=37183..41081,y=-76942..-51334,z=-39459..-15473
on x=-47076..-21857,y=43859..61060,z=-46364..-23097
off x=50139..67202,y=11617..31573,z=-55825..-42177
on x=-69608..-58351,y=36696..39390,z=28928..54334
off x=17230..35559,y=-73061..-64573,z=-27327..-9096
off x=-32668..-6290,y=-81343..-53810,z=39217..47010
off x=-6941..15440,y=64673..94579,z=-5171..12236
off x=4489..8029,y=38739..57877,z=54997..71455
off x=-42969..-27400,y=53522..85284,z=14237..35322
on x=-81995..-62662,y=-60753..-29868,z=-23137..4932
off x=-18900..18279,y=59306..79233,z=39188..71799
off x=34064..42255,y=-4729..2608,z=53674..85548
off x=-30227..-12262,y=58379..78470,z=-2724..-105
on x=-11439..12606,y=-54284..-46038,z=-76593..-51849
on x=26252..65651,y=22769..45282,z=37142..67767
off x=54913..74386,y=-18197..2522,z=28541..55427
on x=-43171..-21729,y=29666..44627,z=52869..73931
on x=-40605..-26003,y=-25028..-2467,z=-82282..-49850
on x=-52773..-34236,y=-2753..13844,z=61651..87231
off x=-93799..-65698,y=-40603..-4419,z=5278..27507
on x=-28724..-13489,y=-22427..-14352,z=57929..90549
on x=18655..36786,y=62146..76247,z=-31256..-22934
off x=-42346..-5229,y=17564..32492,z=69392..84966
on x=-24455..-17132,y=74434..77431,z=-21501..-8410
off x=25211..57315,y=13740..36003,z=-68801..-56185
off x=27..24904,y=75904..97782,z=-10719..5799
on x=-49260..-36416,y=-2846..34476,z=52796..76381
on x=53581..83019,y=-4353..18661,z=37179..50767
on x=-64156..-41167,y=51996..64637,z=24073..47589
off x=5644..33414,y=2470..30586,z=-90196..-64061
off x=54810..84305,y=-57338..-29450,z=-2234..9839
on x=-85272..-75168,y=-22177..1744,z=-31707..-7326
off x=32863..51637,y=-31704..-19915,z=56733..69791
on x=-66125..-35317,y=6125..30008,z=47036..79335
on x=55590..73405,y=-13895..6890,z=40189..68070
on x=6079..24303,y=-86736..-65081,z=-17630..19062
on x=37640..48571,y=-68891..-51790,z=-33967..-3104
off x=8625..20808,y=61479..75865,z=-47719..-32119
on x=-28358..-26349,y=25083..34274,z=58867..69718
off x=-31999..-13374,y=-62161..-41315,z=-60908..-31114
on x=-77428..-70852,y=-4432..11626,z=-43163..-22549
off x=-12405..8575,y=64536..88112,z=-389..11193
on x=-7839..23604,y=9649..18002,z=71320..80369
on x=9903..41159,y=-67049..-35226,z=36893..65184
on x=7673..23235,y=-28519..-2042,z=-76945..-56528
off x=-57904..-35587,y=27900..44561,z=51948..77633
off x=8565..13720,y=-73480..-50019,z=49621..54335
on x=-56404..-36399,y=-57375..-40927,z=36712..70219
on x=70684..91311,y=5805..11539,z=-34339..-11998
on x=-37304..-27013,y=66245..84813,z=29697..35104
on x=67668..84252,y=7104..39933,z=-18209..1515
on x=-10662..7773,y=-72594..-61831,z=25855..50662
on x=26653..57985,y=-52054..-28671,z=-58493..-40415
on x=17227..46111,y=53917..85222,z=-41020..-22517
off x=-24743..-23426,y=-38166..-20539,z=-73558..-70558
on x=-71444..-52816,y=42181..61021,z=-13175..13567
off x=38239..67388,y=-47432..-35883,z=37000..49998
on x=-29372..-10740,y=10145..18327,z=66536..86250
on x=-74091..-53011,y=-35460..-2123,z=10863..36485
off x=-830..26012,y=-83838..-74027,z=-17749..4332
on x=39856..61767,y=19212..36644,z=39104..68753
off x=58969..74710,y=23746..48082,z=-36731..-13095
on x=-46857..-17761,y=54517..88038,z=-21028..4865
on x=5757..31806,y=-87159..-59641,z=21926..45050
off x=57158..79794,y=369..22188,z=-38467..-16755
on x=-22198..-6915,y=20120..55734,z=-77326..-60268
on x=-8295..15579,y=27424..42200,z=-80784..-62186
on x=-70154..-59688,y=-37012..-10957,z=33343..53899
off x=6596..15666,y=-17845..-165,z=71385..80703
off x=18021..36900,y=35594..57867,z=55564..66934
off x=-36438..-22194,y=-74367..-65732,z=-33994..-7716
on x=34321..65894,y=24729..47784,z=44010..60150
on x=37440..55824,y=40602..67577,z=19739..39032
off x=58890..73594,y=-4182..4316,z=-42633..-14798
on x=15171..33924,y=49029..65558,z=-61087..-33220
on x=29532..56508,y=51669..74738,z=-33565..-5605
off x=-71184..-63148,y=27975..59373,z=-43298..-19545
on x=-60077..-44310,y=54154..68101,z=-7114..3158
off x=62585..74266,y=20842..33285,z=23976..43591
on x=-2872..26017,y=-91343..-71379,z=-6102..8061
on x=41592..62416,y=-60063..-32783,z=8821..34878
off x=-25312..6506,y=45464..69626,z=-61839..-56490
on x=23936..44808,y=-2387..26444,z=-89650..-54771
off x=-83092..-59003,y=25545..49808,z=13822..42003
off x=-86923..-66776,y=-34795..-2691,z=-17352..6044
off x=71523..83477,y=-14130..18457,z=-41065..-18062
on x=77806..95470,y=-19234..3652,z=2341..6426
on x=19824..27633,y=-67834..-43300,z=49127..66225
on x=-71200..-47334,y=-53184..-48462,z=-12733..-6216
off x=-53021..-51480,y=-12549..7458,z=41350..63702
off x=-33512..-771,y=-42099..-16505,z=62759..74194
on x=34807..47110,y=-70974..-42229,z=-53462..-42371
on x=66762..79760,y=-387..21133,z=-1509..18944
on x=43420..61556,y=-21987..-6645,z=-80823..-47708
on x=-63729..-50036,y=10611..32202,z=-70719..-39403
off x=-38050..-17413,y=25687..43690,z=-73084..-59525
off x=6350..18248,y=-91079..-62333,z=-37340..-27594
on x=-32608..-9043,y=69031..79721,z=-21063..-630
off x=-87007..-63742,y=-49906..-22057,z=-17417..3476
on x=-17673..963,y=-57481..-36146,z=-76921..-42934
off x=-79831..-50990,y=33844..51773,z=-25828..2983
on x=15672..46344,y=-57937..-32656,z=-67008..-48368
on x=-49967..-27963,y=-81228..-52999,z=17158..34774
off x=18153..43168,y=-85201..-60731,z=8057..30431
off x=-67119..-47969,y=-51209..-29317,z=-54436..-44903
on x=57416..73315,y=-29876..-23159,z=10433..31168
off x=-15008..-1047,y=71855..82302,z=-3495..22865
off x=-52138..-40439,y=42840..55947,z=-46363..-15750
off x=64773..75014,y=9560..22050,z=-38909..-19955
on x=-31122..-1534,y=-22615..6714,z=-87340..-59806
on x=73201..83039,y=-12709..9883,z=-28495..951
on x=-33265..-13215,y=-77820..-55917,z=-37084..-20515
on x=23818..49626,y=-12581..9343,z=-69309..-52153
on x=-77351..-52406,y=-52921..-39440,z=19081..36358
on x=-64586..-51868,y=20667..34234,z=-48558..-37167
off x=-91514..-74820,y=-6979..23809,z=-8029..3818
on x=22909..48595,y=-4908..23549,z=-75631..-58012
off x=27777..35250,y=36781..44804,z=39450..69918
on x=-45648..-27303,y=23384..48276,z=-64720..-45918
off x=21298..46435,y=15936..43855,z=66654..74582
on x=-498..17127,y=18495..44964,z=-84124..-61584
off x=-84477..-58932,y=-29078..2680,z=-55341..-44338
on x=63128..84454,y=-19533..-9427,z=-41106..-27274
off x=-25136..-5974,y=51930..85546,z=25807..35948
on x=50137..88583,y=-38201..-20317,z=-1165..32787
on x=-16269..4565,y=-54781..-37040,z=54733..74868
on x=31918..53358,y=52954..77962,z=-20309..-9155
off x=6259..30795,y=63250..73684,z=25841..49676
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#############
#...........#
###D#A#C#C###
#D#C#B#A#
#D#B#A#C#
#D#A#B#B#
#########
#!/usr/bin/env python3
import re
import math as m
from networkx import Graph
from networkx import shortest_path
from networkx import shortest_path_length
import copy
g_min_energy = m.inf
hallways = [(1,1), (2,1), (4,1), (6,1), (8,1), (10, 1), (11, 1)]
weights = {'A': 1, 'B': 10, 'C': 100, 'D': 1000}
chars = ('A', 'B', 'C', 'D', '.')
def load_input(path):
amphipods = list()
with open(path) as fd:
data = list()
g = Graph()
for i, line in enumerate(fd):
data.append(line)
for j, ch in enumerate(line):
if ch in weights:
amphipods.append([ch, (j,i)])
for i in range(0, len(data)-1):
for j in range(0, len(data[i])-1):
if data[i][j] in chars and data[i+1][j] in chars:
g.add_edge((j,i), (j,i+1))
if data[i][j] in chars and data[i][j+1] in chars:
g.add_edge((j,i), (j+1,i))
return amphipods, g
def is_free(path, amphipods):
positions = set([pos for _, pos in amphipods])
path = set(path)
prev_len = len(path)
path.difference_update(positions)
if prev_len == len(path):
return True
return False
def min_energy_remaining(g, amphipods, rooms):
min_energy = 0
for amphipod, pos in amphipods:
min_energy += shortest_path_length(g, rooms[amphipod][-1], pos)*weights[amphipod]
rooms[amphipod].pop()
return min_energy
def process(g, amphipods, rooms, energy,level):
level += 1
global g_min_energy
if g_min_energy != m.inf and g_min_energy <= energy+min_energy_remaining(g, amphipods, copy.deepcopy(rooms)):
return
finished = True
for i, item in enumerate(amphipods):
amphipod, pos = item
finished = False
room = rooms[amphipod][-1]
path = shortest_path(g, room, pos)[:-1]
if is_free(path, amphipods):
next_amphipods = copy.deepcopy(amphipods)
del next_amphipods[i]
next_rooms = copy.deepcopy(rooms)
next_rooms[amphipod].pop()
process(g, next_amphipods, next_rooms, energy+len(path)*weights[amphipod], level)
else:
if pos not in hallways:
for hallway in hallways:
path = shortest_path(g, hallway, pos)[:-1]
if is_free(path, amphipods):
next_amphipods = copy.deepcopy(amphipods)
next_amphipods[i][1] = hallway
process(g, next_amphipods, rooms, energy+len(path)*weights[amphipod], level)
if finished:
print(energy)
g_min_energy = energy
return
def part1():
# First Part
amphipods, g = load_input('input')
rooms = {'A': [(3, i) for i in range(2, 4)], 'B': [(5, i) for i in range(2, 4)], 'C': [(7, i) for i in range(2, 4)], 'D': [(9, i) for i in range(2, 4)]}
process(g, amphipods, rooms, 0, 0)
print("Part 1:", g_min_energy)
return
def part2():
# Second part
global g_min_energy
g_min_energy = m.inf
amphipods, g = load_input('input_b')
rooms = {'A': [(3, i) for i in range(2, 6)], 'B': [(5, i) for i in range(2, 6)], 'C': [(7, i) for i in range(2, 6)], 'D': [(9, i) for i in range(2, 6)]}
process(g, amphipods, rooms, 0, 0)
result = g_min_energy
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
# part2()
#############
#...........#
###D#A#C#C###
#D#A#B#B#
#########
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
import math as m
from collections import defaultdict
import itertools as it
pattern = re.compile("target area: x=(\d+)..(\d+), y=(-\d+)..(-\d+)")
def load_input():
data = list()
with open('input') as fd:
for line in fd:
line = line.strip().split()
data.append(line)
return data
def prepare(data):
kn = list()
ln = list()
for i, line in enumerate(data):
j = i%18
if j == 5:
kn.append(int(line[2]))
elif j == 15:
ln.append(int(line[2]))
return kn, ln
def largest_number(kn, ln):
zn = [0]*15
number = [9]*14
count = 0
while count < len(number):
if kn[count] > 9:
zn[count+1] = zn[count]*26 + number[count] + ln[count]
count += 1
else:
temp = zn[count]%26 + kn[count]
if 0 < temp < 10:
number[count] = temp
zn[count+1] = zn[count]//26
count += 1
else:
while True:
count -= 1
if kn[count] > 9:
number[count] -= 1
if number[count] == 0:
number[count] = 9
else:
break
result = ""
for i in number:
result += str(i)
return int(result)
def smallest_number(kn, ln):
zn = [0]*15
number = [1]*14
count = 0
while count < len(number):
if kn[count] > 9:
zn[count+1] = zn[count]*26 + number[count] + ln[count]
count += 1
else:
temp = zn[count]%26 + kn[count]
if 0 < temp < 10:
number[count] = temp
zn[count+1] = zn[count]//26
count += 1
else:
while True:
count -= 1
if kn[count] > 9:
number[count] += 1
if number[count] == 10:
number[count] = 1
else:
break
result = ""
for i in number:
result += str(i)
return int(result)
def part1():
# First Part
data = load_input()
kn, ln = prepare(data)
result = largest_number(kn, ln)
print("Part 1:", result)
return
def part2():
# Second part
data = load_input()
kn, ln = prepare(data)
result = smallest_number(kn, ln)
print("Part 2:", result)
return
if __name__ == '__main__':
part1()
part2()
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 14
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 13
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 8
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 4
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 10
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 10
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -3
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 14
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -4
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 10
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 12
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 4
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -8
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 14
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -3
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 1
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -12
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 6
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 14
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 0
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -6
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 9
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 1
add x 11
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 13
mul y x
add z y
inp w
mul x 0
add x z
mod x 26
div z 26
add x -12
eql x w
eql x 0
mul y 0
add y 25
mul y x
add y 1
mul z y
mul y 0
add y w
add y 12
mul y x
add z y
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
def load_input():
with open('input') as fd:
rights = set()
downs = set()
x_max = None
y_max = None
for i, line in enumerate(fd):
for j, ch in enumerate(line.strip()):
if ch == '>':
rights.add((j, i))
elif ch == 'v':
downs.add((j, i))
else:
x_max = j
y_max = i
return rights, downs, x_max, y_max
def get_next_right(right, x_max):
return ((right[0]+1)%(x_max+1), right[1])
def get_next_down(down, y_max):
return (down[0], (down[1]+1)%(y_max+1))
def process(rights, downs, x_max, y_max):
next_rights = set()
next_downs = set()
change = False
for right in rights:
next_right = get_next_right(right, x_max)
if next_right in downs or next_right in rights:
next_rights.add(right)
else:
next_rights.add(next_right)
change = True
for down in downs:
next_down = get_next_down(down, y_max)
if next_down in downs or next_down in next_rights:
next_downs.add(down)
else:
next_downs.add(next_down)
change = True
return next_rights, next_downs, change
def part1():
# First Part
rights, downs, x_max, y_max = load_input()
count = 0
change = True
while change:
rights, downs, change = process(rights, downs, x_max, y_max)
count += 1
result = count
print("Part 1:", result)
return
if __name__ == '__main__':
part1()
.>vv..v..>v..>.>..>>.>.v>..v.v.vv>..v.>.>vv.v..v..>.vv.>>.vv.vv>.....>..v.v>.>>v>...v.vv..>>.v........>v.v.v>v.v.v.>vv>.v>vv>..>>>vvv...v>.
.vv...>.v.....>.....v>.v>v..>>.>>vv....>.v>v.v>........>.....>..v..>.>..>v>v>vv>..v.>v.>v..>.>v......>.>>>>v>.v.>.>.vv...>v.>.v>.vv.vv>.>.v
>.v>.vv..>.v...>v.>v.v.vv.>vv.....v.>v...v.v.v>....>..>v.>>.>.vv....>.v....v..v>>...>v.>...>..>.v>>v>....vv..>>v>>>>>>..v.....>..>>..v.....
.v>>v>v>..>>>.v..>v.v...>v>..v....vv.v......>vv...>..v.>>....v>v>>.v..>..>>..>.>.........>v..>v..v...>>>..>>>....v.>v>v.>v..vv..v>v..>..>v.
.v....v.v...>.v>v..>>..>.>.v.>v.>.v>..>.v.>>..>>.v..>.v>.v>..>>.>.v>..v>.>v.v...>v>..>...>.v.>..vvv.v..vvv.........>>...>.>v...>v>v.v.v>>vv
vv.v...v>vvv..>>...v.v>.v>.v.>.v>v..>v..v..>>v>>.vv>...vv..v..v....v..v...vvvv.v>.>...v..v.>....v>.>v...>......>...v>....>v..v...>....vv...
.>>>v.>..v.v.v>.v..v.v..>.......v>vvv.>.>>..v..v.>..>.vv....>v........>vv..v>.>......v..>>.>.....v.v>vv.......>..v>.v.>..>...>.v.>.>...>..>
v...v.vv....vv>.>.>>.v...>...v.>....>.v.>.vv>.>v.>>..>vv..v>.v....vv>v.>v..>..v.v>v..v..>>..>>v.v.>v.>>.v..>.v.>..>>>.>.v.vv>....>>>v.v.>v.
.v..v.>v.v.>v..v.>v.>.vv.>....>.>v.>..>>..v.vvv>v.>.....v.>>v>..v...>..>.....vv...>>>vv..>v.....v.>.>.>>..>v.....>.>>v.v>>>..v..vvv......v>
v>.v..v....v.>v..v..>>...>v.v...>v>...vv....>vvv>>.>vv>.>v...v>..v...v.v>v.>vv..>..v.>.....>>>......>...>>...v.>vv.>.>.>v.>.>.>vv....>>v...
v>...>.v.>..v..>.v>....>.>.>.v>>.v.v..........>.v..>>..>.>.>.v>vv.>.v....v.v>..>.>>..vv.>..v....>.v..v>...>..>v.v.>vv.v.>.v..>>v>v>vv>.>.v>
.>v..vv>.>v>.>.>vvv.>.v.>>v..v.v........>...v>.....>v...v...v>..>>..v>>>..>...>.>v.....v.>.vv...>vv.v>.>>..v..>>vvv>>..v.>>>.v.vv>>..>>>...
...>.......v.v>..>vv...>>.>.v>..>vv...v.......v.v.v.....>>v.>.>....>..>v.v.>vv..v.>..v.>v>..vv.>..vv.v.>>..>>vv..>...v.v>.....v.>v..>..v>..
>>..>>>.v..v.vv>>...v.vvv....>.v..vvv>.......>...>.vv..v>.v>..v....v..>.>>..vv.....>v..v>vv.vvvv.>>..v>.>.v>.v...v.vv.v.>>v.>>.>>.>.vv>v.v.
>..>v>....>.>vv.v...v...>.v.....>>>v.v.>..vv.v.....>v>>.v.>vv.>v..>.vvv.v.vv....v..>..>>v..vv>>>.vv.>.v.>.v>>..v..>>.>>>.vv>.v.......v>..>.
..>v>..>..v.>>.vvv..vv..v.v>>>>>>..v>v.>......>....v...>.>....>..>>v..>..vvv>v.>.v......v>>..>>>...>>v.........vvv>...>.v....>>.>.>.>>.v>v.
>.v..>v.v>.>.vvv.>>...>.v..v>v..v.v.v.>vvvv>>..v>.>.>>>..>.vv....>..v.v>.>.>v>v.....>.....vv.v.>v....>.>..v.vvv.vvv..>...>.>vv.>>..vvv..vv.
..>>vv.v.>.....v.v.>>vvv>v.>>..vvvv.>.>.>....>>v.v....vv...v.>.v.v>>..>...v..v.>>.>.vvv>>.vv.vvvv>.>v..>v..>.>....>v>v.v>vv...v....vv...>.>
>.>...v.>...>...>.v..>.v>>>.>.vv.vv..vvv>>.>..v.v..v.>.vv.v.>v.v..vv.vv>.v...v.v..v...>>..>v.v>>v...>>>...>..v...v.>..vv>>.>v...>>>.v...>>v
..>>.v.>v..>.>..v...v.v..>v..>.v.....>..>v.v>>..vv.v.v.>>..>>..v>..>vv.......v>.vvvv.v>>>>...>>.>v.>.v.>v>..>>.v...v.v.v.>.v..>v...>..v>v.>
>v.v>.v....v>vv.>.v.>.>>...v.v.vv.>....v...>v.>.>>...v.>v>vv.>...vvv..>v.v>>.>>..vv.vv>>v.>...v>v>...v>..>..>.v.>>v.vv.v......v>vv>.v....v>
.>>..v..v..v......vv..v.v>..v..v...>>>.v....v......v>.>v.v...v>......v.v>>v.v...>vvv>>v>.v.vv..>v>v>...v>.vvv.>v.>vv...vvv..v..>.v..v>.....
>....v>...v.vv>..>....>..v>v>>v.v.v>...>..v..>.v....>..vvvv..>.v>v>.vv..vv>>v>...>>.....v....v..>vvvv.>v...>>vvv>v.v.>.>>>v>>vv>.v.vv.>>.>v
>........v.....>.>v.v>.v.v.>.>.v>.v...v.>>.>...>>>v.v.vv>......v>...>v>>v.>>.>v..>v.>.>...>v.>.v.>....v.v..v.>.v...v.>....>...vv>vv>v.v...v
.v>vv..>>>>.vvv.>>..v.v......v>.>>...vv>v.vv...v.>>>v...>v..>..>>>vv..>....vv..>.vvv...v......>.....v..v..>.>v..>>>>...>.....vv..v.>>>vv..v
.....>.v.v..v>>.>v..>.>.>>........vvv.v>>.v.....>>.vv..v>>.v.v..>..v.v.>v>v..>.>.v..>v>.>....v..>.v...>>.>..v....>v>v.>...vv...>..>v>>.>.v.
v>...>.>..>.>..v.v.>>....v>.vvv.>.>>.>......>.v.>.......vvv.v.>v>.>>.>.>..>v>.>>.vv.v...v..v....>>v.>.v.>....v>>.>v>vv.>>.>>...>..>.v>v>vvv
..v>.vvvv.>>v>>.>v.>..>.v>.>vvvv..vv>...vvvv.vv.>>...v>>.....v>..v>>>v.>..>.v..>v>.>>v.>.v...>..v..>>.>>.>.>.....v.>.vv.v.>>.>.>>>...vv>.v>
vvv>v>vvv>v.>..v..vv>.vv...>>v..vvvvv>v.>v>.>>>..v>vv..>v.>.>.v.>..>>.>v>v.>..v>>.>vv..vvv>v.>.>vv>v..vv>.>.>v.v.>>>.......>v.vv>....>.>...
>>..v>.>.vvvv>.>.....>.>>.vv>..v..vv....>.v..>>>.v.>..>>vv.....>>..>>....v>.>.>.>.v.........>..v.v>.....v>...>.>..vv.>.v.v>....>...vv>>v.>.
>>v...>.>v.v..vv.....>.>.>.>...v..>v.v>>.....>v>v>>vv..v..v..v....v.v>..>>...>...v.>>v...>...>..v>.>..>..>v.>vv>v>.>v>..v...vvv>...v..v.>v>
....>..vv.>vv>....>.v>.v>vv.>>.>>..v>>.vv>.....>.....>.v>....>>.>v.>.v.>>v.>.vv...........v>.>.>v.v..>.>...>...v>...v>>.>>v>.v.v.>.v.>..>..
...>v>>v>v>v.>.>>v.v>v>....>>.>.>vv.v>v.v.>vv.v>vvv.v..v...v.>.>...v>...>.>v.>v>v..v..>vv.>.vv.>.>vv....v>>>.>>>>..>....v>v>v.v.>..v.>>>v..
..>.v.v..vvvvvv...vvv.v>.....v...>.>...>..>>.vv>v>.>>.vv..>>vvv>.>vv>.v.>v..v..v..v..v..>v.>.v...v.v..>vv.v>>v.v..>>...>..>v.v.....v.>vv.v.
.....v.....>>v....v..v.....v>.vv..vv..v>...>>.....vvvvvv..v..>.>>....v>.v>..>...>>..v..>..>.......v....>....>>.v>.v.......>>>v.vv>v.>.....>
>.v>.>>.>.v.>.>...v.v......v.>>v>.>.>>...>v>v>>...>.>..>v..>>.v>.vvvv.v>...vvv....v...>vv>>.v>..vv>vv....v...>...>>v.>>>.>.....v..vv.v>.>>v
>>v.v...vv..>..v.>..>.>.v..v>....v....>vv>>v.>....>..>.v...>.>..>...v>>.vv...v.>...>v.v.>>v>>..v.>v.>.>vvv>v..vv.>...>v>>.>>.>>..>v.>vv.v..
.v..v>...>>>.>.>>vv.v..v...>.>>v>vv.>v.v..>..>.>....v.>.vv>>....v...v>.v>>>vv.>..v...vv.v...>..>..v>vv>..v>.v.vv>>...v.>.>>....v........vv.
v>.v.v.>.>.v>..v..vvvv...>vv.>v.vvv.>>>.v..>..v.>..>.>.....vv...v>>....v>vv>.>.v..>v.>.v>>>vv..v.v.>>.>v.>.v>..v>>....>>.>v..>...v........>
v....v>>>...>v..>v.>..vv.>.vv..v.v>.v>vvv...v>>...v>vv..>.>.>>.>v.v.v>>.>.>...>>.v>v.>..>>........v..v.>>.v>.>vv>...>........>v>...vv.v...>
.>.>v>.v>.v.>vv.v>.v.>v.>..>v.>vvv..v..v.v.>v.>v>v>>...>v.>..v.v.v>..>>.v>..>vvv>v..>...v>.vvvv.v.v.>>.vv........>v..vv...>v.>..vv>v.>...>.
.vv>>...v.vv>.v>v.>..>.>>..v.vv>.v.v>v.vv>v>.>.v>v>..v.>.v>v.vv>>.vv>..v.v>....>v.>.v.v.>>..v.vv..v..v..>v...v.v...>..>v.vv.>>v.v...v>>>..>
..>>>.>.>v>....>>>..>.>.v>>>..>v>..v.v.......v..v>vv.v....v.vv>.>...>>.>v.vv>v.>.vv>.>vv...vv.>..v.....vv.......>...vv.v>.v.>.>v>>.v.v..v..
...>...>v..v>.v>.....vv.>.vvv>>..vv..>.v.v>v.>>v>.>.>v.>..v....v.>.>...>>>....v>.>..v.v.>..>>v.>v.....vvv...v...>.v>>>.v>......v...v>....v>
..>.>v.>...vv.vvv.vv......v.>v>...>.vv>v>..>....v.>...vv>v....v>v.>......v.....v.v.......v..>....>.v.>.vv..>v.v.>v.>v..>.v>v....>v>....>.>.
>.>.>.vv.v>.vv.>..>.vv..>..>v......v.v>>.>..vvv..>...>..>.....>>.v>.vv>>v>.vv.v..v.v>.>...v.>.vvvvv...v>.>...>>....vvv.v.vv.v......>.v.vvvv
v...v>>.>.v.v>.>>v>>v>vv.vv...>vvv>v.v>....v.v>v...v....>..v.v.vv.>v>.vv.>vv.v..v>vv>.>...v.vv.v>vvv>.>.vv>>.>.>>...v..>>v.>v>>>v>v..v.v>..
..v.v>>>v>.>..>>....v>v.v.v.v..>.v......v...vv>>..>...>.>.>>..>.v...>v>v..v.....>v>>.v>.v>>.....>.......>vv>>v..>>>v....v.v..v.>.v.v>>v.v..
.>>v>v>..........>vv.>.v>>>v.>>vvv....v>..>>>v...v.>>.>.v>......v>...vv..>.>v...v.>v>>..>.v..>..>.v....>..>.>>v>>.>..v.......>.v>>.>....vv.
v>>..>>.v>.......v.v..v>..>>>>>vvvv>..>>vvv>..>>...>.>.>.>vvv>.....v>.>..>..>.>vv..>.>..vvv>vv>.>.>.v>......v.>v>.v>...v>..v>>>...>.v..>.>.
.v>>vvv..>vv...>.>>vv.>...vv.>..>>.>v>>..v>....v>>...>..vv>v..>>.>>......>>...>...v.>..v>.>v...vv.v>>v>vv..>>v>..v.>...v>....v..v..v....v..
.v.>vvv.v>.vv>.vv.v>.>.>...>.v..v>..v>vv.>..>>.v.v.>.>..>vv...v.>.>>..>>.>..v..v>..>.v.v.v>vv>.v>>>v.>v.v.>..>.v>..v.vv...>>.v>..v....>..v.
>.v.v>.>>v...>v>>..v.vv.....>..>..>>..>.v.....vv.....>.v>v.v.......v.vvv>.>vv>.v.>.>..v>>.>..v.vv.>.>>.....v.>v>vv...>.v.....>.>v.>>>..vv..
>...>>.v>v.v.>>>.vv>.v>v..>....v.>.vv...>.vv..>..>.v.....v.>v>...v.v....vv>>..>>..>..v.>.>v>v.v.>.>v..v....v>>vv>.>>vv.>>v.vv....v>.....v..
v...>.v..>v..vv........v...>>...v...>.v>.>.vv...v..>>.v>..v..>.>>>......>>>>.vv.>.>.v......>v.v>..>.>>v.v...v..v.vv...vv..>>>vv...>.>>>v...
>...>.>v.>v>.....v.....>.vv.>v.vvv>.v>>vv....>>vv>....>v.>v..v>...v.>>..v..>..>.>v....v>.v>.v>v>.>>.>.vv>.>....>...>v....v.vv>..vvv.vvvv>v.
>.vvv..v..>>.v.v....v..>>.v..vvv....>.v.>vv...v.>v.>v>vvv.v..>...>v>.v>v>v..>>>>..v>>v>.>v>>.vvv......vv>.>.>.v>.>v>.....v>>>.v...>..v..v.v
...>>..>>vvvv.>...v>.>.v>.>>.>......>>>...>>.vvv...vv.>.....>.>vvv>....>.>>v>.>...v>..v..v..v.>v...>..>v......v..vv..>.>v.vvv....v..v>.v...
...v..vv.>..v.>v..>.....v..vvv>..v.v.>..v.>.vv.v.v.>.v>.>>>..v....>>v.v.>.v>>.>v>vvvv>.>v......v..>.....>.>....>..>.>vv.....vv.>.>>...>.>.v
>...v...v..v.>v.>>.>...v>.v.v>>....>.>>v.>..>>.v..>>...>..vv>v.v.>.v.v.>...v.>v.....>.vv.>..>>.>.>.vvv.vvv.v.>....vvv.vv..>..v.>v..........
.vv>v...>.v.>..>vv.v..v..>.v>>>...vv..>.v>>vv>..>.>>v>.v...>.vv.vvv..v.v.vv>.>..v>v.>>..>v>>...v..vvvv..v..>vv>...vv...>>...>.>>>.>...>v.v.
>>.v.v.v.>>v.>>v>.>...vvv>>>..>>.vv....>vv.vv>vv.v..>.v.vv..v>>.v....v.v.>.>..v.>>.>>.v..>>.vv>v>.>vv>..v>>..vv>>>>.v>.>>v.>.>v..>.>.>...v.
..v....v.v.v>.>.v.>...v..>.v>.>vv..v.>..v..v..vvv>>.>..v>..v...>>>>vv>v>vv.>...v.v>.>..>vv>>..>vvv.>v>>>v>vvvv>.v..>.v.>.vv.>.>.vv>..vvvvv.
...v>.>>.>>>.>.vv>.>>.>>>..>v>>.>.....>.>.>.v>>v..>.vv>v.v>>v...vv>vv>.>..v.vv...>.v>.>v..v...vvv..v.>v>>.v.>.v>>...v...>vv.v>.vvv>>.>..v..
v.>.>v.vv>vvv.>>v...>>......>v.>..>v>v.v....>...v..vvvvvv..>v>v..vv>...>>...>v.v>v>>vv>..>v..vv.v>.v.vv>.v...v.>v..>v>.v>..>..v..>.>..>..>.
.>>v>.>>..v.v>...v.v....v.vv..>v>....>v.v......>>.>...>>.v>.>...v.v.>.v>>v.>>>......>>.v.v.>...v....>>.v.v>.>>v.vv..>>v>v>v.v...v.>>.>...>.
>>........vv..vv>v>>..>>>..vv.v>>.>vv>>>>.v.>>v>...v...v>>v....v.....>v..>..vvv.v.....vv>v>v>v>..v>.>vv>v.v.v>...v>.>vv.v.v>.v..>.v......v>
..>v..>v>v>>>v.>>....v.>>vv>v>>..v>..v..>>.....>v>..>>..>....>v..v.....>vvvvv>.v..>.v>v.vv.>v....v....>.v>.v.>.v>>...>..>.v>....>..>v>vv..>
>>>>.>..vvvv..>>.v..v...>v...>..vv..>>.v.>v>.>v.>v>>v.>>..>.>v>v.>v..v>vvv.>v>>.>vvv.>.v>v.v.v>>>>.v>v...>v.>v>.>>>v.v.>v>.v.>....>v.v>..v.
.v>>.>>vvv.>..>.v>>>vvvv>>...>..>vv..>..v..>v..>...v>..>v........v>>>.v>.v>.v..v>vv...>>.v>v...vvvv.vv>vvv>.v.>...>.>.v.>>.v>v>...v>..>>..>
.>..vv.vv.v.>v>>v..v>>>>v>>...v>...>.>>>.v..v......>>>>>....v.>>....v>v.v...vv..vv.>vv...v.v.......>v>..v>>.>v...>.v....v>>>....>.>.>.>>>v.
v..v.v>..>...>.v.v....>v...>v...>.>..>.....v>v....v>.>..>.>v....v>vv...vv.vv...vv>v..v..>>...>>..vvv..>v..>>v.vv>.v>..>...>v...v.>v>v...vv.
v.v..>.vv>..v>.v>.v..v>>v...v..>.v...vv.....>vv.......>....>>vv.>..v...vv.v>vvv..>v.vv..v..>>...v..>>..>..>.v>....v...>...v>.v.v...v....vv.
.>>>.>.......>>v.>...>......>.>.>.v>v..v...>>>.>v..v.vv>>..>.>.>.v.>>v.v......v>v..>.>..>v......>vvv.>>v.>.>...vv>>..v...>..vv..>.v.>.>.v>.
v>v...>>>.v.>>..>vv.vv>..>.>v....>v..>>.>.v>....>v>.>...vv....vv..>>v>...>.>v...v.>.vvv.>>..v.v>>>....>.v.v.>..v.....v.>.>v..>....vv.>v..v>
vv.vv>>>.vv.v...v.>.....>....v.>>>...v.>v.v...>vv.vv>.vv.v......>>...>.>.>..v.v>.>vvv>...v>>v.>....>v>..vv..>.v.v..v>v....vv.>vvv.>vv.v..>>
>>..vv...v....>.>v.v>.>..>v.vv>.v....>>v>v>.vvv......>..>.v..v.>..v..>v..>.v.v>>....v.>.v>>..v>..>>vv...>v>...v.v.v.v.v>vv>v>>v>v.....v>...
...v.>>>.>.v.v>.>>..v.>.vv>.>.vv....>>.v.vv.>.>.>...>.v.v.v..v...v>v..>>.>.>..>.>>....>..>>>....vv>v.>>v.>.v>.>v...v>>v....v.>v..vvv>vv>>.>
.v>.v.>>..v.v.>v>.v.>>....v.>.v...v.>v......vv.>vv..>>>...>vvv.>.v>vv>..>>>..vv>....>v.v>.>>>.v>>v...>>...>v..>.>...>>.v>..v>>v.>..>>.>>v.>
....vv>>..v.>.v.>>.....>.>....>>>v..v...v.>..>.v......>..v>>v>..vv.....v...vv>...>>.>v>...>.>.>...v.>.>>v>.v.v.>...>>....v.>.v>>>..vv.>v>..
..vv.>v>>v...>>vv.>v...v>>.>>.v.v.>v.>v..>>v.......>...vv.vv>..v>..v>.......>>v...vv.>vv..>..>v.....>vv.>.v...vv.v..>>v>.>.>.vvv>......v...
>vvv>.....v.v>>.vv..v>.>v>.>.v>>>v..>.v>..vv..>>.v..>.v>..v.>>...>v..>>v.v.>>v.>vv.>.v>.v....vv>..>>>>v.v>..v.vv>.v>vvv>>.v.v>>v>.vvv.>.>>v
>v.v.>v..>...>.>v>v>>vv.>.>.v...v.>.v.v>.v.v>>.....v.v>.>...vv.>..vv.v>v....>.vv..>>.vv..vv.v>.>>v..v.v..>..v.v.>...>..v.vv.v..v.>v>>vv>v.>
.>v.v..>.>..v..>v..v.vvvv.....>.v..>.>>v.v..>>vv>v.>.>.>...v...v....>..>>vv..>.>...>.v...v.>.>.......>>>..>>.v...v>..>.>vv...>.>>>v...>>>>>
vv.v..v..>v......>...>.v.....>>.vvv>>>..v.v.v>..>v..>..v.>..>>...vvv>v>>..>>vvv.>v..v>...vv....v.vv.>.>...........v.>>vv.>....>v>vv.>>.>.v>
>>>.>.>.>.>...v>>..>.v>>v.>>v.>vv..vvvv>>..v.v>..>>.v...>..vv.>.v..v.>.vvvvvv..v>>...v....vv>.>>v>v..v.>>v..v..v.v.v...>v>.v.>>>>.>>.>>....
...>>v>v.>v.v.>.>>>>v..>vv..v...v..>v..>v...>>>..>.v.>>..v.>.vvv>.v..>.....v>>......>v....>v.>.>.v..>..v.v>>..vv....>..v.vv.v.v...v..>>.>.v
v.>v>.....vv>>.>.v>.vv....v.....>v..>>>.>vv>..v.v>...v>vv..v.>v>...>.>v...>vv.vv.v..>>....>.....>..vv..vv>...>.vv..>v..v>v.>.v>..>>v>..v.>v
..v>.>>.v.>v.vv..>..>v>v.>vv..v..v.vv....v>vv....>.>vv.>>..>..>.v.vv...>..v..v..>v..>....vv.v......>v>..v>>..>.>.v..>.>....>>.>v.v.vvvv.>..
v..>>v.v.....>v..>..v.vvv.v>v....v..>.v>..>>v.>...>v>...v>v>.v...v.>>.v....v..>.v...vv>>>...>>.>>v>vvv>..>.>.>>>v>..vv>...>..>.vv>v....v...
vvv>v>vv.v>v>vv..>>.vv.>v.>.>>.v>..v...>..>v...v>.>....>v>>.v.vv....v..>.v.>......v>vv>v.>..>v>>..vvv>>vv.vvv>..........>.vv....v>>.>v..>>>
v...v>v..>v.....v>>..>.vv..>>..v>.....>..vv>.v...v.v>..vvv.....v..>>v>v..v>.v>..>..>v>.v>>.>..>...vv.>>v..v.>.vv.v..>.>>>>>.v>>..>.>.>vv>..
..>..>v>.>v.v.>.v>vvv.v.v.v.v.>.>vvv.....v.>...v>vv>v>.v.>>>.>.>>.v.>..v.>>>>.>..>vv>v>v>.v.>v...v.vvv>.....v.>>>>.v.v>>...>.v>..>.>..vv..v
.>..vv>.>v...vv.vv>...>..>..>..>..>>..v.vv>...>.......>...v>>>.v>.v..>vv.v.vv.v..v>.v>.....vv.>...>>>>>>.>>v..>.v>.v...vv..v>>.v>....>...>.
.v..>....v..>.>...>>v>......>.v.v>...>.>..>v...>v...>>..v.>..>v>...v>.>..>>..>.>.vv.>...>v.v..v>>..>.>.v.v..vvv>...v>.v>>.v...v..>.>.>.vv..
>..v..>>v.>>>...>vv.v>v.>>..v..........>..>v..>v.v..v.>v.>..>>v>.>...>..>..vv....vv.>...v>>v.v..v...v.>v>>.....v....v>v>>>..>>.v..vv>v...v>
vv>>v..>.v>........>.vv>.v.v...v.>>......>v.v.v.>>..v.vvvvv.>...>>....>>>.>>..v>vv>.v.v..v.>>..>v.>v..v..v..v>....>>vv>.v>.>vvv>v...>.v>...
..v>..v.>.>>..v>.>v.v>v.>....>>..>.>v..vv.......>.vv.>.v..>>>.>>>>.v..v.v......v>....v>.vv....>.vvv>.>v>>....>>>v>.>>.>v.>>.v.vv..>>>..v..v
.>>v>.>>..v..>>v.>>..vv....v>>...v..vv..>v.v....v>..>>..v..vvv>....v.v>.vv...>.>>>v..v>v.........v..>vv....>.vv>...v>.>v..>v>.>v..>...v..>.
>..v........>>>v>.v.vv.>>vvv.>.>v...>vv...v..>..v.>.v>>....vv.v.v.>..>>>vvv...v>>vvv.>.>>>..vv......>vv..>>vv>>..v.vv.v.v....>..>..>v...>v.
...>.v.v>.>.vv.>v.vv.v...>v>v>.v>...v.>.....>.>...vv.>.>.v..>vv..v>vv.>.>....v>.v>v>>vvv>.......>.v....vvv.v>>>v..v>vvvv.......vv........v.
.>..>>.>vv...v.v>>>>>...vv.>vv.v......vv.vv..vv..>>v.>>..v.>>..>.>vvv..v>.>v>v>v...v...vv.v..vv...>....>v>.>....vv>..v.>.>..v>v..>vvv.>v.>>
v>.v>>..v...v>.v.vv......v>vv.>.v.>.v.....>..v....>>...vvvv...>.vv...v>>.>>.>>>>.....v>.>.>.vv.vv....>.>.v>>>...v..>v..>>>..v..>vv>.>....vv
.v.>vv....>.....vv.>..vv..>v>.vv>>>.v...>v.v.>.v..v.v...>..v....vv>..>..vv>v>>..>.>v>v>...v>.>>...v.v...vv.v..v>vv.>.....v>...>>v>v.......>
v.>.v..>>v.v.>v...v.>>>v.>.>>>>>..>v.v.v...v.>v.........>>....>v>>....v..v>>>.vv.>.....v>>v.v>>..........>.>vv..>.>.>....>>>v.>>>v..>...v..
v..>.>>>v....v>>.v>.>vv.v..v>.v.v>.>..>>.vv.>>v>..v>vv.v....>vvv>>v.v.v...>>.vvv.v>v.v.v>..>.>.v.>>...>.v>>...>>.v..v>>.v>v.>.v>>v.v...v..>
>v..>v.v>vv...>..>v.....v..>v.v.v>vv.vv.>......>.vv>...v..>....>>v..v>vv.v>.....v...>>.>>....>.v.....v.>.v...>.v.v..v..v....v.vv>..v.v>v..>
.>v.vv>.>>.>v>.vv.>.>v>..v.v.>>v.v.v>.>v.>..v>>vvv...v.vv>>...v>>.v.>v....vv>>>vv>v.v.>.v>>>v>.v.v...v.>.>..>>.>>...v..>>v>>.v.vv>..v>v...>
..v.>>v.vvv.....v..>.vvvv.>...v>>>.vv>v...v>>v.>...v>.>.v.>v>.>.>...>>.>.v>...>>.v..v...>...>.v.>v.vv.>.v.v>.v.vvv>v..v.v..>vv>>.....>.vv..
>v....>.....>v.v..v.vv.>>v.>v.v.....v>>>v..v.>vv.v>.>.>v.>v.vv>.v>v>.>...v.vvv..>>>>..vv>..>v.>.....>.>vv.>..>v...v>.>>.v>v.>>..>>v.v.>.>v.
v.>v>>.....>.>>v>.vvvv>>>.>v.v>...vv.....v..>vv.v>.....>...vvvv.vv>>.vvv.v..v.v....v.>....vv>vv.>....v.v.>vv...v..v.>>vv...>vv>.>.>>.v.v>..
vv>>....v>..vvvv>v>>.v>>.>..v.>>>.>.v..>.>>vv....v..vv>>v.vv.vv>.>...v...v.v.>v.v..v..v..>v..vv.....vvv>..v>>.....v>>.v.....v.>..v.>v.>vvv>
>v...>.>..v.vv.......v.v.>..v.>...>...v....>>.>>vv>.>>...>..>.v.v.....vvv>..>.v>..v>vv..>v.v>>.v>...>>.v>vv.>>v>.vvv.>..v.>...v..v.vvv>v>v>
..v.>>vvv..>.....vv>.v>>v>..>...>vv.>..vv>.v...>v>>>..v>>v....v..v...>.v.v..v..v..>.v...v...>.>>>.v...v.v.>>>.v.....v>....>.>v>vvv..v>>..>.
>...v...>.v.....>>v>v..v.>>v>v..>>v.v>>...>v......>.>.vvvv...>v.>..>v.>.v>>.v...>.vv.>....>v......>..v.v.>.v>..vv>v...v>.>>v>.v.>..>....>v>
v.>..v.>.>..v.vv..>..>.>.v>v>v......>v.v..vv>...v>>.>..v>..>>..v.....v.v..>v>.>>.>.vv>..>>..vv..v>..v...>..>v..>>v..>v..>.>vv.>v..vv..>.>>>
.>.v>..>..>......>.>.>..v.>..v.>.v>>.v......>..>....>.>>.vvv.....>..>.v.>.>.v>..>..>>>vv...>..>.>vv...>>v.vvv.v.>.v>v>>>>.>>v..>vvv.vv.v>>>
.v.vv.>.......vv..v.>>.>>v>>>v....>...v.v..vv>>>>>.v.>.v>v>>.v.>v.vv>vv.>v>>.>>.>v.>v....v>v...v.vv..v.>>.v....v.>>>.>>v.>>.v.v.>.v......v.
..>..>.>vv....>.>.v.....>vv>.>>...v.vv>v>>.>......>v...>>v.>.v.v.>v>>.v.>.>.v.....v>v.>.v....v..v>.>>....v..v>v>..v.>....>>>v.vv..>>>v.....
.v...v..v...>>>vv.vv..v.>.vv>....>....v.>.vvv.v..vv>...v.>>v.v>>.v>.vvv...>..v.>...v>v>v>vv...>>v.>.vv.vvv.v>...>.>>.v>.v.>.>..>..v..>v....
...v>>..>.>vv>>>v..vv.v>.>>>.>..>>.vvvv>...>>vvv.v..v>.>vv>v.v...>>....v.v....>..>..>.>>v.>.vv.vvv>.>v...>v>..>.>v>>.v>>.vvv>.>>vv>>>>vv..v
.v>>.v.>>...>.......v.v>.>...v........>.v.v.....vv....>.v>....>.v.v>vvvvv>...v>v.v.>v.>.>>>..vv.>.>v>.>.....v>..v>>...>v...>.v.v>..>...v.>.
v>>.vv>vvv>.......>vvv..v.v..>>..v.>v>.vv>.>>v>...v>.v.v>v.>.>...>...>..v.>v....v.>v..>....v....v....>>...>.>.v.>.....>..>.>v>..>.>v>...v>>
...>..>v..>>>v..v.........v..>....>vvv..v.>>.>..v>...>.v.>v.v..>...>>>...>.v>>....v.v.>>>v>..>>.v.>...>.v>.vvvv.....>..v.>v.v.....v>..>.>..
.>v..v>...vv...v..v..>......vv.v.>>.>.........vvv.>.vv.>....v>..v.v.>v.v..>vv.v.>.>>...>v>>.v...v..>.>.....>v.v.......>..>.vv>...>..v.>....
>v>>.>v.>>.>>>>>v...>..>..>..>>v>...>>v....v..v.v.>.....v.v..>>v...>.vv>.>.>.v>>vvv...>.>.>.v.....v.>.v.vv....v.v.vv.v.v....>vv..v...>..v..
>...v.>v....v..vv>>>..v.v..v....vv.v.v.>vv.....v>>v.>>.v>>..>v.>>.v.>v.>.>.....>>.vv>>..>..>...v.>..v.>.v>>v.v.v>>v.>>v.vv.>v>...v>..v.>.vv
.>>.v..v>>.>v>v.vv>>>..>.v>.v...>>..>..>..>v.vv>v.>>v>v>>v>>v>>.v>vv>.>.>>vv..>>>.>..>.>vv.>.v>vv>.v>v.>v.v>.>.v.>..vv>....v.v.>v>.>..v.>..
.>..>...>..v.v>.>v>v.>.v..v...v>v..>.....>v..v..>.>.vv.v....vv.v>.v..>>v...v.....v.>.>v>>..v>..>v..vv>.v....v>v.>.....v..>.>>...>v..v>..vvv
>....vv...v.v>>v>vv..v....v.vv.vv>>......v>v...v.v>v...v>>v...v>>..v.>v...v.v>..>.vvv..>.>>..>.>.vv..>..>>.>>.>..>>.>...>>>>v>.v>.>...vv.vv
..v..>.vvv>.v.>..v...>vv>.v.vv.v>..v>.>.....v.>v>vvv.vvvv..>..v.>v>vvvv.>.vv>>.>.v.v>.v>.>vvvv...>....v.v>.vv>..>vv...v..v.>.v..>>.>.>...v.
.v...v...vv.>v..v>v>v..>>v..>v.v.>.>v>>.vv>>.>....v.>>.v>....>vv.>>..>.v>>....v.>..v>...>.>...v>>>v>v>vv>>>.vv>.>>.vvv..>v....>..>.....v>vv
.vv>.v.>..>..v.....v.v.>...>v>v..v..>v>>>>v.v..>vv..v>>.>>v>...v.>.v>v.>>>vv.v..v.>...vv...>v.vv..>vvv.v...v..>>v>......>.v..>..>>..>v.v..v
.>>.v.>..>v.>vv.>.>.v.>vv.>.v.v..>v.v...v>>.>....v>v.>>....>v..v.>...>vv..>..vv..>.vv.>...>..v>>v.v..v.......>...>vvv>..v...>.v>.>v>..>....
v.v.v>...>.....v.v...v.v..>.v>.vv>v.........>..v>.v..vv>..>.v>v.v>..v.>...>..>v>v>..........>.>...v>.v...>..>v..v>....>..vv..>>...>..vv..>>
v>......v.>..v.>...v..>v......v..v.>..>..>v...>..v....vvv...>.vv....>.>>.>....>v.>>>>>.v.vv..>>>>>>..>v..>.v....v.>v.vvv>>>...v....v..vv..>
>.vv.....v>v.v.v>v>.v>>v..>.v..v..>..>.....>.v.v.>>>..v..v>...v...>...>....vv.>v..vv....v.v>>v>vv..v..v.v>v.>v>vv>.........>.vvv..v.v>>..>.