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:
data = list()
temp = list()
for line in fd:
line = line.strip()
if line:
temp.append(int(line))
else:
data.append(temp)
temp = list()
return data
def main():
data = load_input()
# Task 1
calories = list()
for values in data:
calories.append(sum(values))
result = max(calories)
print("Result 1: ", result)
# Task 2
calories.sort()
result = sum(calories[-3:])
print("Result 2: ", result)
return 0
if __name__ == '__main__':
main()
18313
2404
10479
7011
10279
1496
10342
8918
3162
4525
4368
17242
10920
14072
9754
4435
9396
5915
2602
4032
3303
2685
1856
1334
4865
6385
1733
5328
8899
5482
3195
7837
8986
13794
25121
22211
21257
6360
4007
5124
2266
6943
6966
3887
3427
1255
5266
6119
2841
6167
3883
2776
5894
2013
6930
6613
4637
5259
2347
3550
5639
5117
4530
5961
5956
2503
5060
4770
5240
4123
4089
6794
3333
5244
4415
1733
1209
4458
1223
3859
7728
9793
8350
2278
3241
4668
1836
3669
2996
1772
5016
6294
6367
1080
5964
5547
4793
13744
9478
7979
1490
12490
6770
7282
2059
5242
13237
9365
2230
6498
1352
3846
3863
6205
5803
2646
4188
4431
6380
1526
2620
4438
24331
23578
4199
5126
5725
1123
2415
5427
5789
4856
2610
4833
3398
4239
1432
5122
5013
4939
11760
8419
5706
3765
10182
11795
9688
1712
2091
9651
13022
10393
11862
1672
5431
6812
1866
5599
2036
6561
4097
3467
4739
7656
3252
4322
5068
2345
4155
3090
1228
1270
8407
8118
4996
7157
3944
6230
2728
5669
2113
3076
1290
7673
1022
5805
5128
7912
7862
4955
20640
4131
4874
5220
9947
9739
1662
9418
9684
4875
3073
1151
11911
10310
10793
10307
6979
4265
8322
3518
1855
4912
5481
7124
4664
19975
16112
19450
7231
3909
4743
3794
4448
3200
3447
3331
7011
3345
3935
6750
3900
14850
4890
9625
4832
23682
1375
7463
8112
10624
1105
6625
5157
5839
1019
19089
36719
5372
7085
8536
8717
6255
5961
3198
7729
3055
4406
2263
6686
1458
2377
2740
1284
3045
7121
3070
19161
10515
1027
7782
1703
1864
3611
1039
2394
3472
6964
5824
8011
3341
56690
5107
1876
4973
5485
4325
6079
3187
3565
2875
7137
3887
6763
2633
2151
1105
2400
5338
3382
1330
3945
6556
1670
5526
4281
2168
5382
2347
4225
1905
4672
6706
5747
5808
1159
4878
5923
11148
8722
3896
15697
3499
46749
13315
20966
1625
6338
7882
1505
4226
9948
6438
6012
1003
10033
5066
7756
10151
10719
5299
5629
4466
6290
7220
3657
8261
7348
8525
4531
4892
7833
24723
7817
4234
4428
5810
2091
4301
1378
2342
3872
1167
2073
6867
7026
7005
10018
3954
4497
4951
1283
5383
4152
4390
8731
8521
5415
1029
8200
3769
7224
12281
8337
8969
13938
9651
10923
14358
8896
8401
7073
3934
4424
4538
4371
2335
6363
1264
4331
5107
2270
3109
2547
2304
5911
4600
5674
2620
1846
3804
2387
4094
3648
4241
5593
2974
2101
1621
3939
7429
9425
9653
5835
13414
4517
15783
3867
2287
1019
11604
11910
2591
2468
10543
13050
1396
13959
6883
6303
2889
4047
3954
2245
6672
4574
5731
5879
2837
5859
4812
6785
10290
10131
5605
3321
2122
6331
9107
7937
1786
1362
7409
2093
3901
1306
2089
1558
4163
6118
6270
1929
4224
3864
3922
3609
2496
2246
5397
1535
5499
4932
3684
1348
3437
3665
2973
4506
3971
2511
4563
3168
2687
6249
2593
6470
4100
6309
1316
4362
14966
2940
11485
6675
16873
5695
14706
3953
5620
1678
3630
5015
3277
4957
5288
5555
2860
1750
2795
6170
6308
3671
1354
4018
4730
4070
1685
4478
1918
5532
3970
3751
4890
4277
2737
5535
14799
8129
5254
2065
1282
2407
5174
4549
4326
1201
3372
3906
6234
4937
4234
2149
5194
2519
3555
6929
4367
4547
1024
37240
3693
6526
2679
5434
7924
2974
1754
4287
4744
4187
1348
6598
5963
6035
5404
3270
1250
5947
3037
3927
3702
5255
1640
6476
4499
5207
1991
4613
3088
5024
4737
5160
2450
3582
2605
2573
1100
3732
1633
5663
2415
4039
4957
2697
5428
5050
3979
3428
4563
3770
3635
4012
4773
7377
6189
10812
6905
11196
5394
10135
10008
2868
2630
8542
8897
2718
5831
4460
1303
4771
1574
2960
5070
1596
5530
4177
4210
6465
4179
1000
4460
6173
6654
1378
2148
8704
6875
4511
7540
6078
5585
4030
4333
5953
5095
4782
3651
4673
3267
6389
2358
2120
3684
3034
3420
1322
8922
9535
16357
16552
1378
1039
1262
2067
6491
2776
1352
4914
5832
1369
6105
1384
2474
1704
6256
2538
4701
4090
4077
5333
2777
4082
4640
2542
6356
3065
4855
2535
6510
3709
4197
4344
5906
6852
7398
3578
3308
1239
3817
5676
5441
3368
1752
2629
1923
4711
1667
3701
1350
4764
6439
2341
4052
6407
5327
1229
4834
6008
1302
5595
5260
3680
3220
3154
3353
1942
1740
2356
1908
3058
4668
3641
1663
4199
2190
6067
3923
3288
1978
6110
5330
7020
2487
6521
1084
6582
1784
7861
2759
8077
2961
68314
2160
15170
2267
3867
6851
8543
4118
22260
5313
3525
1483
3613
5798
1472
4020
5607
4391
2502
5512
5535
3755
5590
3668
25502
7623
15508
2138
1227
11355
1288
7062
5391
3994
7738
3667
5000
1691
7322
8054
4540
2353
6870
8475
4289
6415
1251
4933
7224
2608
2320
4432
4637
1395
6575
5581
6841
1161
5617
12505
6274
9171
13548
20154
20682
2843
7363
5967
15256
16032
7940
6992
3940
3100
1334
1389
5182
6666
4030
6116
3036
35234
19273
7268
10689
1846
4211
1504
3780
3789
2017
6279
5001
2341
6350
5169
1966
2640
5574
2125
8432
8339
8130
3506
6115
4684
9548
3300
6848
1274
6463
12007
10719
10590
5616
4471
1304
1635
5960
3702
1747
3658
2446
4724
5675
1739
3170
3556
9134
12963
6987
5728
7877
6499
5909
1119
3090
5033
4884
3151
10675
8053
9237
14206
11710
49154
5999
3861
1836
3451
3673
5193
2680
6068
1743
5600
4793
6211
2967
1021
24720
8749
11674
4039
5341
14256
4553
3893
1528
5490
2417
2392
4023
2430
4649
3163
3673
1378
1957
1055
10777
4742
16291
16430
12295
6502
6052
2944
8166
7567
3580
5957
4691
1623
3269
1013
5809
16958
4994
36633
8535
13662
24448
6651
7911
19793
2436
4671
4420
5322
1215
4952
1193
2387
2799
2748
1343
4123
1715
2978
2148
6050
2036
4670
5444
4584
4220
6061
2834
2319
1370
4572
4249
4144
3236
3812
3487
55521
3845
1473
6794
4597
5566
2735
2660
6402
2515
3439
3772
12809
5790
10817
9729
1788
2476
4333
2940
7232
3582
8604
3742
7644
4823
6128
6737
5712
4168
4465
2183
1217
2257
6326
5966
5699
2985
2290
5190
4155
10754
9830
4507
2165
7208
4409
4256
4158
1941
3124
5852
3376
6411
5508
5072
2374
4189
4032
4957
2050
2737
6772
4468
2072
1214
6231
7077
6100
6990
5676
7474
4524
8778
7129
8151
7975
7277
8672
8097
3847
29172
7125
50466
14169
22037
4483
1801
4863
1920
2776
1407
3998
1142
2664
3920
5708
5481
5701
5159
3654
1960
4419
5933
4941
4511
1120
5179
3447
5285
3675
1333
1418
4595
4140
2353
1995
5588
1443
5681
3439
6178
5795
5144
2788
6232
2620
4665
5624
37076
7362
3885
8268
10947
9084
3016
10383
9594
16223
16281
5352
11764
10192
5248
3151
7341
8125
10671
13510
1759
7635
7021
3620
7640
4967
3662
3840
7613
3948
1820
4010
3936
7375
8060
12396
8236
5033
2739
4296
5564
6502
3501
5637
5826
5862
5579
6416
2277
2471
4325
2621
1600
4290
15494
6834
15459
10418
12560
6382
8598
1089
11386
9538
6933
3943
14268
7172
7680
15936
5695
69893
7293
4968
7862
3210
1924
4742
3519
1095
5922
6335
2405
4233
3819
7282
10018
3820
5380
9377
8889
13183
9964
4473
12469
9862
6567
4903
1198
5238
1582
1820
6080
10178
4554
6315
2818
5956
2491
5291
5056
3699
2843
1243
5430
2175
31126
5392
1590
3738
2507
2817
6963
6140
4606
2814
7044
1282
12230
1430
4283
11385
2557
6868
3871
2558
1957
4058
1935
5738
1513
5744
4130
3321
3760
4155
1063
3694
67474
2215
8962
5442
7390
6223
3648
2390
5464
5125
3842
2131
3414
6085
3353
3660
1593
4395
2664
4987
2352
5693
1391
1661
6017
5013
5243
3734
3116
1541
6456
2806
6143
1344
5977
5422
2326
2164
33377
5950
5168
1348
3144
5760
6974
8537
6664
1248
9040
4510
5642
8547
9407
5058
6158
7726
6731
4182
5246
2686
4196
3809
3253
3260
3162
2703
6373
6136
2904
6356
5038
3368
11040
5793
13747
10478
5166
11697
10072
8434
5732
5244
6374
1877
2902
4263
4835
2283
2086
6044
6343
6232
2849
3694
6392
13062
12405
12869
16366
1652
8036
1720
7759
13661
1370
3505
5885
1708
10440
7438
11480
4904
8387
4788
10326
6143
11063
9649
9384
5849
1935
7411
4694
4435
1321
5301
2096
2422
5484
6560
3070
5008
5405
9444
6355
13150
12686
1618
5831
1957
1288
1382
2946
1926
1828
1646
4823
3637
1309
5727
4450
66234
4016
4075
4551
5869
2866
2461
1055
4712
7220
1973
4650
2387
1102
4558
2290
1969
3624
2383
4059
4877
3439
6891
3819
5824
3440
11447
5522
16700
8373
1356
7249
8484
6767
7990
8778
2235
5995
8511
5466
6088
2583
5235
6093
3089
1570
6112
3668
2187
5582
1380
4800
5529
2987
12323
4775
11105
3805
7671
6737
3197
1256
4539
6383
1476
2134
6785
7337
1229
4965
5055
13128
8149
4426
8087
2873
1695
8214
7147
7216
1070
2801
5033
8103
7750
5749
4082
1630
1958
6113
4486
2111
1486
6451
5630
5682
4558
10475
30751
5397
5067
1178
2106
5557
4847
1661
3469
4908
2590
4686
2118
4495
2994
12590
12902
8742
15433
2777
7451
8722
7302
2269
9592
6162
1907
6741
4442
6526
8289
7479
9481
1642
4982
2001
12803
7255
13545
10713
14621
25826
20771
1055
8331
7422
8400
2208
6688
8425
6883
4192
4725
9970
10127
2777
3933
9274
3791
9906
2779
1118
2823
1563
9917
6065
1863
1885
5053
1922
5356
8266
7335
4260
8730
7307
3140
4340
1080
2120
5498
6769
6170
2944
4677
1155
4676
2420
4945
5941
14838
3844
19712
16283
1906
3672
4274
6550
6072
5299
4493
3348
2804
3747
3208
5359
59156
6128
5959
12262
12166
4945
9635
8095
1757
13656
7215
2545
6298
7873
6515
6407
4182
4911
3966
1942
7281
5082
7446
5545
3876
5618
4226
4445
3915
1250
5469
3872
5157
5539
2894
1357
1419
4214
3009
3364
6618
1432
7583
6192
2529
2076
6231
7333
5028
2989
3801
1895
2367
5747
2724
1304
3085
2524
1295
1022
2613
4239
4413
3418
23885
3895
3302
1097
3150
1379
1815
1484
2074
2616
3395
6100
5488
1006
3046
1951
8238
6010
3652
6640
7990
3900
8191
6978
3025
1966
7152
5963
7326
1866
2507
4764
1434
3194
3326
3081
6828
6495
3257
4236
4938
7090
2826
6614
1341
7098
6771
18885
3826
13103
1193
16653
13676
19294
13878
7460
4327
7335
4898
6259
7941
5940
5603
3095
5674
2886
8680
4662
8044
8210
5886
9057
7917
3258
5995
2800
31568
5423
33845
8988
13780
9059
14650
9824
10327
13747
10937
4594
6882
2696
2860
1070
1662
6098
2369
2821
3603
3593
5347
4871
4967
2211
3330
5226
8520
1896
1906
5172
6845
1565
6366
5509
5068
4047
4661
2384
1904
4705
5402
6650
6120
4834
5897
6492
6200
5868
4130
1530
9654
9306
8529
2508
8918
4040
3717
3245
4195
11698
10053
6635
4749
12283
11894
8168
6418
7151
4827
2391
8643
2315
8664
3547
6900
4418
65083
5164
1748
8739
4945
2604
5493
5310
3763
6011
4091
4342
2566
6021
4067
1385
2486
4444
1713
3380
4253
4720
1602
4814
3234
1739
13603
22634
7845
4139
8832
7441
1967
6707
7981
3416
10633
4808
9206
6975
4257
6024
5176
10639
9329
5010
7215
4522
8168
9936
9792
4326
4601
6508
2501
3866
3060
2188
6429
1014
1383
6937
5313
4392
8977
2420
1013
4267
9689
2955
5583
2947
5570
5067
1139
4531
3001
7698
2028
8025
1424
6837
1357
2186
5433
19739
5321
5019
4714
2688
5290
1593
1320
1703
2978
1476
3034
3538
2825
5819
5547
6441
1104
3128
7940
5977
8434
4493
2139
1617
4933
3219
3273
12383
6076
11222
5523
8875
1005
4958
3234
3196
5527
9875
7306
1591
6031
2124
1224
7008
2559
4540
7670
5927
4323
5630
1067
5482
1939
5428
3416
3494
2469
4287
5538
1190
4234
1734
10808
15234
14069
10497
7697
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
SHAPE2POINTS = {
'X': 1,
'Y': 2,
'Z': 3,
'A': 1,
'B': 2,
'C': 3
}
def load_input():
data = list()
with open('input') as fd:
data = list()
for line in fd:
line = line.strip()
data.append(list(map(lambda x: SHAPE2POINTS[x], line.split())))
return data
def get_result_task1(rd):
result = 0
if rd[0] == rd[1]:
result = 3
elif (rd[0] == 1 and rd[1] == 3) or (rd[0] == 2 and rd[1] == 1) or \
(rd[0] == 3 and rd[1] == 2):
result = 0
else:
result = 6
result += rd[1]
return result
def get_result_task2(rd):
if rd[1] == 2:
return rd[0] + 3
elif rd[1] == 1:
shape = rd[0] - 1 if rd[0] - 1 != 0 else 3
return shape
else:
shape = rd[0] + 1 if rd[0] + 1 != 4 else 1
return shape + 6
def main():
data = load_input()
# Task 1
score = 0
for rd in data:
score += get_result_task1(rd)
result = score
print("Result 1: ", result)
# Task 2
score = 0
for rd in data:
score += get_result_task2(rd)
result = score
print("Result 2: ", result)
if __name__ == '__main__':
main()
B X
B Y
A Y
B Y
B Y
A Y
A X
A Y
C X
A Y
A Y
B Y
B Z
A Y
B Z
B Z
B Z
B Y
A Z
A Y
B X
A Z
A Z
A Z
B Z
A Y
A Z
C X
B Z
A Y
B Z
B Y
A Y
A Y
A Y
A Y
A Z
C X
C Z
A Y
A Y
A X
C X
B Z
B Y
B Y
A Y
C X
A Y
B Z
B Z
A Y
B Y
B Z
A Y
C X
B Y
A Y
A Y
A Y
A Y
B Z
B X
A Y
B Y
A Z
B Y
A Y
C X
A Z
C Z
B Z
B Y
A Y
A Y
B Z
B Y
B Y
B Y
B Z
A X
A Y
A Y
B Z
C X
A Y
B Y
C Z
A Y
C Y
A Y
A Y
C X
A X
A Z
A Y
B Z
A Z
B Z
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
B Y
C X
A Y
A X
A Z
A Y
B Z
C Y
C X
B Y
B Z
A Y
B Y
B Z
A Y
A Y
B Y
B Z
B Y
A Y
B X
A X
A Y
B Y
A Y
A Y
A Y
B Y
A Y
B Y
A X
C X
A Y
A Y
B Y
B Y
B Y
C Y
C X
B Z
B X
A Z
B Y
A X
B Y
B Z
B Z
A Y
B Y
A X
B Y
C X
B Z
A X
A Y
B Y
B Z
A Y
B X
A Y
A Y
C Z
C Z
C Y
A Y
B Z
A Y
A X
A Y
A Y
C X
B X
A X
A Y
B Z
B Y
B Z
B Y
C Y
B Z
B Y
B Y
A Y
B Z
B Z
B Y
B Z
B Z
B X
C X
A Y
A Y
B X
C X
B Z
B Y
A Y
B Y
B Z
A Y
B Y
B Y
B Z
A X
B Y
B Z
B Z
A Y
B Z
B Z
B Z
C X
C X
B Z
B Y
B Y
B Z
B X
B Y
C Y
A Y
A X
A Y
A Z
C X
A Z
B Z
A Y
B Y
A Y
B Y
A X
B Y
B X
A X
C Z
A X
A Y
A Y
C Y
B Y
A X
A X
B Y
C Y
B Z
B Z
B Y
A Y
A X
A Y
A Y
A Z
A X
A Y
A Y
A Y
B Z
C X
A X
C X
A Y
A Y
B Y
B Y
A X
B Y
C Y
B Y
A Z
B Y
B Z
C X
A X
B Y
A Z
B Z
B Y
B Y
B Y
B Z
B Y
B Y
B Y
A X
A Y
B Z
C X
A Y
A Y
B Y
B Z
C X
A X
A Y
B X
B Y
A Y
A Z
A X
A Z
A Y
C Z
A Y
B Y
B Y
B Z
C X
B Z
A Z
B Y
B Z
B Y
A Y
A Y
C Z
A Y
B Z
B Y
B Y
A X
B Y
A Y
B Y
A Y
A Y
C X
A Y
B Y
A Y
C X
B X
A Y
B Z
A Y
A Y
C Z
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
import string
def load_input():
data = list()
with open('input') as fd:
data = list()
for line in fd:
line = line.strip()
data.append(line)
return data
def get_priority(char):
return string.ascii_letters.index(char) + 1
def main():
data = load_input()
# Task 1
result = 0
for rucksack in data:
length = int(len(rucksack)/2)
common = set(rucksack[0:length]).intersection(set(rucksack[length:]))
result += sum(list(map(lambda x: get_priority(x), common)))
print("Result 1: ", result)
# Task 2
chars = set()
result = 0
for i, rucksack in enumerate(data):
if i % 3 == 0:
chars = set(rucksack)
else:
chars.intersection_update(rucksack)
if i % 3 == 2:
result += sum(list(map(lambda x: get_priority(x), chars)))
print("Result 2: ", result)
if __name__ == '__main__':
main()
WwcsbsWwspmFTGVV
RHtMDHdSMnDBGMSDvnvDjtmpTpjTFggpmjmTFggTjmpP
vtCSGRMBDzHddvBHBzRhrlcZhlLzWNlqblhzcr
shhszHNHHZWqSzVNdClMjlFjBBbNTB
tQQGmnrMnJnGfmvrRRPCjlbljFBdjFCjTjnP
mRwtfGrMmJtwRDvQJQrJpMLSzVDHzhzHZqZzqSzcWVWH
WsWWgrtgsrhTQtsFcWPcRMCCTvqvMvqNNqMMHlMq
bBJrBGbzzLJznJrbSDGGJLqmlvqMqvlmLHRqRZZRNZ
bzJfDGVSzVrJGwjVGPPpQthdPsPpjdphsc
pJpCCBSWlczWWBWMHdMmMsFmpddrgF
wfVqZZGVQvzsMqmMgHjm
vDZGvPttQTVtGDQDDDGwbSCcSJSCJWTcRRSRczRJ
HLVHsVWLwbWswbpWFWrrmThfTPNnhNSDDNhDfznTnhnS
pBRcvGvvBtpGcqqQvgcphPfzfDGhzdzPDzDDhnhS
ZQRvqBptjJgZCtJqqMMMLHWwMWZWHHFFHm
PvPFPvLLLSvNFvQNWNPvrPLrZjwhMttTwtTtQZBwqjqtZqwM
HJDDbHjgppzCDCmzpgzsGbCsTMZqZllqhJBhMTtVBBhMtMth
zgGncmGGzHCnHDpDgDCGsmFLLPFjPRRWLRjdcjrcdRLd
zHnWzntnBRWTSBzRBddpFvZVcHpLFvjvLppvHP
MmmWmNGQhbCpZVLLbccvpj
QDMCGrNWfwNznBJsJzDBdg
tcRcZccZmdZJctRcjrlhNNDfrdNdSfNsNT
QHQpBV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ZzzTgWjdzDjzb
ZhNLMrNcGrchLqcCVMqRvlSnFnRnmmGRggnPnP
HMCMCMrHfwMHtFwTtgHHbVjjbsRZDwDVRbZqjhBD
cDpmpdpNLNDcdZjZqZBNBqssRR
SLJSdPcznSvdvDcHFCftFTFWCTHnWt
NlMmlPClmdGldRZHJs
tgJJcJQcntHBsnBt
TfSgQhhccczSVQqrgSgTjFWqLWmwLFNJLWWPPwqM
GGwTHqWVdnTTVVqgngzzqHzGFbJspFccRsjDpDcjsRFDsdjR
rtLflllZSrhQPLBtQStZvhjDNjbcDNDRNFjCsCDCFs
mPLBQPtvtQZtBlLSmMqVGwHbVMqTHWmz
VvJCrqTvPvQrCpRNVRFGfZfmfG
HMzsdWsjhZSsJJZNZf
wHlbjnlzWCvqJBQlrD
FnVRRsVdSnSnFSRqTVdqBBDBhrDdmcddMcMQMhzm
HtZvJwHlgjlGlHJLNjJrMmrcmDQfDLczDrMhhh
vGGpJjttvlZljZllZvJZvwGqsSTRWSCpnCWTVPVmWWTWWn
wSHCNwwmcSMLSDFcwwSSHQvZnQjLZffZjZZbVZjVVb
JqsNJJGGqprJNtpWhGhspfnffTnTvZvVbZnTrfBQvV
GsWhdGtPWpghJRqhtNPmClczSlDglHMlczmwCH
TzRpjVRjFpVLTTdgrTgrGsZwrZZwgg
vQfSBdbDbMbQNBJrlhmGnrgrgwZhvm
SHSCbdbddcVWqqFPCLqR
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:
data = list()
for line in fd:
temp = list()
for values in line.strip().split(','):
temp.append(list(map(lambda x: int(x), values.split('-'))))
data.append(temp)
return data
def main():
data = load_input()
# Task 1
fully_contains = 0
for a, b in data:
if a[0] <= b[0] and a[1] >= b[1]:
fully_contains += 1
elif a[0] >= b[0] and a[1] <= b[1]:
fully_contains += 1
else:
pass
result = fully_contains
print("Result 1: ", result)
# Task 2
non_overlaps = 0
for a, b in data:
if a[1] < b[0] or a[0] > b[1]:
non_overlaps += 1
result = len(data) - non_overlaps
print("Result 2: ", result)
if __name__ == '__main__':
main()
57-93,9-57
55-55,55-83
55-88,78-88
24-24,24-95
7-92,8-93
25-84,84-85
62-85,62-85
66-78,65-76
28-32,31-33
24-81,2-25
45-80,79-80
75-99,75-91
24-49,23-24
22-69,49-69
15-77,76-78
25-50,21-50
29-77,29-64
47-93,46-48
37-42,70-97
5-95,4-6
37-90,74-95
17-48,18-85
2-97,1-89
2-48,1-48
52-70,42-71
17-90,90-94
76-77,2-76
10-89,10-96
40-52,39-53
9-97,8-96
6-74,5-6
3-89,2-89
35-63,62-79
13-39,18-39
45-81,4-46
8-76,39-67
3-76,1-4
1-96,1-1
11-59,58-60
41-53,25-42
5-54,11-93
15-91,95-95
62-62,2-63
11-41,40-42
52-98,51-53
29-52,47-51
15-86,16-86
13-98,28-99
8-13,14-54
47-61,64-95
27-95,10-76
9-27,10-10
23-89,24-24
98-98,15-99
8-92,92-96
2-38,27-87
22-64,20-63
1-6,5-66
23-49,9-48
63-64,35-63
6-7,7-81
23-91,22-92
32-97,33-69
21-24,20-25
35-42,34-43
82-82,15-83
23-34,20-34
37-92,37-86
35-94,30-36
48-52,51-53
7-74,3-73
41-43,42-86
2-5,5-91
98-99,8-98
68-86,67-67
37-54,36-37
3-95,2-96
50-79,25-78
12-71,11-72
91-92,74-91
10-43,9-44
30-93,2-91
20-44,20-54
36-84,35-85
75-76,75-75
54-54,18-55
36-91,14-39
8-25,8-25
16-97,4-96
7-83,2-8
4-4,4-71
1-98,1-98
87-87,33-88
22-88,21-88
8-94,9-89
99-99,5-96
63-92,63-92
42-68,10-69
18-96,19-19
16-90,16-90
9-93,8-94
48-88,87-89
3-68,67-98
72-93,97-98
11-99,11-99
3-99,2-99
83-87,79-86
14-14,5-14
1-2,1-92
9-90,91-94
53-85,84-84
11-89,3-11
13-33,32-86
40-74,74-91
68-71,69-86
17-51,18-51
47-90,47-90
2-3,3-85
7-97,8-75
21-29,28-75
87-93,53-93
49-74,27-95
56-65,55-97
14-16,15-81
7-7,8-71
24-26,23-82
34-56,50-55
10-97,11-96
52-70,16-69
20-56,20-21
27-96,96-97
23-98,15-24
24-72,86-98
44-77,60-88
6-98,5-99
1-96,99-99
8-95,99-99
10-81,4-62
88-88,69-89
30-67,29-68
14-96,15-96
58-86,73-86
7-55,14-54
3-97,62-98
11-86,9-87
41-79,16-41
2-99,1-96
7-56,5-7
25-61,24-62
25-83,26-82
20-82,7-12
36-58,41-58
98-98,16-89
98-99,86-99
18-50,18-93
44-67,40-48
46-90,47-91
21-49,48-66
2-90,89-94
12-25,13-25
5-9,6-44
68-75,70-76
25-99,26-99
95-95,17-96
13-14,13-90
79-99,76-77
87-88,88-89
77-77,6-78
36-92,35-35
10-11,9-9
9-37,8-38
80-91,81-81
17-97,17-99
4-19,18-71
35-92,8-91
30-31,22-30
19-19,18-47
51-79,52-55
4-8,7-77
3-98,3-99
68-76,67-68
86-86,74-93
20-86,35-86
8-98,7-98
56-58,14-63
41-47,42-47
16-89,41-88
21-22,22-52
2-62,3-33
3-83,3-3
87-94,25-86
80-95,95-98
7-57,8-58
3-24,23-23
5-43,2-4
32-85,86-86
39-82,38-83
73-87,21-79
86-94,39-87
87-88,4-87
41-65,48-60
40-70,62-70
3-44,2-43
3-19,19-98
65-98,66-98
79-84,80-83
93-97,91-98
21-96,21-96
30-77,31-83
5-82,2-5
10-82,9-10
84-94,47-50
26-93,27-39
47-95,77-90
30-33,33-81
45-73,46-72
12-59,12-59
31-60,31-59
23-76,39-75
66-88,80-93
58-76,2-75
9-56,36-55
2-94,2-94
75-81,72-80
9-46,10-41
7-93,6-6
99-99,43-97
33-83,33-83
20-85,84-84
61-76,60-94
16-75,17-75
16-18,17-71
6-88,7-35
38-79,6-38
9-42,8-10
18-60,86-95
3-3,2-98
2-99,3-99
78-82,79-82
34-75,23-76
3-12,3-4
16-95,20-95
81-85,66-75
8-87,15-61
37-58,37-37
2-87,1-86
49-89,48-84
56-58,57-88
77-79,3-78
25-92,25-98
14-73,73-74
15-17,1-16
41-84,1-84
34-64,6-63
86-88,28-87
2-87,2-87
68-76,34-69
42-78,54-83
7-92,2-24
2-12,1-11
72-83,64-82
49-93,48-92
31-32,32-59
4-90,4-86
2-65,71-83
21-88,14-78
5-92,93-94
1-10,2-9
40-66,39-40
47-77,46-46
2-99,25-99
37-95,37-95
60-64,60-64
32-51,33-51
22-90,11-88
13-54,12-54
67-77,16-72
7-37,9-90
2-54,53-53
5-5,6-68
8-9,9-31
4-39,40-61
5-95,6-95
1-11,11-95
30-70,30-70
58-58,59-97
11-41,12-44
2-6,1-7
10-58,10-64
3-95,1-3
23-55,8-23
37-60,52-59
6-46,6-47
8-45,27-53
12-95,94-94
43-52,43-44
9-95,10-94
2-9,5-26
5-8,9-97
2-60,3-60
87-89,45-88
5-9,9-90
47-91,45-47
39-47,27-39
16-72,16-34
89-90,35-89
18-93,8-17
4-35,9-71
64-96,27-62
30-68,7-30
25-70,3-26
41-77,40-77
87-97,24-97
2-97,97-98
41-50,49-67
49-53,50-80
18-18,19-87
36-39,37-40
4-83,27-93
28-92,29-91
33-93,93-94
2-94,2-94
26-65,25-26
5-14,15-27
19-49,19-49
56-56,2-55
79-79,49-80
79-80,55-80
61-82,17-62
61-63,1-62
20-92,32-73
57-57,5-58
19-37,20-20
13-75,75-76
61-99,62-99
19-92,19-91
34-68,35-35
4-76,91-99
30-71,71-72
51-95,28-51
64-70,51-75
28-90,89-91
70-85,42-83
2-91,5-80
45-53,17-52
70-80,20-69
29-88,30-89
5-5,5-89
30-30,30-77
20-71,21-40
11-44,18-43
6-90,6-90
1-98,97-99
3-98,3-98
9-42,24-42
75-75,73-76
20-87,86-88
62-86,63-91
15-61,14-16
46-58,45-58
2-53,47-54
3-89,3-35
3-99,1-78
50-80,9-81
96-98,69-97
6-78,6-78
19-77,18-77
17-75,18-75
54-73,53-73
92-97,73-85
5-76,77-77
43-93,18-94
7-8,8-92
49-87,50-88
34-56,35-57
25-98,24-26
11-93,12-94
68-99,67-67
5-8,9-55
8-83,4-43
52-84,51-53
4-96,3-71
6-94,6-99
19-67,18-68
1-91,2-96
24-35,36-54
13-96,13-99
19-47,32-36
10-62,6-61
3-4,4-98
42-43,43-76
17-58,54-58
57-77,12-77
78-99,25-77
3-91,1-90
13-28,29-83
60-88,23-59
78-95,79-95
16-97,16-17
14-71,12-70
1-99,2-99
11-84,5-11
55-80,55-80
28-67,68-68
60-81,60-81
7-74,7-74
3-68,2-4
5-70,6-70
4-92,30-93
44-79,43-99
31-70,4-98
2-93,1-93
6-95,5-5
16-36,5-36
13-14,13-31
53-84,54-73
41-75,74-91
31-90,48-91
25-93,19-93
9-95,6-9
27-89,25-28
19-86,18-73
11-62,10-11
73-75,23-75
19-90,18-96
5-5,4-51
16-98,42-52
11-81,12-82
65-95,66-95
61-61,61-82
68-74,73-78
31-42,1-32
7-97,7-96
58-59,42-58
99-99,13-92
63-94,20-95
17-38,8-18
60-71,15-52
75-90,9-76
14-99,13-98
9-16,16-81
54-83,54-90
18-18,18-53
16-64,15-16
19-60,18-19
2-90,1-91
79-79,79-98
32-58,31-33
60-65,59-65
13-34,13-34
6-34,33-33
59-64,58-84
13-13,13-71
4-76,3-82
77-86,60-75
63-96,52-95
4-68,3-5
21-45,5-21
11-81,10-12
1-97,96-96
25-78,26-79
17-38,20-48
61-62,62-90
16-99,16-99
12-66,42-65
3-85,2-84
6-47,7-46
3-76,4-85
10-44,11-72
12-47,47-48
47-84,48-84
43-99,24-77
21-44,21-25
75-85,44-84
86-97,32-86
24-92,23-88
86-88,49-87
96-96,2-79
90-95,17-95
11-88,10-89
3-59,1-4
10-56,11-83
46-94,47-94
3-98,98-99
34-86,34-94
9-17,11-16
89-93,21-90
15-98,15-98
32-84,33-85
46-46,45-80
5-69,70-93
8-99,9-98
4-99,5-95
1-35,2-67
1-99,2-98
11-22,14-22
32-95,33-94
48-77,72-77
28-30,22-29
35-86,36-86
56-60,55-60
44-75,44-59
85-91,8-86
21-22,21-59
96-97,8-60
7-50,51-85
32-98,33-33
11-12,11-81
6-7,6-39
32-68,33-69
19-46,18-50
45-96,45-49
1-13,4-94
86-87,14-87
15-15,16-93
29-48,28-28
89-97,90-98
6-59,7-60
13-13,13-64
21-64,81-95
17-34,18-33
3-87,86-90
4-84,2-38
40-76,39-76
17-84,18-85
66-96,25-65
16-97,16-96
64-65,4-66
53-66,10-86
15-78,16-77
75-76,54-75
4-98,20-97
22-75,23-62
42-89,42-89
70-71,69-70
18-90,19-89
40-68,67-69
7-73,6-7
86-95,96-97
40-58,39-72
1-43,5-28
10-60,5-49
30-81,29-91
7-77,8-11
8-65,9-65
3-57,4-11
1-2,2-96
56-58,41-57
34-89,83-90
59-97,58-98
29-30,28-30
54-82,31-57
4-99,98-98
14-36,34-39
88-97,3-98
16-53,17-99
39-39,39-72
39-61,62-80
20-32,31-43
49-70,50-70
65-75,34-66
1-99,1-2
57-90,56-94
28-62,33-62
21-21,22-96
18-65,17-88
93-97,60-94
74-93,92-94
9-18,17-77
46-89,30-45
17-97,16-98
2-99,98-98
11-21,12-20
99-99,4-96
36-48,35-44
70-74,63-81
40-41,40-92
2-94,22-93
67-73,60-78
29-30,22-29
65-99,65-99
7-20,6-21
29-99,30-99
40-98,86-99
20-37,21-53
86-86,7-87
25-39,30-93
55-78,56-88
5-15,6-7
16-17,2-16
71-72,72-83
9-21,8-21
5-44,3-26
77-77,12-84
15-16,16-53
44-69,43-69
6-84,5-5
34-77,33-77
15-78,15-97
28-86,15-29
47-96,46-46
57-59,21-58
2-91,4-92
11-14,13-75
45-46,45-99
26-57,24-26
4-95,67-98
15-54,15-15
41-44,19-42
19-20,19-98
16-86,15-86
13-47,46-82
13-50,12-14
11-98,6-89
44-89,45-99
7-82,82-83
24-61,24-24
23-60,23-59
10-86,9-10
74-86,73-74
1-41,5-82
3-4,4-84
94-98,19-83
2-97,93-96
89-91,45-90
7-12,11-94
52-60,46-51
3-3,2-85
35-43,42-66
29-92,28-92
20-21,21-96
91-91,90-91
8-34,8-21
8-95,95-96
4-81,44-82
2-84,1-2
11-88,11-11
17-69,16-70
12-76,11-12
13-64,66-75
38-68,69-85
86-86,85-91
10-87,11-97
10-78,36-77
8-68,7-68
4-87,3-87
62-64,12-65
32-79,33-79
2-90,2-3
3-8,8-26
63-64,63-70
25-30,7-30
3-92,3-92
4-98,3-99
2-3,2-43
43-65,43-85
17-62,91-94
88-90,48-89
13-96,1-96
44-71,44-93
66-71,70-72
28-63,27-62
19-19,20-99
23-23,24-93
27-84,28-85
77-82,21-78
40-40,24-41
88-89,6-88
1-97,96-98
1-88,2-42
12-39,12-13
47-62,61-65
3-97,7-96
30-66,29-67
71-90,72-78
98-98,6-97
43-43,43-48
36-99,35-95
30-93,30-99
5-28,6-11
3-22,2-96
9-87,8-71
41-79,27-69
6-99,7-98
99-99,45-76
97-99,14-96
6-39,7-92
5-49,13-64
6-41,4-41
93-98,16-94
8-98,25-97
41-64,41-42
5-87,5-6
12-68,13-67
24-75,24-75
41-42,5-41
16-92,13-49
16-31,27-96
27-79,78-78
32-71,33-72
23-24,24-96
4-4,4-78
85-91,40-91
6-10,9-75
38-69,39-69
8-8,8-74
7-40,1-7
33-88,34-88
32-92,33-92
7-19,6-64
21-22,21-22
7-8,7-99
4-48,5-47
27-27,26-61
77-85,76-86
22-39,29-40
4-42,5-63
85-87,43-79
8-88,7-9
55-90,54-90
7-98,6-8
6-85,7-84
18-56,5-19
54-81,42-50
7-27,28-40
96-98,81-97
52-74,52-53
61-64,20-63
45-92,45-60
18-89,19-89
9-51,8-52
19-19,20-95
49-99,49-99
17-78,16-16
20-95,20-21
11-94,96-99
38-57,56-58
94-97,18-90
38-42,10-53
67-86,68-86
2-96,2-91
33-77,33-89
25-26,25-51
86-98,16-97
2-71,2-71
28-29,6-28
30-83,31-84
13-85,13-84
23-61,22-48
32-74,74-92
41-53,10-94
15-89,20-90
25-69,25-25
1-96,1-96
7-96,6-96
1-98,2-2
47-47,11-48
35-94,93-95
67-69,68-77
43-63,44-64
14-94,15-49
7-95,6-96
15-40,41-41
8-83,82-90
66-75,11-67
40-52,45-51
20-57,7-20
4-87,3-87
97-97,56-95
45-45,45-45
58-96,9-95
33-45,44-44
6-26,16-26
46-59,47-60
24-40,23-40
6-91,94-98
40-93,20-84
32-42,41-42
2-94,3-93
59-59,2-60
7-40,3-7
47-89,88-88
35-66,65-67
84-99,52-85
75-99,75-96
8-21,7-8
3-53,4-52
22-62,22-62
72-72,73-78
39-72,38-96
2-14,1-91
4-98,5-76
8-88,7-13
5-6,5-99
20-90,19-90
26-29,27-34
52-69,53-95
56-56,50-57
23-79,22-79
16-93,16-78
13-76,55-92
36-70,35-70
43-81,40-80
4-94,95-99
1-94,1-94
48-84,47-49
32-93,31-92
11-19,18-77
62-80,39-74
62-63,62-96
3-94,93-95
15-66,16-66
23-95,22-88
57-57,25-58
71-86,3-72
2-79,7-78
47-49,13-48
46-94,45-45
19-77,65-76
31-37,38-87
4-79,92-99
17-19,17-19
1-82,41-89
47-91,48-49
6-19,10-37
14-42,18-39
40-79,20-61
2-84,1-31
83-95,47-84
68-71,2-69
37-73,8-72
85-86,36-85
2-9,8-78
17-59,58-68
62-90,78-90
77-94,41-93
11-90,12-94
34-79,33-97
42-56,22-57
38-44,44-45
1-84,98-98
63-74,61-73
28-57,4-58
48-48,47-90
37-38,38-77
72-84,72-72
3-47,47-47
50-91,25-59
5-38,4-38
24-86,23-55
55-74,50-75
33-83,34-83
1-91,73-88
13-13,14-85
54-94,60-99
21-85,84-86
12-98,8-36
89-98,4-90
4-15,8-15
98-98,1-99
21-79,20-78
2-63,62-63
78-80,63-79
24-68,67-86
24-25,25-47
53-68,4-55
11-82,10-82
23-92,5-99
94-99,67-88
11-51,32-86
49-79,24-48
22-73,91-99
4-9,8-89
23-85,23-54
5-86,6-13
13-14,14-94
72-81,73-82
56-98,55-98
3-96,2-96
88-88,20-89
78-79,79-85
29-94,20-30
8-43,85-90
96-98,7-71
45-74,70-71
23-79,94-94
41-97,40-97
73-96,72-72
4-28,4-65
89-98,20-90
37-70,37-98
26-36,26-35
41-41,7-42
7-22,21-90
12-84,13-75
98-98,1-99
47-75,74-87
7-33,33-90
41-68,41-87
64-92,65-88
41-54,10-42
6-89,93-96
20-48,1-21
8-91,8-8
11-95,10-97
72-98,31-90
44-45,33-44
54-56,18-55
7-9,10-88
44-45,45-90
52-56,54-83
68-70,1-69
91-92,91-92
13-74,14-75
4-60,61-91
9-94,10-95
9-95,9-10
50-61,49-68
50-50,5-51
38-46,43-43
4-11,12-22
42-42,43-96
77-91,48-76
23-89,24-94
9-65,10-15
53-81,7-73
8-28,22-37
76-95,31-77
9-84,3-84
12-98,13-99
17-74,17-78
60-89,59-89
1-15,2-14
14-91,13-88
87-97,42-96
77-77,73-76
16-77,15-69
80-95,81-96
40-73,41-90
47-63,46-62
5-98,4-97
46-93,42-92
15-30,7-23
7-90,91-95
1-99,1-2
5-97,4-99
81-87,8-28
56-69,24-68
87-89,20-88
78-99,1-98
32-97,33-97
19-20,20-33
77-78,21-78
2-6,5-42
35-36,35-44
2-83,82-84
48-97,49-58
36-53,53-75
5-92,4-93
49-85,50-86
45-81,43-82
3-97,1-43
97-98,58-97
6-88,3-88
4-67,5-66
43-88,32-44
95-95,13-96
4-54,13-97
1-45,3-45
2-9,8-98
1-12,1-53
13-98,14-84
85-99,86-99
4-16,3-16
15-77,14-15
18-67,67-68
34-69,33-70
97-97,9-92
76-84,58-77
76-84,42-55
96-98,2-97
50-98,51-72
54-94,53-94
23-91,23-91
21-94,22-95
41-89,42-89
48-78,47-78
18-51,51-76
5-49,1-34
40-55,40-47
41-96,41-97
8-10,9-94
74-79,66-80
6-15,15-91
10-99,9-99
12-92,12-96
32-96,20-33
5-67,1-66
21-90,31-94
22-23,22-60
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
def load_input():
number_list = 9
data = list()
commands = list()
pattern = re.compile('move (\d+) from (\d+) to (\d+)')
with open('input') as fd:
data = [deque() for _ in range(number_list)]
section = 0
for line in fd:
if section == 0:
if line[1] == '1':
section = 1
continue
for i in range(number_list):
pos = 4*i+1
if pos < len(line):
char = line[pos]
if char != ' ':
data[i].appendleft(char)
else:
break
elif section == 1:
section = 2
else:
line = line.strip()
match = pattern.search(line)
commands.append([int(match.group(1)), int(match.group(2))-1, int(match.group(3))-1])
return data, commands
def main():
data, commands = load_input()
# Task 1
for command in commands:
for _ in range(command[0]):
temp = data[command[1]].pop()
data[command[2]].append(temp)
result = "".join([char[-1] for char in data])
print("Result 1: ", result)
# Task 2
data, commands = load_input()
for command in commands:
temp = deque()
for _ in range(command[0]):
temp.appendleft(data[command[1]].pop())
data[command[2]].extend(temp)
result = "".join([char[-1] for char in data])
print("Result 2: ", result)
if __name__ == '__main__':
main()
[F] [Q] [Q]
[B] [Q] [V] [D] [S]
[S] [P] [T] [R] [M] [D]
[J] [V] [W] [M] [F] [J] [J]
[Z] [G] [S] [W] [N] [D] [R] [T]
[V] [M] [B] [G] [S] [C] [T] [V] [S]
[D] [S] [L] [J] [L] [G] [G] [F] [R]
[G] [Z] [C] [H] [C] [R] [H] [P] [D]
1 2 3 4 5 6 7 8 9
move 3 from 5 to 2
move 3 from 8 to 4
move 7 from 7 to 3
move 14 from 3 to 9
move 8 from 4 to 1
move 1 from 7 to 5
move 2 from 6 to 4
move 4 from 5 to 7
move 1 from 3 to 6
move 3 from 4 to 3
move 1 from 4 to 1
move 5 from 1 to 9
move 1 from 4 to 6
move 4 from 7 to 4
move 15 from 9 to 2
move 7 from 1 to 6
move 3 from 3 to 5
move 1 from 4 to 9
move 2 from 5 to 3
move 2 from 4 to 9
move 4 from 1 to 6
move 1 from 3 to 1
move 1 from 3 to 2
move 4 from 6 to 3
move 24 from 2 to 8
move 4 from 9 to 8
move 1 from 1 to 3
move 2 from 5 to 4
move 1 from 2 to 4
move 19 from 8 to 1
move 5 from 3 to 9
move 8 from 1 to 3
move 3 from 4 to 1
move 6 from 9 to 5
move 2 from 3 to 4
move 1 from 8 to 5
move 2 from 4 to 6
move 11 from 6 to 1
move 8 from 8 to 7
move 1 from 6 to 5
move 13 from 1 to 3
move 1 from 1 to 7
move 2 from 7 to 8
move 5 from 7 to 1
move 2 from 8 to 4
move 3 from 5 to 3
move 11 from 3 to 1
move 2 from 5 to 3
move 2 from 5 to 3
move 2 from 7 to 1
move 7 from 3 to 1
move 1 from 4 to 5
move 1 from 6 to 4
move 3 from 4 to 7
move 3 from 7 to 1
move 6 from 3 to 5
move 1 from 5 to 9
move 4 from 5 to 4
move 2 from 3 to 4
move 8 from 9 to 2
move 5 from 4 to 6
move 1 from 6 to 5
move 1 from 4 to 9
move 39 from 1 to 7
move 7 from 2 to 6
move 1 from 9 to 3
move 1 from 2 to 7
move 1 from 3 to 1
move 5 from 7 to 3
move 4 from 5 to 1
move 19 from 7 to 9
move 1 from 9 to 8
move 1 from 9 to 7
move 5 from 9 to 3
move 6 from 6 to 7
move 1 from 8 to 3
move 4 from 1 to 4
move 23 from 7 to 6
move 1 from 1 to 6
move 21 from 6 to 2
move 3 from 4 to 8
move 7 from 6 to 1
move 1 from 4 to 9
move 1 from 6 to 7
move 6 from 1 to 2
move 1 from 7 to 4
move 15 from 2 to 8
move 5 from 3 to 8
move 22 from 8 to 7
move 1 from 8 to 1
move 5 from 3 to 4
move 1 from 3 to 2
move 1 from 1 to 2
move 3 from 4 to 8
move 3 from 8 to 9
move 11 from 2 to 1
move 2 from 1 to 4
move 15 from 9 to 5
move 22 from 7 to 3
move 2 from 4 to 9
move 3 from 4 to 2
move 8 from 1 to 8
move 6 from 8 to 6
move 1 from 6 to 2
move 3 from 6 to 9
move 3 from 2 to 7
move 4 from 2 to 9
move 2 from 7 to 5
move 1 from 1 to 7
move 2 from 8 to 2
move 2 from 7 to 5
move 9 from 5 to 3
move 8 from 5 to 2
move 1 from 6 to 4
move 1 from 6 to 9
move 1 from 2 to 9
move 2 from 5 to 1
move 7 from 2 to 3
move 1 from 4 to 3
move 1 from 2 to 4
move 5 from 3 to 4
move 6 from 9 to 3
move 1 from 2 to 6
move 6 from 9 to 6
move 2 from 1 to 8
move 3 from 6 to 3
move 2 from 8 to 6
move 6 from 4 to 1
move 14 from 3 to 9
move 1 from 6 to 4
move 3 from 3 to 9
move 1 from 4 to 5
move 10 from 9 to 6
move 6 from 6 to 7
move 2 from 1 to 8
move 1 from 8 to 6
move 16 from 3 to 2
move 1 from 8 to 1
move 1 from 7 to 1
move 7 from 3 to 4
move 1 from 6 to 5
move 4 from 2 to 3
move 5 from 4 to 9
move 2 from 4 to 5
move 4 from 7 to 4
move 5 from 9 to 6
move 2 from 5 to 4
move 11 from 6 to 7
move 1 from 6 to 8
move 5 from 1 to 5
move 2 from 6 to 4
move 7 from 7 to 3
move 1 from 8 to 6
move 2 from 7 to 3
move 1 from 1 to 3
move 3 from 2 to 8
move 9 from 2 to 5
move 1 from 6 to 1
move 1 from 4 to 8
move 7 from 4 to 7
move 8 from 5 to 6
move 1 from 7 to 2
move 1 from 7 to 4
move 3 from 7 to 8
move 1 from 2 to 3
move 1 from 1 to 2
move 1 from 1 to 7
move 3 from 7 to 6
move 11 from 6 to 2
move 4 from 8 to 7
move 2 from 8 to 7
move 15 from 3 to 2
move 7 from 9 to 4
move 3 from 3 to 2
move 4 from 4 to 7
move 5 from 7 to 3
move 3 from 4 to 6
move 3 from 6 to 9
move 1 from 4 to 2
move 1 from 8 to 1
move 2 from 3 to 7
move 2 from 3 to 7
move 23 from 2 to 5
move 1 from 9 to 1
move 1 from 7 to 9
move 1 from 1 to 8
move 8 from 7 to 1
move 1 from 8 to 4
move 1 from 4 to 2
move 3 from 9 to 8
move 1 from 7 to 9
move 22 from 5 to 9
move 1 from 8 to 5
move 1 from 7 to 4
move 1 from 4 to 5
move 1 from 8 to 3
move 2 from 9 to 3
move 5 from 5 to 2
move 5 from 5 to 4
move 3 from 2 to 7
move 1 from 7 to 3
move 6 from 1 to 7
move 4 from 3 to 1
move 6 from 2 to 8
move 1 from 5 to 6
move 2 from 8 to 1
move 12 from 9 to 4
move 8 from 9 to 4
move 1 from 2 to 9
move 2 from 9 to 8
move 3 from 2 to 8
move 5 from 8 to 6
move 7 from 7 to 1
move 4 from 8 to 9
move 1 from 6 to 1
move 17 from 4 to 7
move 1 from 2 to 4
move 2 from 4 to 1
move 6 from 4 to 6
move 1 from 1 to 4
move 7 from 1 to 5
move 9 from 7 to 9
move 8 from 9 to 8
move 5 from 8 to 3
move 1 from 5 to 6
move 2 from 3 to 6
move 1 from 9 to 1
move 1 from 6 to 1
move 10 from 6 to 1
move 1 from 5 to 1
move 2 from 9 to 1
move 1 from 9 to 7
move 2 from 6 to 8
move 2 from 8 to 2
move 1 from 6 to 8
move 22 from 1 to 9
move 9 from 7 to 5
move 1 from 8 to 1
move 2 from 8 to 3
move 4 from 5 to 9
move 1 from 8 to 3
move 5 from 1 to 9
move 2 from 7 to 3
move 2 from 4 to 7
move 1 from 8 to 5
move 2 from 2 to 4
move 1 from 5 to 8
move 9 from 5 to 8
move 2 from 7 to 5
move 2 from 4 to 5
move 3 from 8 to 4
move 3 from 4 to 3
move 2 from 8 to 6
move 1 from 6 to 4
move 3 from 5 to 9
move 1 from 6 to 3
move 12 from 3 to 5
move 1 from 3 to 1
move 7 from 5 to 4
move 1 from 1 to 3
move 1 from 8 to 1
move 7 from 5 to 1
move 6 from 9 to 6
move 29 from 9 to 5
move 2 from 4 to 6
move 26 from 5 to 2
move 24 from 2 to 7
move 1 from 3 to 2
move 8 from 1 to 7
move 7 from 6 to 9
move 2 from 5 to 3
move 1 from 6 to 4
move 3 from 8 to 5
move 2 from 3 to 8
move 2 from 2 to 8
move 5 from 9 to 2
move 27 from 7 to 2
move 2 from 8 to 3
move 2 from 9 to 5
move 3 from 8 to 5
move 2 from 7 to 4
move 3 from 4 to 7
move 2 from 3 to 2
move 4 from 5 to 1
move 5 from 7 to 2
move 29 from 2 to 8
move 9 from 8 to 3
move 2 from 4 to 8
move 7 from 3 to 2
move 3 from 5 to 4
move 1 from 7 to 5
move 3 from 5 to 6
move 2 from 1 to 8
move 2 from 6 to 8
move 3 from 4 to 2
move 4 from 4 to 2
move 1 from 6 to 8
move 8 from 2 to 4
move 2 from 3 to 5
move 1 from 4 to 1
move 3 from 1 to 2
move 4 from 8 to 2
move 3 from 4 to 9
move 3 from 4 to 1
move 2 from 9 to 5
move 1 from 4 to 6
move 4 from 5 to 1
move 1 from 6 to 8
move 1 from 9 to 3
move 4 from 2 to 3
move 15 from 8 to 2
move 9 from 8 to 1
move 1 from 3 to 9
move 5 from 1 to 9
move 3 from 9 to 7
move 2 from 7 to 6
move 3 from 3 to 2
move 1 from 7 to 8
move 1 from 9 to 6
move 1 from 9 to 8
move 2 from 8 to 2
move 1 from 1 to 2
move 1 from 3 to 7
move 4 from 1 to 7
move 19 from 2 to 5
move 1 from 1 to 4
move 1 from 7 to 4
move 1 from 1 to 5
move 3 from 1 to 4
move 1 from 1 to 8
move 6 from 2 to 4
move 7 from 2 to 1
move 2 from 7 to 9
move 8 from 2 to 8
move 2 from 7 to 3
move 1 from 6 to 4
move 10 from 4 to 6
move 5 from 6 to 7
move 2 from 9 to 8
move 6 from 8 to 9
move 1 from 2 to 3
move 2 from 8 to 3
move 5 from 1 to 8
move 8 from 5 to 2
move 8 from 8 to 7
move 7 from 2 to 8
move 1 from 1 to 2
move 1 from 9 to 7
move 1 from 4 to 2
move 2 from 2 to 6
move 5 from 9 to 3
move 2 from 8 to 6
move 2 from 3 to 9
move 4 from 8 to 6
move 7 from 6 to 1
move 8 from 1 to 5
move 1 from 8 to 7
move 1 from 9 to 6
move 12 from 5 to 3
move 1 from 4 to 8
move 2 from 9 to 5
move 1 from 2 to 3
move 3 from 5 to 1
move 1 from 1 to 5
move 21 from 3 to 8
move 2 from 1 to 5
move 6 from 5 to 7
move 2 from 5 to 6
move 10 from 6 to 9
move 1 from 6 to 8
move 13 from 8 to 2
move 2 from 5 to 4
move 2 from 4 to 3
move 4 from 9 to 1
move 5 from 7 to 8
move 12 from 8 to 1
move 5 from 9 to 6
move 1 from 3 to 7
move 2 from 6 to 5
move 11 from 2 to 1
move 1 from 8 to 4
move 16 from 1 to 9
move 1 from 2 to 6
move 1 from 8 to 5
move 12 from 9 to 3
move 14 from 7 to 2
move 1 from 7 to 9
move 1 from 4 to 2
move 1 from 7 to 5
move 3 from 9 to 5
move 4 from 6 to 9
move 3 from 9 to 4
move 1 from 8 to 4
move 2 from 4 to 5
move 1 from 7 to 1
move 5 from 3 to 5
move 2 from 4 to 2
move 8 from 2 to 7
move 7 from 2 to 4
move 1 from 3 to 7
move 3 from 9 to 7
move 2 from 2 to 9
move 3 from 4 to 5
move 6 from 1 to 8
move 6 from 1 to 5
move 3 from 9 to 2
move 22 from 5 to 9
move 1 from 5 to 6
move 2 from 2 to 3
move 5 from 7 to 6
move 5 from 8 to 9
move 2 from 7 to 2
move 20 from 9 to 4
move 1 from 8 to 3
move 2 from 2 to 5
move 1 from 2 to 5
move 15 from 4 to 8
move 1 from 5 to 7
move 6 from 9 to 1
move 5 from 4 to 8
move 2 from 4 to 8
move 1 from 2 to 1
move 5 from 6 to 5
move 5 from 5 to 7
move 1 from 9 to 8
move 5 from 7 to 2
move 2 from 5 to 1
move 4 from 7 to 5
move 1 from 5 to 9
move 1 from 6 to 8
move 1 from 7 to 2
move 6 from 3 to 4
move 3 from 5 to 7
move 1 from 9 to 2
move 6 from 2 to 3
move 1 from 3 to 4
move 13 from 8 to 9
move 7 from 1 to 5
move 6 from 9 to 2
move 1 from 1 to 4
move 6 from 2 to 3
move 1 from 1 to 4
move 5 from 9 to 7
move 11 from 8 to 4
move 7 from 7 to 3
move 2 from 7 to 8
move 1 from 8 to 2
move 8 from 4 to 1
move 2 from 1 to 6
move 2 from 5 to 8
move 3 from 1 to 9
move 1 from 8 to 2
move 11 from 3 to 2
move 2 from 8 to 9
move 9 from 4 to 7
move 11 from 3 to 8
move 7 from 9 to 6
move 5 from 4 to 6
move 3 from 7 to 3
move 1 from 7 to 1
move 5 from 7 to 6
move 2 from 3 to 5
move 1 from 3 to 4
move 5 from 2 to 5
move 1 from 1 to 7
move 1 from 4 to 8
move 1 from 7 to 6
move 7 from 5 to 7
move 2 from 5 to 7
move 3 from 1 to 7
move 1 from 2 to 3
move 1 from 6 to 4
move 1 from 3 to 4
move 1 from 5 to 3
move 18 from 6 to 4
move 9 from 7 to 1
move 14 from 4 to 6
move 3 from 6 to 4
move 12 from 6 to 7
move 2 from 5 to 3
move 3 from 7 to 4
move 6 from 4 to 7
move 5 from 1 to 7
move 5 from 4 to 5
move 5 from 2 to 1
move 9 from 8 to 4
move 9 from 1 to 3
move 2 from 8 to 2
move 4 from 2 to 4
move 1 from 7 to 6
move 1 from 2 to 3
move 1 from 8 to 9
move 1 from 6 to 9
move 2 from 9 to 3
move 3 from 4 to 1
move 13 from 3 to 5
move 12 from 5 to 1
move 7 from 1 to 8
move 1 from 3 to 6
move 4 from 5 to 4
move 1 from 5 to 2
move 8 from 4 to 9
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:
data = fd.read().strip()
return data
def start_of_message(data, n):
""""""
for i in range(len(data)):
if len(set(data[i:i+n])) == n:
break
return i + n
def main():
data = load_input()
# Task 1
result = start_of_message(data, 4)
print("Result 1: ", result)
# Task 2
result = start_of_message(data, 14)
print("Result 2: ", result)
if __name__ == '__main__':
main()
rvnvzvhzzjgjgffclllnhhtltptgptgpttjhttsllmbbphbpbzpbpjjcwjwqwccnrrtvrtrfrwffnqffsggwzzhtzhthqhffmrrzsrrnrtrqqbllhrlrjrvvrvvgdgjgfjjtzznffrfvfggswgssccpcwpccstcsstwssgzssswsgwsgsnsshcsscsffcwcmmhmsmrsrddwhhszsfsjfsfccwssvdssmzzwrzzjfzzvzzfsfsvshschhvlhhvmvpvhhstsdtstgtrrtjjcssgfssnsnfsnscnsslvvqbbhthqtqzqmzmjjfmmbdmmzdmdpmpnnfjnnrwnwbwrrwjrrttfzzlwwfmmnhhqlhqqbnqnqznncmmhfmfftsfszssftstggppfddtztltctqcqjcqcmclcnccdgcggvmvvcsstztbzttsccmgcghcczfzszbzmbmjjggsqgghbhjjhhrrjljmllczlzzqssjfjqfjfmfdfgffczfzwwpfwpwbbftbffplphhfcftctlcclhlnlhnhlhnhqnhhjbjmmtpmmlsmllvhhjghhmzzwpzprrjrzzvrvcvqvssgssnccmgmppfhfwhhczhhprhrffpvvqrqvqccdhdvvvssvdvwdwwzggfvfnvvqvwwzwmzzvttgzzwjjfvvpvffqpqhqrrwccjbjppbzbrbrrphrhgrhhzbbhrrblbjjznnlccsffpcfpcfpfddfwddbffczztzsttzsstddrqdqqchqccrlccfcwwghwhnhbhjbhhzrrgprrftrffqlljlslggzdzvvrgvgcgnnngtnggdcgddhjhchqcqfqwfwjffqppblbddgmdgmddrnddjtdjttgzgpzggwvwjvwwhdwwbvvtftcfttpftpfpzfznnchnhrrdtdbtdbdppsjsgsttptsptssnwntwnnsshqqgnnqnddhjjtqqjhhmghmhmsstrrhmmwvvlssprsrbbswsddbnntmtbmtbmmtmrrffvjffdrffnttbffbccgchghjgjwwshwswdswdsdsrdsdjdvjjgbjbssptpddzbdddqdpdspswssjrjwwcbbvsspnspslpplzlqlccvlvfllntlntnqnrqnqpqlqflfrfsfgsfswwptwwgqggrhghzghhrthtzhzsswhhzffpsffhnnrvnrvvhmmlvvqsslddhcddsllpmpggrhrcrbbmnmjmqmlmpmrrqwqhqrqhrrgrqqsrrpjpdjppzhphthddlzdzhddjvdjdcjcncnvnzzvwzvzgzjggcllvpllgdgqqdvvwnvwvwqqvwvvrbbtqqwhdztqfzzcqrshjzwqnpdsshmpjzwqdptbvfqzmfnbtlgbbsjbqgnblhbbpsfdzvcmpzfwczcnbdndsjzccjcqnrdglwfrvwtnjwpvpvvgwtmnpzhbwnbqwznmdvdrsjnlsfrpcnhlbmlgmrcjbbvhqnvbrmlnfttjllstqnqqnhqrzrhfqjbfbwfhhjzwtwzjmszzhjnjbhrlbnnpfvdmlftjnfsfnvddqfhqqlljrthptvmhbqrdmdcmljwgbrqrjwcrtmvjgqtblnslgbjmdsrrpgfsctrhwlwnszpljhrfnsfpcsgczzltgsztclhgcqljrcmbbpdlztncnrnrmgrttplcnldfqddqhznmcczbmwvsztmwmcqnrzmlmqchnhnhrrhhfntjzqcbnttspptqwvphlbtpfcbhdqzbhsbvhmsqbsdntwpcrnzvmbgqsgttbqhhblfjpmvfcrzhfnzwrzbzgsdfqndzzhfdnrvsnvfbptthjnhgljhrvwwrlbnfpvvjdjchcgbhfrqvszhrhqvtzplwsptvdhqwlzhcjpclmmrlccvgvtgsfpnjhqhrbqglznpdhmsqwwsbmhmlsmmvvghsmplqjchrfctltmnqnddzqjfpljwljbdqjcqdqzwsbcclqsmsmlstvljwwtfmpnhqzqfjghjfchjccqrchsvngvrnwfwttsnvrdlfvwfptsjcpslvvpmjclfcpljqjszptsgsmntzrdjbgrzmgvzddqrlsndjzzqbznqnphbnwfhtjjlwjpsvffrdrbsbttpgrvmqrdndqvlgzcpfbttvqdgvrmtvfclcbcwllthmdzjcflwpnrsqzrjdzbvqgzsqvjjpjjpnjtcjqhcfbjdqndlcwzhcbjtgtlvtdwctdnqcbcgsmrcrmwjntdwbjdbzmshbvlspjfdbvmlrbdzlmlggthvphnrqlrcdsqpsgqcmpgmgdzvdqlmcldvztpsbmpwjgjfhswplwrvwpbwbsgsvlhdvmpzwnnbwjwmshwcnqfqjdpchfjjcbdnslqchhnznpqpnnctznbtccclgjhmnngdjlmqnzpsdptqqcrblmrlnnpgvrfrtmbjnmspfrbwpclhgtbsghndrjfbggsplvcjnhjjbqzsfdpfnvchzjgbhdqgddfgddvzdcrjlntnsmscqwmpptqgbnvtsvpjvmhcfpbfrpzqbpfhlbjrmbmvdvvnvfqsndglvhfrqcsbsbbprscrbfthzcwcdrprqrwjzwrpblfllpwzlhmqvltjgpcjzpzwbltgwsrgrrhzcqfpvhcprdhnzcfphqrwcvtpcbppjwzmmwjhbvwbblnbwvcqzvlfzjhgmlnhlhrbsplfctggfbhbgwpncznvtmdtqqmjsvsnrlqswzvflrfsncgpdcndlwrfrqwqnqtjmsphwsgzhdjpnsdgrbrfhbfdrntwvgvbwnvwnrmdbhqgrglbfwprflnrljrwsgwtpgtmfhvvghtzndvwlzjchhmlwcncmpvrslrglzjcnhfdqhcrljhgbzpssvdnmfwzstmvrztgpsscfswltnbwrrtcnvbswmmjbmnnnvqwjzhprfnvlbvzzdvbwlwchrvqnwwpbnttbhfdvjjvzsznhczjcncmcrmwtrlsvbwpsrcwqdvgcfjsbqnwmjmtcgpnmcbfbcqhzrjbtlpvwzhjqqprbdnbgzfwlprlcspwjwnfftldqzbcgqnjtglvbpqffdvjbpslqcdzwdnmncvcwfshdhsmssttqfrsbnjgmhfqzlgrbpdfqtfdwslsgphfzzgbzjssfbgnwztzmczplqwjmhtlflpvqqqmrvlllhngtfgsvbbnvhzqbcgpmnlsmpwqwgqfjpzplzjhrslwzrsrgjgpppjlnhrnggcdzvspsztnschnqftgffbtvrpzndzpqmtsfmwgnrvpmtgpvnmqfmwgcvlznwqnjnjwpgnqfjwtdhhmztlvlcvrlzmlpmjdvdnzwbfsshfsvbbhqsmphjhqtlnvlsmvwlqvfqpnjnzlgmdvwzzrllmcgwtqdwphhbwmlrqhqrfmdvtqswvsllqvwmfbbpllsbjbvgsmrcgqvfgsnszfrdlcjbtfgcbclhmzlmqlnhmslcmgrcvjjlbpsjjcznzqwmztcgdgbmrlgwzjzzjrpndfrdzztzzgmsrcnwrvqrdcczrbhdpfjwvqsmbrcvllvjrrbrsqnzldltdgzscjrssvdhzhnvltpgfdfcvfbtqmphdzhpzgjhjbwsmdlbqqgcrhjrwhgvfgdllmmlnpsbtvdrrzmltfwgrcsfrrsdbdmjtrwhnlgcrgjgmbzvzvqbflvbrsqcssjgsvpjmlhtcggzwbvddmwwtfdrlltjqcpwnthczzlzdszvtmrmhbpcgstvrsnmbdcmjzsvnncmgmlnrzzhfvmblgptwwwbrmtcczjwcqmvdrsvfjgqqvghnhbntqcdrppfmvdzbcjvztrnpdhmdpmnvsnzzldvdfqbdrwqqqqsmswthwpjwdrflszbspqhpfwztjjcbdsrftdsrsfdltnfztcslmbsghgrtcscrfmptqplwpmtqdzthgfjhbqdnsffrpjmgczmrlfvzcjttwtmtqfbtlqrttvjdwhfgcgcclrlswmzhzbfhjrggnhwtnffnqqcvldlttvvgrbcqbmqzvtflfmdblhdbzphrqtbshvp
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import networkx as nx
def load_input():
data = nx.DiGraph()
cur_dir = ''
with open('input') as fd:
for line in fd:
temp = line.strip().split()
if temp[0] == '$' and temp[1] == 'cd':
if temp[2] == '..':
preds = list(data.predecessors(cur_dir))
cur_dir = preds[0]
else:
cur_dir = cur_dir + temp[2]
if not cur_dir.endswith('/'):
cur_dir += '/'
data.add_node(cur_dir)
elif temp[0] == '$' and temp[1] == 'ls':
pass
elif temp[0] == 'dir':
data.add_edge(cur_dir, cur_dir + temp[1] + '/')
else:
size = int(temp[0])
filename = temp[1]
data.nodes[cur_dir][filename] = size
return data
def get_total_size(g, node):
total = sum(g.nodes[node].values())
for successor in g.successors(node):
total += get_total_size(g, successor)
g.nodes[node]['total'] = total
return total
def part1():
data = load_input()
total = get_total_size(data, '/')
result = 0
for node in data.nodes:
total = data.nodes[node]['total']
if total <= 100000:
result += total
print("Result 1: ", result)
def part2():
data = load_input()
total = get_total_size(data, '/')
needed_space = 30000000 - (70000000 - total)
temp = [data.nodes[node]['total'] for node in data.nodes if data.nodes[node]['total'] > needed_space]
temp.sort()
result = temp[0]
print("Result 2: ", result)
def main():
part1()
part2()
if __name__ == '__main__':
main()
$ cd /
$ ls
dir bntdgzs
179593 cjw.jgc
110209 grbwdwsm.znn
dir hsswswtq
dir jdfwmhg
dir jlcbpsr
70323 qdtbvqjj
48606 qdtbvqjj.zdg
dir tvcr
dir vhjbjr
dir vvsg
270523 wpsjfqtn.ljt
$ cd bntdgzs
$ ls
297955 gcwcp
$ cd ..
$ cd hsswswtq
$ ls
dir bsjbvff
dir dpgvp
267138 grbwdwsm.znn
dir hldgfpvh
dir jdfwmhg
dir jtgdv
93274 ptsd.nzh
268335 qdtbvqjj.dlh
185530 qdtbvqjj.jrw
dir vcbqdj
dir wtrsg
$ cd bsjbvff
$ ls
dir dmnt
148799 grbwdwsm.znn
324931 hzmqrfc.lsd
211089 qdtbvqjj
$ cd dmnt
$ ls
221038 zht
$ cd ..
$ cd ..
$ cd dpgvp
$ ls
dir fzttpjtd
dir jdrbwrc
dir rwz
dir tssm
$ cd fzttpjtd
$ ls
149872 jdfwmhg
$ cd ..
$ cd jdrbwrc
$ ls
149973 hpgg.srm
dir ptsd
$ cd ptsd
$ ls
2594 twzf.pqq
$ cd ..
$ cd ..
$ cd rwz
$ ls
dir jdfwmhg
302808 zzlh
$ cd jdfwmhg
$ ls
229683 cdcrgcmh
218733 nhzt
$ cd ..
$ cd ..
$ cd tssm
$ ls
dir ptsd
37272 qfnnrqsh.qvg
215066 wnvjc.jqf
$ cd ptsd
$ ls
24102 bwtbht.dwq
224035 qdtbvqjj.dmp
$ cd ..
$ cd ..
$ cd ..
$ cd hldgfpvh
$ ls
316712 grbwdwsm.znn
328950 tqvgqjrr
$ cd ..
$ cd jdfwmhg
$ ls
130652 gcwcp
dir jdfwmhg
215427 lfw.zml
dir qdtbvqjj
4181 rgsvgssj.qsr
$ cd jdfwmhg
$ ls
dir bvm
dir hsswswtq
122279 qznt.jhl
dir sjw
dir zpfdtl
$ cd bvm
$ ls
22841 fbcgh.mrp
dir hsswswtq
dir hstg
41317 ndrt
dir nvmvghb
239316 ptsd
dir qtwvdtsp
98555 vzh
$ cd hsswswtq
$ ls
dir ddcjvjgf
127104 plwvb.pbj
dir ptsd
dir qhp
dir rjtrhgwh
$ cd ddcjvjgf
$ ls
135870 bwtbht.dwq
81968 gcwcp
182253 mrbh.wmc
275931 nsrqrts
322128 pfpcp
$ cd ..
$ cd ptsd
$ ls
214981 jsrlsc
dir wpbdrcw
$ cd wpbdrcw
$ ls
197849 mljfb.ggb
173586 ptsd
$ cd ..
$ cd ..
$ cd qhp
$ ls
293198 bnrgl
$ cd ..
$ cd rjtrhgwh
$ ls
224393 clrp.nst
$ cd ..
$ cd ..
$ cd hstg
$ ls
51671 gdsfpc
209216 hsswswtq
97203 jlnr
dir thdhg
57399 tssm
$ cd thdhg
$ ls
201896 jjp.wvw
$ cd ..
$ cd ..
$ cd nvmvghb
$ ls
210047 gfcrzgj
dir rqjbplv
dir rvwd
292931 sgwvcqfr.bpq
dir vtjd
$ cd rqjbplv
$ ls
105204 gcwcp
$ cd ..
$ cd rvwd
$ ls
66170 jdfwmhg
$ cd ..
$ cd vtjd
$ ls
dir ptsd
$ cd ptsd
$ ls
300524 bwtbht.dwq
$ cd ..
$ cd ..
$ cd ..
$ cd qtwvdtsp
$ ls
289574 wctgtq
$ cd ..
$ cd ..
$ cd hsswswtq
$ ls
24935 gcwcp
dir jzpbdcmc
26834 mljfb.ggb
182501 phnmlsjp.pjc
dir pttnl
dir qdtbvqjj
dir vst
$ cd jzpbdcmc
$ ls
297521 grbwdwsm.znn
dir qwc
dir zzswd
$ cd qwc
$ ls
81143 hsswswtq.rjw
54843 mjvvfsz.rgz
273051 pfwgtmtt.ccs
$ cd ..
$ cd zzswd
$ ls
216062 vlbwz.zmh
$ cd ..
$ cd ..
$ cd pttnl
$ ls
257733 mljfb.ggb
250887 pfwgtmtt.ccs
$ cd ..
$ cd qdtbvqjj
$ ls
34667 gcwcp
$ cd ..
$ cd vst
$ ls
70250 pfwgtmtt.ccs
dir zpcqhml
$ cd zpcqhml
$ ls
219936 jdfwmhg.zbm
$ cd ..
$ cd ..
$ cd ..
$ cd sjw
$ ls
152311 nqjtvzff
157117 pfwgtmtt.ccs
118226 ptsd.vsm
$ cd ..
$ cd zpfdtl
$ ls
189042 gcwcp
$ cd ..
$ cd ..
$ cd qdtbvqjj
$ ls
dir ftz
dir hvlffb
dir lzbb
53335 ptsd
dir qdtbvqjj
$ cd ftz
$ ls
dir fft
256058 gcwcp
497 hsswswtq.vqs
103941 hvtcz.fsg
171587 ljlnz.ffg
115101 mljfb.ggb
dir qdtbvqjj
$ cd fft
$ ls
58845 bwtbht.dwq
136040 gcwcp
256973 mljfb.ggb
$ cd ..
$ cd qdtbvqjj
$ ls
dir fgqhdh
304573 ntm.wmc
$ cd fgqhdh
$ ls
317143 gcwcp
26010 lsfpfdqz
$ cd ..
$ cd ..
$ cd ..
$ cd hvlffb
$ ls
6682 vjt.mcf
$ cd ..
$ cd lzbb
$ ls
dir bbvml
324162 bwtbht.dwq
dir fjs
dir pffntc
dir pnltt
dir ptsd
$ cd bbvml
$ ls
dir qdtbvqjj
dir qssdcrp
dir tssm
$ cd qdtbvqjj
$ ls
246275 qdtbvqjj.cgn
$ cd ..
$ cd qssdcrp
$ ls
274399 hsswswtq
$ cd ..
$ cd tssm
$ ls
dir ssqc
$ cd ssqc
$ ls
178904 njrssmlm.gcm
$ cd ..
$ cd ..
$ cd ..
$ cd fjs
$ ls
dir dmvnp
121967 fqlzlvwt
204348 grbwdwsm.znn
102733 jdfwmhg.qsl
240279 ptsd.jwm
228793 ptsd.nsh
dir ssm
$ cd dmvnp
$ ls
dir psj
dir zjw
$ cd psj
$ ls
170665 gcwcp
56058 lsfzc.dcp
40658 tfsllqqw.fgv
$ cd ..
$ cd zjw
$ ls
79989 fggsl.dmz
$ cd ..
$ cd ..
$ cd ssm
$ ls
106263 bwtbht.dwq
106259 jdfwmhg.qtb
6246 rwbnr.tqv
$ cd ..
$ cd ..
$ cd pffntc
$ ls
111475 qbmrdms.ldm
$ cd ..
$ cd pnltt
$ ls
dir nptfhlf
dir zngmf
$ cd nptfhlf
$ ls
223065 qrb.drh
205674 rdgfz
$ cd ..
$ cd zngmf
$ ls
61655 bwtbht.dwq
$ cd ..
$ cd ..
$ cd ptsd
$ ls
dir hrvrt
dir thwtl
$ cd hrvrt
$ ls
152296 pfwgtmtt.ccs
$ cd ..
$ cd thwtl
$ ls
156783 pfwgtmtt.ccs
323304 sltc
$ cd ..
$ cd ..
$ cd ..
$ cd qdtbvqjj
$ ls
320175 pfwgtmtt.ccs
$ cd ..
$ cd ..
$ cd ..
$ cd jtgdv
$ ls
81164 ptsd.tpj
$ cd ..
$ cd vcbqdj
$ ls
dir crng
330203 gvlrg
152022 qdtbvqjj.slq
294095 rthwj.zrf
dir vjsbf
$ cd crng
$ ls
dir gznrh
$ cd gznrh
$ ls
259458 ptsd
$ cd ..
$ cd ..
$ cd vjsbf
$ ls
47331 hlld.fzf
147103 jdfwmhg
$ cd ..
$ cd ..
$ cd wtrsg
$ ls
144344 dtcc
$ cd ..
$ cd ..
$ cd jdfwmhg
$ ls
323973 qdtbvqjj
$ cd ..
$ cd jlcbpsr
$ ls
dir htrdwm
dir jdfwmhg
dir pwmvbhsl
dir vwfdfmcp
$ cd htrdwm
$ ls
dir btn
105731 dlncqrbm.dgl
158267 gqqghldt
242513 hsswswtq.drj
dir jdfwmhg
212816 swsgtv.wbb
228996 tgll.rcs
$ cd btn
$ ls
50419 pfwgtmtt.ccs
$ cd ..
$ cd jdfwmhg
$ ls
dir bwc
$ cd bwc
$ ls
184634 cfwg
$ cd ..
$ cd ..
$ cd ..
$ cd jdfwmhg
$ ls
319749 hsswswtq
dir jdfwmhg
271619 jdfwmhg.znz
dir jhmmt
181217 mljfb.ggb
11297 rcpl.tgf
83423 zwscbcvm.ths
$ cd jdfwmhg
$ ls
267171 cts.hlf
$ cd ..
$ cd jhmmt
$ ls
84473 jdfwmhg
$ cd ..
$ cd ..
$ cd pwmvbhsl
$ ls
dir jsg
171725 mljfb.ggb
152612 qjr
dir vfsqw
$ cd jsg
$ ls
176951 jdfwmhg.fhn
284927 ljvvtw.wcq
153109 vnvtt
$ cd ..
$ cd vfsqw
$ ls
104559 htsrns.gws
$ cd ..
$ cd ..
$ cd vwfdfmcp
$ ls
291404 csmvbjlt.tdf
$ cd ..
$ cd ..
$ cd tvcr
$ ls
dir djtwv
dir hsswswtq
272845 mdds
dir ndshbjzn
65929 scpltww.twm
dir tssm
30516 zdpscm
dir zqdrdzv
$ cd djtwv
$ ls
271696 cwjj.hjp
$ cd ..
$ cd hsswswtq
$ ls
dir djngm
dir hcz
dir ptsd
$ cd djngm
$ ls
317775 ltwjzpjb.rcj
37776 qdtbvqjj.lzf
$ cd ..
$ cd hcz
$ ls
217741 pgdmr
128868 qdtbvqjj
306138 zbmrplsn
$ cd ..
$ cd ptsd
$ ls
304048 ftm
120236 mdcwvvng
$ cd ..
$ cd ..
$ cd ndshbjzn
$ ls
206408 pfwgtmtt.ccs
$ cd ..
$ cd tssm
$ ls
dir mlcnsf
dir nbgjm
204079 pdljvb
185465 rqgdmbjf.rhr
dir sfnlb
$ cd mlcnsf
$ ls
249868 fqrncwd
29146 zdz.jth
$ cd ..
$ cd nbgjm
$ ls
113314 mljfb.ggb
$ cd ..
$ cd sfnlb
$ ls
234917 tjp
$ cd ..
$ cd ..
$ cd zqdrdzv
$ ls
40790 vtdnhzm
$ cd ..
$ cd ..
$ cd vhjbjr
$ ls
dir glv
dir mvns
dir qbrnh
$ cd glv
$ ls
288849 bgvqll.sfj
259105 jdfwmhg
dir qcjlshcv
$ cd qcjlshcv
$ ls
dir nwqqjcmh
$ cd nwqqjcmh
$ ls
137244 grbwdwsm.znn
312904 mzh
dir qdtbvqjj
$ cd qdtbvqjj
$ ls
dir nlqbq
$ cd nlqbq
$ ls
307636 ptsd.vtr
$ cd ..
$ cd ..
$ cd ..
$ cd ..
$ cd ..
$ cd mvns
$ ls
dir gzqlmrdh
dir qjhtlh
dir tssm
dir vthg
$ cd gzqlmrdh
$ ls
274950 mlzdqwm
$ cd ..
$ cd qjhtlh
$ ls
157835 ptsd.lqm
300380 wst.trp
$ cd ..
$ cd tssm
$ ls
15772 gcwcp
$ cd ..
$ cd vthg
$ ls
dir gdndtlnc
$ cd gdndtlnc
$ ls
3175 hsswswtq.bds
320462 mljfb.ggb
305508 mzvtzvqc
dir qdtbvqjj
154575 tssm.vgb
$ cd qdtbvqjj
$ ls
236889 drnnvh
$ cd ..
$ cd ..
$ cd ..
$ cd ..
$ cd qbrnh
$ ls
dir hsswswtq
4623 hsswswtq.rnf
266326 jrmq.ztg
295980 tssm.vzb
dir wnbfzd
dir zjzhncs
dir zttlggt
$ cd hsswswtq
$ ls
48277 gsqjdbhv
$ cd ..
$ cd wnbfzd
$ ls
97133 mljfb.ggb
$ cd ..
$ cd zjzhncs
$ ls
298303 gcwcp
dir ggr
113206 grbwdwsm.znn
$ cd ggr
$ ls
244876 ptsd.zvb
$ cd ..
$ cd ..
$ cd zttlggt
$ ls
dir hdbwrcm
dir mbvpd
dir mtd
dir ptsd
dir tcwqp
$ cd hdbwrcm
$ ls
267323 bwtbht.dwq
$ cd ..
$ cd mbvpd
$ ls
84087 frf.smv
$ cd ..
$ cd mtd
$ ls
158543 mljfb.ggb
$ cd ..
$ cd ptsd
$ ls
112797 vtschwnb.fnp
$ cd ..
$ cd tcwqp
$ ls
90637 lbsqcj.sfn
179097 tssm.dbl
$ cd ..
$ cd ..
$ cd ..
$ cd ..
$ cd vvsg
$ ls
168715 bwtbht.dwq
dir bwv
dir hsswswtq
dir lqmnjrlb
dir mmrfrj
175244 vct.tsc
dir zwvlhs
$ cd bwv
$ ls
201509 gcwcp
62815 grbwdwsm.znn
dir gwdh
dir mfdvcn
166355 pfwgtmtt.ccs
dir ptsd
169681 qdtbvqjj.fgh
250573 wvndzgv
$ cd gwdh
$ ls
306377 sphrj.pjh
$ cd ..
$ cd mfdvcn
$ ls
27796 bvclvtrm.jlf
65045 cghr.vzg
dir hsswswtq
197145 jdqztgh.pvd
$ cd hsswswtq
$ ls
298155 bwtbht.dwq
$ cd ..
$ cd ..
$ cd ptsd
$ ls
27501 grbwdwsm.znn
231999 jdnsv
113528 rmfmb.zzw
dir tssm
dir vgjfsh
$ cd tssm
$ ls
dir dndv
226375 grbwdwsm.znn
$ cd dndv
$ ls
152739 sdjrzcv.tvs
$ cd ..
$ cd ..
$ cd vgjfsh
$ ls
211409 swtbttb.vrp
170879 vvfnf.hrp
$ cd ..
$ cd ..
$ cd ..
$ cd hsswswtq
$ ls
dir qdtbvqjj
dir tssm
86418 vhsgq
$ cd qdtbvqjj
$ ls
118588 bwtbht.dwq
$ cd ..
$ cd tssm
$ ls
113460 gml.wdg
$ cd ..
$ cd ..
$ cd lqmnjrlb
$ ls
dir tssm
$ cd tssm
$ ls
dir jdfwmhg
$ cd jdfwmhg
$ ls
64663 nswd.rwc
$ cd ..
$ cd ..
$ cd ..
$ cd mmrfrj
$ ls
319070 gltlwnlt.jzw
232039 hspr
104688 hsswswtq.jsr
dir jdfwmhg
88712 jdfwmhg.zcw
dir pfr
dir prnnpwcd
45488 qdtbvqjj
dir tssm
dir wcmwrtjn
$ cd jdfwmhg
$ ls
140910 bjjhtzct.stm
$ cd ..
$ cd pfr
$ ls
289538 qdtbvqjj
217502 vvpwf
$ cd ..
$ cd prnnpwcd
$ ls
dir qdtbvqjj
$ cd qdtbvqjj
$ ls
dir pqg
dir tssm
$ cd pqg
$ ls
222392 ptsd.ggr
$ cd ..
$ cd tssm
$ ls
158252 dcnvjj.zfd
10486 jdfwmhg.qmb
4374 qdtbvqjj.vqm
254229 vgqfw
$ cd ..
$ cd ..
$ cd ..
$ cd tssm
$ ls
dir ptsd
$ cd ptsd
$ ls
173766 fvlsgqb
35658 wtc.vvd
$ cd ..
$ cd ..
$ cd wcmwrtjn
$ ls
160089 chfhpc
76202 frgpdnd.ngw
138996 jsfsfpqg.nhf
dir mlm
dir nbdbzsn
dir ptsd
278574 vrnb
$ cd mlm
$ ls
dir gqwhhmvd
dir nrzvzgrt
dir nzplht
dir zzp
$ cd gqwhhmvd
$ ls
dir ddmvjpj
dir jdfwmhg
$ cd ddmvjpj
$ ls
273423 jdfwmhg
43605 pfwgtmtt.ccs
$ cd ..
$ cd jdfwmhg
$ ls
239406 qctw.vzb
$ cd ..
$ cd ..
$ cd nrzvzgrt
$ ls
20712 gcwcp
239372 gjgdvbwb.gcz
dir hdzhl
124814 jdfwmhg
dir jfzr
295071 qwjgwqp
221611 shrzpsj.dwh
dir tssm
dir wdlsvzvl
$ cd hdzhl
$ ls
dir gfwbd
184323 hsswswtq.mln
177147 nqgqz.tnf
4680 pfwgtmtt.ccs
$ cd gfwbd
$ ls
254870 cldm.fft
301411 tssm.cvn
$ cd ..
$ cd ..
$ cd jfzr
$ ls
dir dvvflnnw
dir jdfwmhg
216389 lwtwn.ttt
201727 pfwgtmtt.ccs
107829 prphc.ncb
5816 sdvq.jvn
$ cd dvvflnnw
$ ls
24741 brtrbwh.wwd
27700 mljfb.ggb
$ cd ..
$ cd jdfwmhg
$ ls
325218 bwtbht.dwq
63718 mvl.ngz
162645 vtd.vgp
$ cd ..
$ cd ..
$ cd tssm
$ ls
60903 pfwgtmtt.ccs
332768 qdtbvqjj.jwb
$ cd ..
$ cd wdlsvzvl
$ ls
142213 vgvd
$ cd ..
$ cd ..
$ cd nzplht
$ ls
275904 hsswswtq
157369 jdfwmhg
84363 jvcvmbm.fht
dir qbjqgg
$ cd qbjqgg
$ ls
331934 gcwcp
$ cd ..
$ cd ..
$ cd zzp
$ ls
151335 flsd.zmj
dir gwlhqlp
99086 jdfwmhg.hft
$ cd gwlhqlp
$ ls
201894 glcnpqzp.jvc
$ cd ..
$ cd ..
$ cd ..
$ cd nbdbzsn
$ ls
169929 bwtbht.dwq
$ cd ..
$ cd ptsd
$ ls
128999 bwtbht.dwq
dir jtlrn
dir pszlt
dir ptjnh
dir ptsd
2981 qdtbvqjj.qcn
dir rpb
dir tcjgpqj
dir tmddnh
dir tssm
$ cd jtlrn
$ ls
124888 grbwdwsm.znn
30046 jznz.dwf
$ cd ..
$ cd pszlt
$ ls
154368 dbblsg.mzr
$ cd ..
$ cd ptjnh
$ ls
306974 grbwdwsm.znn
82840 ptsd
$ cd ..
$ cd ptsd
$ ls
dir ftjhsb
dir jdfwmhg
304012 lqgtvmrl.qbj
96971 mljfb.ggb
$ cd ftjhsb
$ ls
56965 dhgds
$ cd ..
$ cd jdfwmhg
$ ls
dir lssbmtms
dir vmwshd
$ cd lssbmtms
$ ls
95453 gcwcp
198402 mljfb.ggb
1507 mzlmp
40526 twlqhml
$ cd ..
$ cd vmwshd
$ ls
267087 pfwgtmtt.ccs
$ cd ..
$ cd ..
$ cd ..
$ cd rpb
$ ls
dir lqbchlbp
dir ptsd
$ cd lqbchlbp
$ ls
151429 ptsd.tjz
$ cd ..
$ cd ptsd
$ ls
28900 gcwcp
55920 llt
$ cd ..
$ cd ..
$ cd tcjgpqj
$ ls
dir cvdlcvq
329232 hcmj.nvp
232764 nvtmgc.qgs
108056 ptsd.gcn
39056 qdtbvqjj
91792 tssm.wqz
$ cd cvdlcvq
$ ls
46978 grbwdwsm.znn
17760 qrdbsdpj.dhm
$ cd ..
$ cd ..
$ cd tmddnh
$ ls
238434 gggvq.tfc
$ cd ..
$ cd tssm
$ ls
dir tlllv
$ cd tlllv
$ ls
198184 trmf.qqw
$ cd ..
$ cd ..
$ cd ..
$ cd ..
$ cd ..
$ cd zwvlhs
$ ls
19923 gcwcp
129179 grbwdwsm.znn
214660 pghcvh
101270 ptsd.gzl
dir srjlz
$ cd srjlz
$ ls
221301 nrcg.pqw
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 line in fd:
line = line.strip()
data.append([int(value) for value in line])
data = np.array(data)
return data
def main():
data = load_input()
# Task 1
visibles = np.full(data.shape, True, dtype=np.bool_)
visibles[1:-1, 1:-1] = False
inner = data[1:-1, 1:-1]
it = np.nditer(inner, flags=['multi_index'])
for value in it:
i, j = it.multi_index
i += 1
j += 1
for k in range(4):
highest = 0
if k == 0:
highest = max(data[0:i, j])
elif k == 1:
highest = max(data[i+1:, j])
elif k == 2:
highest = max(data[i, 0:j])
else:
highest = max(data[i, j+1:])
if highest < value:
visibles[i, j] = True
break
result = np.sum(visibles)
print("Result 1: ", result)
# Task2
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
options = visibles.copy()
options[0, :] = False
options[:, 0] = False
options[-1, :] = False
options[:, -1] = False
indexes = np.argwhere(options)
most_scenic = 0
for i, j in indexes:
temp = 1
for d in directions:
y = i
x = j
while True:
y += d[0]
x += d[1]
if x == 0 or x == data.shape[1] - 1 or y == 0 or \
y == data.shape[0] - 1 or data[y, x] >= data[i, j]:
temp *= abs(j-x) + abs(i-y)
break
most_scenic = most_scenic if most_scenic > temp else temp
result = most_scenic
print("Result 2: ", result)
if __name__ == '__main__':
main()
112121202020313300020340412130241443213110212555412551412441344012102310202342110301131001201210222
002220000133232333300400324440200340331442222154322435351134115104433131022400301210231103320120102
002111110023312202140422121302301411425412143121451113531553512221212012141140202223332010130102121
200121112032232121304410232442313124341433152252314544515325125233341244332012020324021110233002001
201022212100303122230042110420411144235142233535353242115241433555244414021310121244221013322222121
011133013013221340022444040034222334222333233513241314324332525223122512421234021412140011030323220
210300120303001122232014221422523555232331235422254211412225214325215241553042040303041423101011002
003120002332341304133020544511125535535541345465624233512532523153125344553310344313112440310203011
131130201012400142322154551413323211211264453362355545322422255141341455331312144311201120100013210
231231113320032112042452344144421222532325455233246353364224262633314514222114310222010411123020310
130132323324003111222144335255232253526222366424453236522644225645542113443452221300403213402211010
113120324042321002433123114511424246663652545323562652666642343346224141215312351154031420431123313
322103103420203222134243312435226546235454342354423362646633563243445363453321134444313221424211210
222002200102244012425542311135622554533554536552565362325262535422342364211432245513321404214403103
020312030211000311145233135522425335364263235236633766423525523653365556233412434131421431421413032
210200210122104332244324435223345455654634767746775377345346266325246256554325112245151433442112120
122021103003325452113155263653362555455536744343555667465337737332644556355541512314415321432122010
302130331324344154351152233526435626553676357536566754666777544543643553226655255322235341014410100
314012231321215344153565545233452474545654556345434346477343637634766266254223421545221444103004003
203142142342444551513532553564436657337357765377547636675373434576744336526346456543411441023143110
012342201025331211122452444533576366457663645436375557334447647673566472636623645223251551503132201
242040141354332534632526224223663666376753663766575676333754654644753446365223356333455541211334020
304212105422512243642223324443434437444774475647656876467367634464365546355325563651434541552020333
411420043555145455366465334765477455434665856478775445748748844536643753776566362432434143454420144
401414045521554536566434665734634475568447478784884574576588667675763475753664255466323144315114340
403203444553445263226363636763747365744764846865845556768875448846334555367546232343531522434303222
320101251535223652234326457665537657586786457478765885578775686476536463546335334642346321452233131
101012145413152534234557444577344864876885844857544755664447444658566665757343254462522531514251101
340341152532244444232667437647346678855466568676685668454547775878787354745333434364264512332351234
034022314552563333466574354365446884777648857896869775765876486687448874547744636623356245124411300
434115222252325233267546336767445666887887795778879879888964665878876674757366746353365644321332143
312035533543623363556753755356877487485687695957956976755556874674844755665746737526623244522514143
420252322135326524253347754684544485747997555758865876756898776645768885645667637664454254124241132
042551521433445422576644675485868857686859585876589677967989879564666758475665333623554365252143351
404455122524562436436545777675857467559889565668857859685895859976758774886545433533522546412531113
402414213444443632667535548848565847669657785977756989557799965677887465558473374753636263414433431
022221152324544456367356377556875457665895668676988667859858876695687554757534736365524353324555445
344111222625453364363635787885744595658769866898866968696568596595864444764473337656423523432142535
225434342232366345537763675578769565995877778767697786787965759585779855884865343633323444422312351
035315413543653543334365848874759855766697967679779767999679566665785768858653734543735645643221454
023235144645352563656735676476699588575688669887679986967789786578779847658656675663653453233341153
142225254342433566337738656784888579869898976766696886867989878587588888556744335476656546565134514
332531546644465434575456856855557977598878768976688677796996689765566874765455375433552656652141222
245115244422246534474538846486987698857687868676878977996687768986655856867454644744464462545223145
534255233266234565357356454786989999898896977688879977977896669857699764786566736463343326443154122
454354332542262477736688458567665797769979688789788788987866776769877696655848467435475444463335241
512543144352562655357675475585978965976868699798788899789679876985786899685774865763673624244331431
324412256535565334657448674688895886877986668889799998798889878866685759475645457456546355544251525
115513233345333374765468446775577596767887988887878879877777968697669577748775734356333445243551434
415151565352224735474558556859799577886898999998979889789968896887667799778755865475767222365331232
341542233524534557363486747546566765697666978897898998779776898687767558456588645347447452326635211
141352533235633637755547684876556558796988688897999988799797887989695558885678545676777233242514541
521224242633256545773565667556868787766779689977797878779776688978856968445584875373474655564453414
212223344626635634464468564667887899889688667779987877977666888978896755878447456437466626246242154
234115532222663767644584477756969899977977999989879987999976887779867996588585775466444223626514313
135352514355535475547475454586885687868789797787897877999696989878678658675857877374766244666335415
245312112534242364465384488548568678767769779778898997999876767795755964548464847565732454524524223
021525515246626734753566444568597959566979986967678896977989678777787774766445653374342254643512525
154333554224543664547576668488558779569899998698676696676768688689695868756558334756732443435414211
241121123663636476553777547778679898575887899887676677898688967655685877474554463766356464665314411
042314546263224256647665654464888598856776787699868899986977858568579785688458575346453652462152344
123331145253442347344577548844655756795759896669869969898669978977675445684486336563564633463521424
441245214645233266655474685847446687769676869796966869876898656576557445456865677774743333555121233
125144145355562535553453348876854556596588579796889867979959976599967847546665344765436664421452124
005214145522463625374665767445668477766757899558986688996855569799556464475877546663265544522533142
424213534345444245575767446587747766879868999866679969656557796695754688786576454364542222333552433
340123443165235626753533465668444668759977876797965776795859756987877778467766435676633663325451242
003233434214334366657377335845776467875798576979767697579687977648857565845364473624435244552521232
424135233343456444347333753548856886767998675667957686789866998677467875563746577654546663332345512
142144412143652453363555366356464857764776776669865675576766767657655474454367647255355333454132411
114044434535536365647343757563768767554848877759975798758895468485667587677463336535634542315521124
243044411234356654655645476665375787765667655868887868786658648788875454747665334553525245122313313
223005135155362266463337346655467578858875455446758445778678456564555447754654655642444335244151100
441031313535133543536645563565447868478877557885475885785484588664864367437333352334646552545540434
230403434533122325663365655775564467566764578557546875654785658764434354637753535553443132323132432
231103055415354435244636576576467643575457665666647886566848556463753663346723326243525141135130424
234240311433354434253255264577573744567747565865655865884455858675735663776644624454624322251114322
001140425351442116425436424534333635755754445857766654848476464365374745573246334553145131221240002
423442125121142242554242262463344446436337646568454446465366647477574476743566434562422322213241112
041120244223522424262622532426564364336575645645643473455773734743736536462532635531424223442140002
333213342044141312256465444645743463747737775353476574446663366477433766453534634424144243324342330
123301211302132311214446544655333545346646756574364363763577337443636433244534466131243245142313041
333302233005545533332445234232634365637756745756665533337455656536362324645335641322232425441330441
210101031320143231223346443232362353735643457655456457447337655745423533326242244322432513011341141
103110441134453455534214566635432365634456656643365735556363677266633236436433421143354400234124322
210103104441245232113425543552436226532532734735737666776674646353226636524623254312414101401413013
020024442231000453252454154546643563663622535463445755356246553442265263346551444421542422240011133
031020232402201014325415255432463233224332466352332362464633465245446636555422514435430143120003112
310302320413232125411435155524536333442626366353663655223253243262552253454113353253031242202102210
221201232400342023452154554354353535536252463345626432342652363255555242425543353242440134432103103
210032311140434341431423452253535242446256556466223466635264232223251545121524142114121403343313003
120033031102121020314222514435233222253442525525522546426665636231521441532113451340400133032210231
210023013101112320231215311434153455555125335452263535435665554254354533423243412221004001101231111
221223223131114201030343552243332413432225514566333324653532145252122232542252133334211422030222312
222331111212014202022011214444443411412221134525134425141412252142514152354243232311422120203312310
110131122101302404410231242111542122454123223331222324435451342542314134420104111021220102332003000
201221202213022021032201013424223253221544343453433115235543553513232252242121443333323311020103222
001200323302010132410244321011414224212135145444322543324442532241244022442341044312322333033210110
012221120210002201233041204141124034134123443133233422423453224352410321301023102020300131022311221
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
direction = {
'R': (0, 1),
'L': (0, -1),
'D': (-1, 0),
'U': (1, 0)
}
def load_input():
data = list()
with open('input') as fd:
for line in fd:
a, b = line.strip().split()
data.append((a, int(b)))
return data
def next_pos(pos, d):
next_pos = (pos[0] + d[0], pos[1] + d[1])
return next_pos
def next_tail_pos(head, tail):
next_tail_pos = tail
diff = [i - j for i, j in zip(head, tail)]
if max([abs(v) for v in diff]) > 1:
d = [np.sign(i) for i in diff]
next_tail_pos = next_pos(tail, d)
return next_tail_pos
def get_tail_pos(pos, value, length):
tail_pos = list()
for i in range(value[1]):
pos[0] = next_pos(pos[0], direction[value[0]])
for j in range(length):
pos[j+1] = next_tail_pos(pos[j], pos[j+1])
tail_pos.append(pos[length])
return tail_pos
def part_n(number, length):
data = load_input()
length = length
pos = [(0, 0) for _ in range(length+1)]
tail_pos = list()
for value in data:
tail_pos.extend(get_tail_pos(pos, value, length))
result = len(set(tail_pos))
print(f"Result: {number}: {result}")
def main():
part_n(1, 1)
part_n(2, 9)
if __name__ == '__main__':
main()
L 1
R 1
L 1
U 1
R 2
U 1
D 2
R 2
U 1
D 2
U 2
L 2
D 1
U 1
D 2
L 2
D 1
L 2
D 2
L 1
U 2
R 2
L 1
D 2
L 2
R 2
D 2
L 1
U 1
R 1
U 1
L 1
D 1
R 1
U 2
D 2
R 1
U 1
R 1
L 1
U 1
R 1
D 1
L 1
U 1
R 1
D 1
U 1
D 1
U 1
R 2
L 2
D 2
L 2
R 1
U 2
L 2
R 1
U 1
R 2
D 2
R 2
L 2
U 2
R 2
D 2
R 1
U 1
L 2
R 1
U 1
D 2
U 2
D 1
R 2
L 2
D 2
L 2
R 2
U 1
R 2
L 2
D 2
L 1
D 1
R 2
L 1
U 2
R 1
U 2
D 1
U 2
D 1
L 1
R 2
D 2
R 2
U 2
R 1
U 2
R 2
U 1
R 1
D 2
U 2
R 2
U 1
R 2
D 2
R 1
L 1
U 3
L 2
U 1
L 2
U 1
D 1
U 2
D 1
U 2
R 2
L 1
U 3
R 1
U 1
R 3
L 3
D 3
L 2
U 1
D 3
U 1
R 1
L 1
R 2
L 1
R 3
L 3
D 1
R 2
L 3
U 3
D 1
L 2
U 2
D 2
L 2
U 1
R 1
L 2
R 3
L 3
D 3
R 2
D 3
U 1
L 3
R 1
U 2
L 1
D 3
L 1
U 1
D 3
L 3
U 2
D 1
U 2
L 3
R 1
U 2
D 2
R 3
D 3
U 2
D 3
L 3
R 3
L 1
U 3
L 1
D 1
L 2
D 2
R 1
L 3
R 2
L 3
R 3
L 1
D 1
U 3
L 2
R 2
L 2
D 3
U 3
L 3
U 3
D 1
U 2
R 2
U 1
D 3
L 3
R 1
L 3
U 3
D 1
L 3
D 2
R 1
U 1
R 1
D 2
L 2
U 1
L 2
R 2
L 2
D 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4
L 7
D 6
U 7
D 7
R 2
D 2
R 10
L 12
U 14
D 1
U 5
L 8
R 1
U 5
D 8
U 1
D 15
U 13
L 15
R 1
L 10
U 14
D 15
R 10
L 13
D 8
L 7
U 11
R 7
U 10
D 15
L 1
U 5
L 2
R 6
L 4
U 15
R 13
U 4
R 7
U 4
R 10
L 3
U 10
R 10
D 13
R 11
L 12
D 12
U 7
R 8
D 14
L 4
R 4
L 8
D 6
R 8
L 5
U 6
L 7
U 14
D 14
R 14
L 9
D 5
U 14
R 16
L 4
R 14
U 3
D 10
L 5
R 9
D 4
R 14
L 16
D 13
L 4
R 13
D 5
R 5
U 1
R 6
L 15
D 16
R 15
D 11
R 11
D 6
U 7
L 10
D 7
U 12
R 6
L 2
U 7
L 8
U 14
L 5
U 6
L 10
R 16
L 13
D 13
U 7
R 9
L 8
U 3
D 6
R 2
L 4
R 15
D 12
U 7
D 4
U 2
L 10
D 4
L 11
D 12
R 5
L 13
U 16
L 12
R 3
L 16
R 14
L 8
R 7
U 7
L 7
D 12
R 2
D 5
R 14
U 9
D 15
U 2
L 10
D 1
U 13
L 2
R 13
D 5
U 1
D 2
L 7
D 14
U 12
D 8
U 10
L 3
R 1
U 14
R 8
L 12
R 8
U 2
R 1
D 14
U 5
D 11
R 16
U 1
R 13
D 2
U 14
R 11
D 12
U 17
R 12
L 6
U 4
R 16
D 4
R 2
D 1
U 6
D 11
R 8
L 7
R 3
U 3
L 14
R 11
L 9
U 9
L 2
R 6
U 11
R 9
L 15
U 7
R 6
D 15
U 11
L 5
U 2
R 8
D 13
L 5
U 6
R 13
D 15
U 11
L 10
R 16
L 14
U 15
R 3
L 9
U 11
L 6
R 7
L 6
D 16
U 8
R 2
U 14
D 14
R 15
D 2
L 16
D 14
U 17
D 6
L 16
D 7
R 2
U 17
D 2
U 2
D 15
U 5
R 9
L 10
D 16
U 1
L 5
U 6
R 10
D 11
R 1
U 7
R 13
U 6
R 2
L 11
D 13
U 8
D 4
R 15
U 8
R 14
L 17
U 5
L 12
U 11
L 14
R 12
L 2
D 10
L 14
D 10
L 11
U 15
D 7
U 5
R 10
U 4
R 14
U 3
D 9
L 6
D 10
L 1
U 4
L 15
R 4
U 13
D 18
R 15
L 3
U 17
R 5
L 3
D 3
L 1
U 10
L 3
R 5
U 13
D 2
R 17
D 3
U 4
L 15
D 5
L 18
U 7
D 7
U 10
L 18
D 14
U 18
L 11
D 3
L 15
D 14
L 16
R 2
D 8
L 12
U 11
R 12
D 2
L 3
R 12
U 7
L 9
D 8
U 7
L 10
D 2
U 10
D 16
L 17
R 13
L 12
R 18
L 6
U 2
D 6
L 15
D 8
U 14
R 12
L 8
R 6
L 17
U 5
D 4
L 8
U 16
R 8
U 12
L 1
R 6
D 11
L 10
U 13
R 4
L 9
R 7
D 1
L 17
R 4
L 13
R 8
D 14
U 3
R 10
L 18
R 11
U 3
D 5
U 2
L 14
R 12
D 12
R 11
U 5
D 17
R 2
D 6
L 13
D 4
L 5
R 7
U 7
L 12
D 16
U 6
L 1
R 18
D 4
R 11
D 10
L 11
D 2
L 1
D 5
U 2
R 19
D 10
U 14
R 1
U 11
R 15
D 2
L 15
U 19
R 3
L 2
D 12
R 2
L 15
R 8
D 3
R 8
D 11
R 17
D 5
R 16
L 8
R 12
L 5
R 14
D 3
R 19
D 4
R 18
L 4
U 12
D 7
L 8
R 11
U 14
L 12
U 17
L 1
D 5
R 8
L 18
U 16
L 15
D 13
U 18
R 11
L 7
R 19
L 15
U 10
L 4
R 9
U 7
R 8
L 16
R 8
L 17
D 8
L 17
D 18
U 9
D 2
L 6
U 6
L 7
D 18
R 1
U 13
L 2
U 1
R 8
U 11
D 14
R 6
U 13
R 2
D 11
L 5
U 12
D 7
U 4
R 4
D 19
R 17
L 10
U 5
L 1
U 4
L 6
D 11
L 16
D 9
R 16
L 3
R 1
D 3
L 5
U 18
D 13
R 10
U 5
D 4
U 17
R 4
D 18
U 1
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:
line = line.strip().split()
if line[0] == 'addx':
data.append([line[0], int(line[1])])
else:
data.append(line)
return data
def update_pic(pic, value, cycle):
if cycle in list(range(value-1, value+2)):
pic += '#'
else:
pic += ' '
return pic
def part():
data = load_input()
value = 1
cycle = 0
limit = 20
result = 0
pic = ''
next_add = 0
for cmd in data:
value += next_add
next_add = 0
pic = update_pic(pic, value, cycle % 40)
cycle += 1
if cmd[0] == 'addx':
pic = update_pic(pic, value, cycle % 40)
cycle += 1
next_add = cmd[1]
if cycle >= limit:
result += value*limit
limit += 40
print("Result 1: ", result)
# Task2
print("Result2:")
for i in range(cycle//40):
print(pic[40*i:40*i+40])
def main():
part()
if __name__ == '__main__':
main()
noop
noop
noop
addx 3
addx 20
noop
addx -12
noop
addx 4
noop
noop
noop
addx 1
addx 2
addx 5
addx 16
addx -14
addx -25
addx 30
addx 1
noop
addx 5
noop
addx -38
noop
noop
noop
addx 3
addx 2
noop
noop
noop
addx 5
addx 5
addx 2
addx 13
addx 6
addx -16
addx 2
addx 5
addx -15
addx 16
addx 7
noop
addx -2
addx 2
addx 5
addx -39
addx 4
addx -2
addx 2
addx 7
noop
addx -2
addx 17
addx -10
noop
noop
addx 5
addx -1
addx 6
noop
addx -2
addx 5
addx -8
addx 12
addx 3
addx -2
addx -19
addx -16
addx 2
addx 5
noop
addx 25
addx 7
addx -29
addx 3
addx 4
addx -4
addx 9
noop
addx 2
addx -20
addx 23
addx 1
noop
addx 5
addx -10
addx 14
addx 2
addx -1
addx -38
noop
addx 20
addx -15
noop
addx 7
noop
addx 26
addx -25
addx 2
addx 7
noop
noop
addx 2
addx -5
addx 6
addx 5
addx 2
addx 8
addx -3
noop
addx 3
addx -2
addx -38
addx 13
addx -6
noop
addx 1
addx 5
noop
noop
noop
noop
addx 2
noop
noop
addx 7
addx 3
addx -2
addx 2
addx 5
addx 2
noop
addx 1
addx 5
noop
noop
noop
noop
noop
noop
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
from copy import deepcopy
from collections import deque
import math as m
def load_input():
d = {
'items': deque(),
'op': "",
'cond': list(),
'count': 0
}
data = list()
with open('input') as fd:
for i, line in enumerate(fd):
line = line.strip().replace(',', '')
temp = line.split()
if i%7 == 0:
data.append(deepcopy(d))
elif (i+6)%7 == 0:
data[-1]['items'] = deque([int(v) for v in temp[2:]])
elif (i+5)%7 == 0:
data[-1]['op'] = "".join(temp[-3:])
elif (i+4)%7 == 0:
data[-1]['cond'].append(int(temp[-1]))
elif (i+3)%7 == 0:
data[-1]['cond'].append(int(temp[-1]))
elif (i+2)%7 == 0:
data[-1]['cond'].append(int(temp[-1]))
else:
pass
return data
def part1():
data = load_input()
rounds = 20
worry_factor = m.prod([monkey['cond'][0] for monkey in data])
for _ in range(rounds):
for monkey in data:
for _ in range(len(monkey['items'])):
old = monkey['items'].popleft()
monkey['count'] += 1
worry = eval(monkey['op'])//3
if worry % monkey['cond'][0] == 0:
data[monkey['cond'][1]]['items'].append(worry)
else:
data[monkey['cond'][2]]['items'].append(worry)
temp = sorted([monkey['count'] for monkey in data], reverse=True)
result = temp[0]*temp[1]
print("Result 1: ", result)
def part2():
data = load_input()
rounds = 10000
worry_factor = m.prod([monkey['cond'][0] for monkey in data])
for _ in range(rounds):
for monkey in data:
for _ in range(len(monkey['items'])):
old = monkey['items'].popleft()
monkey['count'] += 1
worry = eval(monkey['op'])%worry_factor
if worry % monkey['cond'][0] == 0:
data[monkey['cond'][1]]['items'].append(worry)
else:
data[monkey['cond'][2]]['items'].append(worry)
temp = sorted([monkey['count'] for monkey in data], reverse=True)
result = temp[0]*temp[1]
print("Result 2: ", result)
def main():
part1()
part2()
if __name__ == '__main__':
main()
Monkey 0:
Starting items: 97, 81, 57, 57, 91, 61
Operation: new = old * 7
Test: divisible by 11
If true: throw to monkey 5
If false: throw to monkey 6
Monkey 1:
Starting items: 88, 62, 68, 90
Operation: new = old * 17
Test: divisible by 19
If true: throw to monkey 4
If false: throw to monkey 2
Monkey 2:
Starting items: 74, 87
Operation: new = old + 2
Test: divisible by 5
If true: throw to monkey 7
If false: throw to monkey 4
Monkey 3:
Starting items: 53, 81, 60, 87, 90, 99, 75
Operation: new = old + 1
Test: divisible by 2
If true: throw to monkey 2
If false: throw to monkey 1
Monkey 4:
Starting items: 57
Operation: new = old + 6
Test: divisible by 13
If true: throw to monkey 7
If false: throw to monkey 0
Monkey 5:
Starting items: 54, 84, 91, 55, 59, 72, 75, 70
Operation: new = old * old
Test: divisible by 7
If true: throw to monkey 6
If false: throw to monkey 3
Monkey 6:
Starting items: 95, 79, 79, 68, 78
Operation: new = old + 3
Test: divisible by 3
If true: throw to monkey 1
If false: throw to monkey 3
Monkey 7:
Starting items: 61, 97, 67
Operation: new = old + 4
Test: divisible by 17
If true: throw to monkey 0
If false: throw to monkey 5
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import networkx as nx
import string
import math as m
def load_input():
with open('input') as fd:
data = list()
start = None
end = None
for i, line in enumerate(fd):
temp_line = list(line.strip())
if 'S' in temp_line:
j = temp_line.index('S')
start = (i, j)
temp_line[j] = 'a'
if 'E' in temp_line:
j = temp_line.index('E')
end = (i, j)
temp_line[j] = 'z'
temp = [string.ascii_lowercase.index(v) for v in temp_line]
data.append(temp)
return data, start, end
def weight_func(n0, n1, attr):
return 1 if attr['w'] <= 1 else None
def create_graph(data):
graph = nx.DiGraph()
for i in range(len(data)):
for j in range(len(data[0])):
if i+1 < len(data):
graph.add_edge((i, j), (i+1, j), w=data[i+1][j] - data[i][j])
graph.add_edge((i+1, j), (i, j), w=data[i][j] - data[i+1][j])
if j+1 < len(data[0]):
graph.add_edge((i, j), (i, j+1), w=data[i][j+1] - data[i][j])
graph.add_edge((i, j+1), (i, j), w=data[i][j] - data[i][j+1])
return graph
def part1():
data, start, end = load_input()
graph = create_graph(data)
result = nx.shortest_path_length(graph, source=start, target=end, weight=weight_func)
print("Result 1: ", result)
def part2():
data, _, end = load_input()
starts = list()
shortest = list()
for i in range(len(data)):
for j in range(len(data[0])):
if data[i][j] == 0:
starts.append((i, j))
graph = create_graph(data)
for start in starts:
try:
temp = nx.shortest_path_length(graph, source=start, target=end, weight=weight_func)
shortest.append(temp)
except nx.exception.NetworkXNoPath:
pass
result = min(shortest)
print("Result 2: ", result)
def main():
part1()
part2()
if __name__ == '__main__':
main()
abcccccccccccccccccaaccccccccccccaaaaaaaacccccccccccaaaaaccccaaaaaaccaaaaaaaaaaaaaaaaaccccccccccccccccaaacccccaaaaaaaacccaaaccccccccccccccccccccccccccccccccccccccccccccccccccaaaaa
abccccccccccccccccaaacaacccccccccccaaaacccccccccccccaaaaaacccaaaaaaccaaaaaaaaaaaaaaaaaaaacccccccccaaacaaacccccaaaaaaaaaccaaaaccccccccccccccccccccccccccccccccccccccccccccccccaaaaaa
abcccccccccccccccccaaaaacccccccccccaaaaaccccccccccccaaaaaaccccaaaacccaaaacccaaaaaaaaaaaaacccccccccaaaaaaaaaacccaaaaaaaaccaaaaccccccccccccccccccccccccccccccccccaaacccccccccccaaaaaa
abcccccccccccccccaaaaaacccccccccccaaacaaccaaccccccccaaaaaaccccaaaacccaaaccccaaaaaaaaaaaaaccccccccccaaaaaaaaaccaaaaaacccccaaacccccccccccccccccccccccccccccccccccaaaccccccccccccccaaa
abcccccccccccccccaaaaaaaacccccccccaacccacaaacaacccccccaaccccccaccaccccccccaaaaaaaaaaaaccccccccccccccaaaaaaacccaaaaaaacccccccccccccaacccccccccccccccccccccccccccaaaccccccccccccccaaa
abcccccccccccccccaacaaaaacccccccccccccccccaaaaacccccccccccccccccccccccccccaaaaaaaaaaaaccccccccccccccaaaaaaccccaaccaaacccccccccccaaaaaaccccccccccccccccccccccccccdccccccccccccccccaa
abccaacccccccaaacccaaacaccccccccccaaacccaaaaaaccccccccccccccccccccccccccccaaacccaaaaaacaaaaccccccccaaaaaaaccccccccaaacccccccccccaaaaaacccccccccccccccccllllllcccdddddcccccccccccccc
abaaaacccacccaaccccaacccccccccccccaaacccaaaaaaaacccccccccccccccccaaccccccccacccaaaaccccaaaaccccccccaaacaaaccccccccccccccccccccccaaaaaaccccccccccccccccllllllllldddddddddddccaaccccc
abaaaaccaaaaaaaacccccccccccccccaaaaaaaacaacaaaaacccccccccccccccccaaacccccccaaacaaccccccaaaacccccccccccccaaccccccccccccccccccccccaaaaaccccccccccccccccclllllllllldddddddddeeaaaccccc
abaaaccccaaaaaaaaccccccccaaacccaaaaaaaacccaaacccccccccccccccccaaaaaaaaccccccaaaaacccccccaacccccccccccccccccccccccccccccccccccccccaaaaccccaaaccccccccckllppppplllmmmmmmmdeeeeaaccccc
abaaaacccaaaaaaaaacccccaaaaaaccccaaaaaccccaaccccccccccccccccccaaaaaaaaccccccaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccccccaaaacccccccckklpppppppplmmmmmmmmmeeeeaccccc
abaaaacccaaaaaaaaacccccaaaaaacccaaaaaaccccccccaacccccccccccccccaaaaaaccccccaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccccccaaaacccccccckkkppppppppqmmmmmmmmmmeeeaacccc
abaaaaaccaaaaaaaaccccccaaaaaacccaaaaaaccccccacaaaacccccccccccccaaaaaaccccccaaaaaaaaccccccccaaaaccccccccaaacccccccccccccccccccccccccccccccaaacccccccckkkpppuuuppqqqqqqqqmmmeeeeacccc
abacccccaaaaaaaccccccccaaaaaccccaccaaaccccccaaaaaacccccacccccccaaaaaaccccccaaaaaacaaaccccccaaaaccccccccaaaacccccccccccccccccccccccccccccccccccccccckkkpppuuuuuuqqqqqqqqqnnneeeccccc
abcccccccaccaaaccccccccaaaaacccccccccccccccccaaaacccaaaacccccccaacaaacccccccccaaacaaaaaccccaaaaccccccccaaaaccccccccccccccccccccccccccccccccccccccckkkkpppuuuuuuuqvvvvqqqnnneeeccccc
abcccccccccccaaacaaccccccccccccccccccccccccccaaaacccaaaaaacccccccccccccccccccccccaaaaaaccccaaacccccccccaaaccccccccccccccccccccccccccccccccccccccckkkkrrpuuuxxxuvvvvvvvqqnnneeeccccc
abcccccccccccccccaacaaaccccccccccccccccccccccaacaacccaaaaacccccccccccccccccccccccaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccckkkkrrrruuxxxxuvvvvvvvqqnnneeeccccc
abcccccccccccccccaaaaacccccccccccccccccccccccccccaccaaaaacccccaaccccccccccccccccccaaaaaccccccccccccccccaaaccccccccccccccaaacccccccccccccccccccckkkkrrrruuuxxxxyyyyyvvvqqnnneecccccc
abcccccccccccccaaaaaacccccccccccaacaacccccccccccaaaaaaaaacccacaaaacaaccaaccccccccaaacaaccccccccccaaccccaaaaaacccaacaacccaaacacccccccccccccccccjjkkrrrruuuuuxxxyyyyyvvqrqnneffcccccc
abcccccccccccccaaaaaaaacccaaacccaaaaaccccccaacccaaaaaaaaacccaaaaaacaaaaaaccccccccaaacaaacccccccaaaaaacaaaaaaacccaaaaacaaaaaaaaccccccccccccccccjjjrrrtttuuxxxxxyyyyyvvrrnnnfffcccccc
SbccccccccccccccccaaaaacccaaaaccaaaaaaccccaaaaaacaaaaaaaaacccaaaacccaaaaaccccccccaaaaaaacccccccaaaaaaaaaaaaaaccaaaaaccaaaaaaaaccccccccccccccccjjjrrrtttxxxEzzzzyyyvvrrrnnnfffcccccc
abccccccccccaaaccaaccaacccaaaaccaaaaaacccccaaaaacaaaaaaaaacccaaaaccaaaaaacccccccccaaaaaaccccccccaaaacaaaaaaacccaaaaaaccaaaaaacccccccccccccccccjjjrrrtttxxxxxyyyyyyvvrrrnnnfffcccccc
abcccccccccaaaaccaacccccccaaacccaaaaaacccaaaaaaaaaaaaaaaaacccaacacaaaaaaaacccccaaaaaaaacccccccccaaaacccaaaaaaccccaaaacccaaaaacccccccccccccccccjjjrrrtttxxxxxyyyyyyywvrrnnnfffcccccc
abcccccccccaaaacccccccccccccccccccaaaccccaaaaaaaaaaaaaaaaaacccccccaaaaaaaacccccaaaaaaaaaccccccccaccacccaaaaaaccccacccccaaaaaacccccccccccccccccjjjrrrrttttxxxyyyyyyywwrrroooffcccccc
abccccccccccaaaccccccccccccccccccccccccccaaaaaaaaaccaaaaaaaccccccccccaaccccccccaaaaaaaaaaccccccccccccccaacccccccccccccccaaccccccccccccccccccccjjjjqqqqttttxxyywwwwwwwwrrooofffccccc
abcccccccccccccccccccccccccccccccccccccccccaaacacccccaaaaccccccccccccaacccccccccccaaacaaacccccccccccccccccccccccccccccaaacccccccccccccccccccaacjjjjqqqqqttwwwwwwwwwwwrrrooofffccccc
abcccccccccccccccccccccccccccccccccccccccccaaccccccccccaacccccccccccccccccccccccccaaacccccccccccccccccccccccccccccccccaaacccccccccccccccccaaaaaajjjjqqqqttwwwwwwsswwrrrrooofffccccc
abcccccaaaaccccccccccccccaacaaccccccccccccccccccccccccccccccccccccccccccccccccccccaacccccccccccccccccccccccccccccccaaaaaaaaccaaaacccccccccaaaaaacjjjiqqqtttwwwwsssssrrrrooofffccccc
abccccaaaaaccccccccccccccaaaaacccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaaaaaaaaccaaaaacccccccccaaaaacciiiiqqttswwwssssssrrroooogffccccc
abccccaaaaaacccccccccccccaaaaaacccaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccaaaaaccaaaaaaccccccccaaaaacccciiiqqqssssssspppooooooogggaccccc
abccccaaaaaaccccccccaacccaaaaaaccccaacccccccccccccccccccccccccccccccccaaaaccccccccccccccccccccccccccccccccccccccccccaaaaaaccaaaaaaccccccccaaaaaccccciiiqqsssssspppppoooooggggaacccc
abccccaaaaaccccccaaaaacccaaaaaacaacaaaaaccccccccccccccccccccaacccccccaaaaacccccccccccaaaccccccccccccccccccccccccccccaaaaaacccaaaaacccccccccacccccccciiiqqqpssspppppgggggggggaaacccc
abccccccaaacccccccaaaaaccccaaaccaaaaaaaacccccccaacccccccaaccaacccccccaaaaaacccccccccaaaacccccccccccaaaaccccccccccccaaccaaacccaaacccccaaacaaaccccccccciiqqppppppphhhggggggggaaaacccc
abccccccccccccccccaaaaaccccccccccaaaaaccccccccaaacaaccccaaaaaacccccccaaaaaaaccccccccaaaacccccccccccaaaacccccccccaaaaaacccccccccccccccaaaaaaaccccccccciiippppppphhhhggggggcaaacccccc
abaacccccccccccccaaaaaccccccccccccaaaaaccccccccaaaaacccccaaaaaaacccccaaaaacaaacccccccaaacccccccccccaaaacccccccccaaaaacccccccccccccccccaaaaaacccccccccciiiippphhhhhhcccccccaaacccccc
abaacccccccccccccccaaacccccccccccaaacaaccccccaaaaaaccccccaaaaaaacccaaccaaacaaaaccaaaccccccccccccccccaaacccccccccaaaaaaacccccccccccccccaaaaaaaacccccccciiihhhhhhhhaaaccccccccccccccc
abaaccccccccccccccccccccccccccccccaacccccccccaaaaaaaacccaaaaaaccaaaaaacccccaaaacaaaaaccccccccccccccccccccccccccaaaaaaaaccccccccccccccaaaaaaaaaccccccccciihhhhhhcaaaacccccccccccccca
abaaccccccccccccccccccccccccccccccccaacccccccaacaaaaacccaaaaaaccaaaaacccccccaaaaaaaacccccccccccccccccccccccccccaaaaaaaacccccccccaaacaaaaaaaaaacccccccccccchhhaccccaacccccccccccccca
abaaccccccccccccccccccccccccccccccccaaaaaaccccccaaccccccccccaaccaaaaaaacccccaaaaaaaccccccccccccccccccccccccaaaccacaaacccccccccccaaaaaaacaaacaaaaaacccccccccaaacccccccccccccccaaaaaa
abccccccccccccccccccccccccccccccccccaaaaaccccccaaccccccccccccccaaaaaaaacaaaaaaaaaaccccccccccccccccccccccccaaaaaaccaaaccccccccccccaaaaaacaaacaaaaaacccccccccaaaccccccccccccccccaaaaa
abccccccccccccccccccccccccccccccccaaaaaaaacccccccccccccccccccccaaaaaaaacaaaaaaaaaaaaacccccccccccccccccccccaaaaaacccccccccccccccaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccaaaaa
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:
line = line.strip()
if line:
data.append(eval(line))
return data
def check_order(packet1, packet2):
ordered = True
stop = False
if packet1 and not packet2:
stop = True
ordered = False
elif not packet1 and packet2:
stop = True
elif not packet1 and not packet2:
pass
else:
for item1, item2 in zip(packet1, packet2):
if isinstance(item1, list) and isinstance(item2, list):
stop, ordered = check_order(item1, item2)
elif isinstance(item1, int) and isinstance(item2, list):
stop, ordered = check_order([item1], item2)
elif isinstance(item1, list) and isinstance(item2, int):
stop, ordered = check_order(item1, [item2])
else:
if item1 > item2:
ordered = False
stop = True
elif item1 < item2:
stop = True
else:
pass
if stop:
break
else:
if len(packet1) > len(packet2):
ordered = False
stop = True
elif len(packet1) < len(packet2):
stop = True
else:
pass
return stop, ordered
def part1():
data = load_input()
result = 0
for i in range(len(data)//2):
_, ordered = check_order(data[2*i], data[2*i+1])
if ordered:
result += i + 1
print("Result 1: ", result)
def part2():
data = load_input()
order = [[[2]], [[6]]]
for i in range(len(data)):
for j in range(len(order)):
_, ordered = check_order(order[j], data[i])
if not ordered:
break
else:
j += 1
order.insert(j, data[i])
result = (order.index([[2]]) + 1) * (order.index([[6]]) + 1)
print("Result 2: ", result)
def main():
part1()
part2()
if __name__ == '__main__':
main()
[[0,5,[[],[],2,[7,9]]],[[8,8,3,[6,3,8,9,1]],[2,0,10,7,10],4,10,[9,[1,8],4,[4,0,5,10],[4,0,8,8]]],[9,10],[],[0,[[]],4,10]]
[[],[4,7,3,6,[2,[10],[2,5,10],5,2]],[[1,10,[6,9],3],[6,10,8,[1],[10,7,3]],[[7],[10,9,9,2],1,7],7],[3,7,9,[[4],0]],[[4],[[9],0,9,[]],[7,[],[],[5,7]]]]
[[10,[[10,7,3,0,10],10],[[8,7,7,2,8]],0],[0,7,4],[2,10,[],[8,[7,10,10],1,0],[2,8,6]]]
[[[7,6,5,[]],[[10,0,4,1,6],[5,9,10,6],[1,5]],[7,[6],[10,5,6,7,1]]],[2,[3,[7],[4],7,[4,4]],[],0,[]],[5,[1,6,6],[8,9,[1,1]],[5]]]
[[[[3,9],5,[5],[0],5],[],[4,[6,2,2],[10],[],7]],[[],0]]
[[],[[3],6],[10,[[4,1,10],[2,7,6,0],[0,8,9],[7,0,3,4,4],7],[[7],3,[3,2],[],4]],[[[10,2,7,8]]],[10]]
[[10,6,7,0,[1,7]],[[[3,5,9,1,10],[],1,2,[0,9]]],[4,1,[4,4]],[1,2,2,5],[[5,[8],[]],7,[1,3,[4,1],5],[[10,7,9,2,2],[]],[[3,0,10,7],0,[],[0,3,9,7,3]]]]
[[[],[4,[5],4,[5,5,8,9,1]],[7,10,[8,8,6,2],[],[3,3,6,2]],[3,3]],[],[5,[4,[10,6,6],[]],[[0],[4,7,0],[2,9],[9,4,3,8]]],[[3,[7,0,2,10,3],1,10,10],0,9,[[8,1]],[2]],[8,[[10,2],5,[0],[8,3]],[5,[4,1],[9,8],[0],9]]]
[[8]]
[[[[6,5,8,3],1,[1,5,5,5],[9,5,0,1],[7,0,0,4]],[[6],10,[3,2]],3,6,[10]],[4,[3,[1],10,[5,5,7,3]],[[6,2,5,0,5],[0],[7,5,4],[4,9]],[]],[],[[[4]],[4,[5,3,6,5,0],[2,6,1,6]],2,[[4,2,8,1],[6,2,7],[7,7,10,7],2],2]]
[[],[],[[[7,9,4,8]],[[5,1]],[7,[8],[9,1,5,4],2,[]],4],[2],[[[2,10],[9,7],[3,6,9,9,7],5,2],8,0]]
[[],[0,1,6]]
[[[[2,8],7,[]],[[7,6,10,3,2],3],4],[],[[[4,10],4,[1,3,8]],5,4],[[7],7],[]]
[[[]],[0],[3,[7,[5,3,2,5,6],2,[3,1],10],[8,10,[3,8]],7]]
[[4],[[[7,9,8],3,6],[[],8,[2]]]]
[[[8,3,[3,5]],0],[3,[[9,2],[2],7,1],10],[[3,[0,6,6],10,[5],[1,7,0]]],[],[6]]
[[6,8],[7,[[],[1,4,3,6],[7,8,9,2,10],8,7],8,9],[6,7,[[10]],[[4,8,9]]],[[[6,3,6,1]],[[8,10,10,0,5],[1,4,4,7,5],1,[0,2,1],5]],[5,5,[[2],10,[],6]]]
[[[[],4,7,0,7],[[1,2],0,[7,1,4],[6,2],[8,6,2,1]],0]]
[[2,[[5,4,10],3,[9,0,8,7,4],4,6]],[[[8,10,7]],[2,[]],5],[[]],[4,9,[],7],[9,[[6],0,[]],[7,[],2],0]]
[[[[5,5,0,2,9],6,2,1],[10],[[4],[10,6,6,10],[]]],[],[6,[]],[0,1]]
[[9,6,[3],[1,5,[9,2,4],[4,1,6],[]],[[]]]]
[[5],[9,[],3,8]]
[[8,[[7],1,8,[2,6,4],8]],[]]
[[],[],[[0,[],9,[0]],[[3],[4,6],[8,6,5,8,0]],6],[],[]]
[[10,0,[[],5,[4,4,10,9,8]],8],[],[3,[[0,3]]]]
[[[[0,9,4],[7,3,9,4]],[4,[0,5,7,10,3],0,9]]]
[[[[0,8,8,0,4],[7,10,5,10,6],9,8,10],[[0],[],[0],10]],[9,8,[[8,7,5,5,10]]],[1,[10,4,1,[10,4,10,0,1]]],[[[1,9],9,5],3,1,[[7,6]],[]]]
[[3,1,[[9,5,8],7],[3]],[[9],7,4,[]]]
[[7,3]]
[[[[4,2],[3,3],4,7,[1,2]],5],[[6,[2,9],[10,3,6,4,2],[2],3]]]
[[[6,[]],[[4]]],[],[3,[[7,2,1],[],[8,9,9,10],[9],10],9,1]]
[[[1,7,[7]],10],[[6,8,2,[0,9],2]]]
[[[2],9],[[[2],[5,4,0,9]],[10,3,2,[0,0]],[[1,6,10,0,1],[3,5,6,7],[8],[1]]],[[8],[6,10],8],[9,0]]
[[]]
[[[],[4,3],6,[[],[9,5,3,9],[9,5],2,3],5],[4,[2,2,9,6,5],2],[[],2,[[],[5,6,6]],[10,[7,2,4,2,9],8]]]
[[5,[7,[],[0,4,3,10],4,9],10,[[4,8]],10],[[[2,5,5],6,0,[5],[9,3,2,10]],[[5,4,8],[3],[1]]]]
[[5,[[7,2,1,10,0]],[1,[4,0,5]]],[0],[[],10,[]],[10,[[9,3],[0],3],[7,9,3,[]],1]]
[[[4,2],1,4,7],[[[],9,[3,5,8,7,6]]],[[6,3,4,[8,2,5,2,5],[9,8,3,1,9]],1,[[10,9]],[[1,4,1],1,8,[2],[10,3]],10],[[[],1,1,[]],0,9],[7,[6,[7,2,2,6,0],7,5],[[3,10,10,0],1,[1,8,4],[1,1]],[[7,7,6,2,4],2]]]
[[5,7],[],[6,[4,8]],[8,[3,[10,2,0,5,6],[9,0,7,8,8],[0]]],[2,4,7,[]]]
[[],[4,[5,0,3,6]],[5],[]]
[[1,1,8],[[[1,10,3],1,[6,6,6],6]]]
[[[4,10],0,9,[[1],[3,5],[10],4,[7]],1]]
[[[0,5,10,2]],[[]]]
[[[8]],[[[8,9,0]],10,[[9,7,5,3,6],[9,7,3]]],[6],[2,[[4,7],[6,9,8],[10,0,8,0,0],[9,4,3,10]]]]
[[[],[[],7,[10,1,8,4,0],6,[10,2,2,6]],[[5,7,10],[9,9,5,5,0],6,[6,2],10]],[],[]]
[[],[7],[[[7,3],6,8,9,[2]],[[7,8,6,2],[],9],3,[[9,0,8,10],9,[1,9,7,0],[6,9,1],8]]]
[[8,[[10,8,5],[],[4,0,6]]]]
[[3,4,[0,3,7],2],[[2,6,9,4,0],[1,[6,10],10,[4,5,1,9],0],[10]],[7,[[0,2],[3,5,10,1],9,[6,9,0,1]],8,9],[],[[[1,10,8,10,7],[4,9,5,2,1],5],10,4,7]]
[[[[9,9,4,6,8]],3,2,10,6],[[[2,0],6,[9,10,0,1],[1,0,7,7,1]],[9,10,3,[1]]],[4,6,2,[2,2,5,[9],3],4],[[8],10,[9,[],[],[1]],8,[[],3]],[4,4,[10],7]]
[[[9,[9],[4,0,10],[3,0,4,4]],8,[0,[4,8,0,5],[5,2],[0]],8,1],[6,0],[5,0,3,4],[[[2]],1],[]]
[[[10,3],6,6,10]]
[[[7]],[],[[0,[0,3,7],[],[5,0,2,6]],[2,[8,9,3,9]],[]]]
[[],[[1,8,[0,10,3,7,2],5]],[[9,[4,7,7,6,10],[4,9,3]]],[[[9,4,4,9]]],[[[9,6,8,1]],2,4,[],5]]
[[1,[],[10,6],9]]
[[3,1,4,8],[[],[1]],[]]
[[2,[5,[]],[]],[[2,1,8,6,[4,10,2,7,3]],4,[[9,0,2,3,7],8,10,4],5,[[],[10,9]]],[[4,[9,6,3,9],2,0]],[[[3]],[]]]
[[1,[9],[[],4,[7,9,9],[1,4],[2,6,4]],3,2],[[],6],[[[0,7,3,2],2,2,[5],[3,7,8,3]],10,1],[[[],[],0,[0],[7,4,5]]],[[9,[3,3],[6,8],[10]],2]]
[[9,7,[],[0],0]]
[[],[[5,5],[9],10,2],[],[[6,4,[5,6,9,1,2],2,8]]]
[[[[8,3,5,10,1],[3,4]],[9],[[3,10],9,7,[]],6],[2,10,[10,2,0],[0],[1,1,[2,4,0,8],[7,1,6,3],[8,10,8,1,4]]],[[[0,9]],[[7,2,1,3,4],6,[7,5]]],[8,10],[7,6]]
[[],[[[10,8,8,6,2],2,10,[8,6,7,7,3]],9,1,[[3],9,9],[[5,2,9],2,0,[10,1],5]],[[],6,1],[[[3,2,4,7,3],[],9,[9,2,3],3]],[[[]],1,7]]
[[7,[[7,2,8,9],9],[8,[0,3],[3,5],[5,8]]],[9,[0,3,10,1],[[4,8],4,[3,7,5],[6,2]],[[],6,[5,2]]]]
[[],[0,[[0,0,1,3,8]],6]]
[[10,6,8,8,[]],[9,[[7,4,8,1,4],6,[7,4,5],1],[[7,3,10,5],2],[[1],0,1,7],[6]],[[7,[4,7,9,6],[9],[6,3,3,3]],[6,[10,0,5,8],10,1,6],7,[9,0,2,1,9]]]
[[1,[[4,1]],7],[],[[6,0,5,[9,10,0,6,0]]],[[6,[],[]],[[9,2],9,7],7],[8,10]]
[[[6,4,8],[8],0,[5],2],[7,6,7,1],[10,10]]
[[[[10,8,9,6,10],5,4,0,8],[[7,1,5,0,8],[2,5,5,4,2]],[[2,2]]],[[[6,2],1,[],3],[8,3,5,1],[[7],[0,4,2],4,[0,2,6],[1,6,3]]],[6,[3,0,[6,8]]],[[[9],[6],9,[2,3,9]],5,[7,[8]]]]
[[5,4]]
[[[[],[2,1,4,2],3],[1,9,[8,2,4,10]],[5]],[[1,2,[10],7],10]]
[[7,[],[[10,5],5,1],[5]],[3,3],[1,7],[[[1],9],1],[9,[[7,2,6,6,0],[]],[],[]]]
[[1],[[],3,[4]],[0,9],[[[10,10,6,8,9],4,3]]]
[[[10,10,4,3,[7,10,7]]],[[3,10,9,[8,6,10,5],1],[[7,7],1,0],[5,[4,8,7],6,4,5],1,[[3,5,5,8],[5,9]]]]
[[0,4],[[]],[[4,3,1,4],2,[8,2,1],1]]
[[[0,[4]],[[0,6,0],4,8],[10],5],[],[[4,[10,1,8]],8,[]],[7],[]]
[[[[7,7,3,4],[4,5,0,8],2,[1,6,5,10]],[[2,0,1],10,[2],4],1,2,[10,[7,7,7,2],[]]]]
[[[10,[8,3,0,5,4],6,3,[4]],2],[[10,6,[],[10]],2,5],[[]],[[],[8]]]
[[[7,5]],[[[7,5,4,1,2],8,9,[7,10,6],10],[[8,3,2],[1,1,5,4,4],2],0,5,6],[],[5,7],[5]]
[[3,[[4,2],5,10,8],10,[[5,8,8],3,[6]]],[[[4,7,9,3,4],0,[9],4],[[9,9,3]],[10,6,[3,9,10,1]],2],[9,8]]
[[5],[7,10,[7,[7,5,5,10]],[[3,8,9,10],[],[3,6],5,5]]]
[[[],6,[[],7,5,[6,3,2,10,5]]],[]]
[[[[4],5],[10,4,[6,2,1,3,3]],8,[[]],1]]
[[5,[]],[[[3,7,7],[2],2]],[6,7,[[6,1,3,5,8],[0,0],2,[10,8]],[9,[2,10,5,0]],4],[0,1,[1,[7,1]],9,[6,1,2]]]
[[8],[[[7,7,6,3]],6,5],[[6,10,2,1],[[],9],[5,[],7,3,[9,4,0,2]],[[10,1,9,1,2],9,8]],[]]
[[],[[3,[7,1],0,6,[3,8,3,10,4]],9],[6,4],[10,[9,8,[2,6,0],[2,3,0,0]],[[10,7],[9],3],8],[10,[],[8,[3,5,0,9,1]]]]
[[10,3,4,9,3]]
[[[4,[7,9,9,2,7],[],[],4],3],[1,9],[]]
[[10],[[[0,4,2]],3,8],[7,[0,[2,10,4,3],[5,1,5],2,10],[7,[],1,[],[1,9,7,4,7]]]]
[[5,[3,[7,6]],[6,7],2],[4,[2,[]],[[6,10,4,10],[5,1,0],10,5,1],[[4,10,0,7,5],4]],[]]
[[[[6],10],1,[[10]],9],[7,4,10,10],[2,0,[8,0]],[8,9],[6,[[10,2,7,0,1],1,[0,5,3,7,2],[6]],4]]
[[[[],[2,2,6,0],[5,10,0,10,0]],3,[[3,7],3],5],[],[[],3],[7,[[7,4,8],9,2,[2]],[[1,3],[5,3,2],10],[10,3,[10,6,9,3]],[7,[9,6,0]]]]
[[2,[[3,8,10,9,7],[2,5],[],10,0],[1,8,2,[]]],[10,[5,[2,8,2],5,3]]]
[[],[0,[]],[[1,[],[0,7,0,1,8],[]],[[4,1,8,5],[5,10]]]]
[[[[3,9,9,9,7],3],[0,[6,2,6,4,7],2,[7,9,9,7,8],[0,3,1,5]],[1,[2],[8,5,8,8,10],[7,3,2,10],[2,7,8]],7],[[],7,3,[9,6]],[[2,[0,8]],[1,4,[8,3,0,10]]]]
[[[]]]
[[8,2,3,1,0],[2,[5,[3,5,0,3],7],3,[1]],[10,[[9,4,0],3,[2,0],6],[[]],10]]
[[[[9,3,0],[6,9,6,10],2,[],[5,9]],0],[3,5,[],[4,9,[0,0]]]]
[[6,2,[6,[4,0],[4,5,8,7,1]],[[0,0,1],[9,5,3,1],2,[5],[1,5,7,4]],4],[8,[],[[0],[],[4,5]]],[6,[[10]],1,[1,5,1,10,[7,5,8,2,7]],[[7,1,2,1]]],[6,2,7,[6,[4,3]],[[7],10,[3],4]]]
[[[[3,1,4,10,3],3],8],[3],[1,[5,[5],8,[9,10]],[[]],[4,[1],8,[]],[[],5]]]
[[[10,6],[[1],6,0],[9,2,2],[4,[4,6,10,7,9]],6],[],[[],3,1,4,10],[]]
[[[10,[4,1,7,7],9]],[[[3],[4],[1,3,0]],8],[[7],[6,[0,6,0],[1,8,5,3],[0]],0,6],[],[9]]
[[1,1,[6,[],6,[2,4,10],[9,10,4,3,7]],7,2]]
[[[[0,9,2,6],[0,10,1,8,7],[10,10,6,1],5,[9,2,9,1]],[3],5,10],[0,[[3,1,10,8],[],[],[7,9]],[[10,1,2,10]]],[[1,[10]],[],[[2,4,0,1,5],1,4,3],9,[2,[3,7],[],8]]]
[[[6,1,7,7],4,[[6]],[[6],[9,4],[3]]],[[],[[10,0,2],[9,1,10,1,6],1,[1,8,2],[]]],[],[[],9,[6,0,2],[[],3,9,[6],[1,0,6]]],[[2,[6,7,7,6,7],2,[4,0,0,3,2]],[7],[8,[4,10,0,7,2]],0,4]]
[[4,[[10],2],[]],[[3,[2],[10,0],2],6,2],[[3,[],[],[5,5],6],[0,6],5,[3],[7,[3,8,1,3],6,10]]]
[[],[1,[[],4,[1,10],[5,6,7],[7,8,1,2]]],[[8,1],[0,[]],2,[]]]
[[[[5,5,5],9,9],[],[0,[4,6,9],9,7],4],[[[],0],8,[1,[0,0,10,9,4],[3,5]]],[[8,1],[[]],[[3,5],3,[4,10],4],[9,[8,0,6,10,7],[3,4],10],7]]
[[3,[[0,0,10,10,0],6,[7,8,5,10,9],[3,5,1],[10,1,9,7]],7,[10,3,[0,5,8]],10]]
[[],[[],[[10],8,[3,5,2],[10,4,0]]]]
[[1,8,[[],1,7]],[4],[[[2,6,8,10],0,3,5],[[8,6,7],9,[],[4,2,2,1,0]]],[6,10,0,[[8,0,6,4],[9,7]],5]]
[[2,[3,[5,0,9],7],[[1,4],1,2,[10,8,8,0]],[4,8,2,4]],[9,[],[[3,4,6],[2],[4,6,10,5],0],4]]
[[6,4,[2,[9,5,8,2,1],10,5],[[6,7,8]],2],[],[]]
[[1,[5]]]
[[],[5],[5,[2,[0]],[[5,0,3],4,8,0],3,1]]
[[9],[[[8,8,3,5],[1,1,2],10]],[1],[[[]],[[8,6,8,9,8],7],[10,4,10,[1,3,3,7]],4],[]]
[]
[[[[]],5,[9,[],9,[6,4,1,3]],7],[10,5],[2,9,[[4,1]],6,3],[[6,1,[4,0,10],[3],2],4,[]],[[5],[[2,1,8,7,6],9],[6,6,[10,7,6,5,8],[2,6]],[],7]]
[10,6,2,5]
[10,6,2,5,4]
[[[],6],[],[],[]]
[[],[[],[5,2,[9],[]],2]]
[[1,1,1,2],[],[[9,6,2,9]],[],[7,7,1,[8,4],5]]
[[[7,7,0,4,[2,9,4,7,1]],2,10,[10,[],[5],6],3],[[],[[7],[10,10,4,9,0],[10],1],[],[[10,0,10,9,1],[0,8,2,10],4]],[6],[],[2,5,3]]
[[],[[2,8,[1],[5,2,5,2],[2,9]],[10],[10,6,7,[0,4,8,10,2],[]],[]],[[10,[2,2,0,5],2],[[6,0,3,8,5],[9],[],10],[],[[8,7,10],6,8,3]],[[[5],5,5,[0,3],[10,3]],[1,4,5,[]]],[1,2]]
[[[[],8,4,8]],[],[]]
[[[[10,4,6],[],1,[]],[[3,4],[7,5,4,2],[],0,[10,10]],[[0],[6],[6,5,2,10,4],3,6],[[8,10,4,3],2,0,[3,4,8]],5],[[[3],7,3,[5,5,4,2]]]]
[[[7],1,7]]
[[0,6],[[],[[9,8,10,2],[0,9,5]]],[2,[],9,[[],8,[2,4]]],[4,6,0,3,4],[[[3]],0]]
[[[[6]],5],[[9,[6,10,0,7],[3,8,7,4]],0,[],[[1],[7,4]]],[[[1,5,6],6]]]
[[3],[[[7,7,2,0,7]],[0,4,10,7,[10,0,4,1,6]],[[4,7,9],5],[[6]],7],[[[5],[],[],[1,5,10,6],3]]]
[[5,[7,3,[9,4,10,7],[1,4,10,4],[]],[9,2,1]],[1,7,[[],[0]],7,0],[],[2,[[5,1,0,7]]]]
[[8],[7,0],[6,5,[[],[],8,[5],1],7,[]]]
[[8],[],[7]]
[[[],[[6,1,6,9,8],1],[[8,7,8,0],10,[8],8]],[[[]],[[6,6,9,5],[0,2],7,3,[5,9]]],[]]
[[],[0,[[],[7,5],[3,10,7],7],[[9,4],10],[[5,7,8,7]],[]],[],[8,9,3,6]]
[[[[9,8],6],3,0,[[3,7],[5,1,0,2],10]],[7]]
[[],[],[6,0,10,[],[2]],[[[1]],[7,3,[10,10]]]]
[[8,[8,10,6,4,10],[],1,[[8,0,1],9]],[0,0,3],[],[[[],[3,6],8,[]],1]]
[[9,[[6,3,3,7],5,[2,9,5,8,0],[6,7,8,4],10],[3,4,[8,4,1,10,10]]]]
[[2,[[4],[0,8,3,10,4]]]]
[[[2,[0]],[5,[3,4,1,0],6,[1],1],3,4,9],[6,1,3,6],[7,[10,0,1,[8,10,8,0,6]],9,[[8,4,2],0,6,8,0]],[],[[[6,0,6,8],1]]]
[[6,[[9,10,4,3,9],1],9],[[[9,2],[],[3,2]],[[4,7,8,3,5],0,[5],[10,5,6,0,6],[2,10,3,6,8]],[6,[]],[5,[4,5,9,10],[1,0,1]]],[[[2,1,9,9],[10,6,4,1,8],[],5,[2,10]],8,[[1,1,8],4,[2,4,0]],7]]
[[10,[1,[2,3,0,6,9],1,[],[8,4,1,6,1]],3],[[[2],[]],[],7],[],[2,6],[10,4,6,6,[[],[9,8]]]]
[[10],[[9,[8,9,5],3,9],7],[[[9,8,10,5],3,6],10,5,10],[5,1]]
[[2,3,[]],[1,[[2,1],5,3,[7],0],5,[]],[[],[1,4,[]],[6,[1,4,8,3],9,[2,3],8],10,3]]
[[[],[9]],[[[7,2],9,[4,8,6],[0,3,9],[8,8,1,4,1]],7]]
[[2,[10,6,[5,0,9,5]],10],[[[3,3],6],[[6,8,2,5],[8,6,0,5]],[[1,7],4]],[0,[[3],[]],[[2,6,9,1],9,[4,2,5,0,2],9,[7]],[9,7,6,[2,2,9,5]],6],[[3,4,[6,9]],2,[4],3,[[1,9],[0,2]]]]
[9,0,10,9,1]
[9,0,10,9]
[[[5],[7,0,9,2],2],[[3,[0],[]]],[6,[]]]
[[3,[2,[0,4,5,1],[9,0]]],[9,2,[6],[3]]]
[[[9],[0]],[1],[[[4,5]],3,10,5,10],[8,9,0,1],[[2,[10,5,5,2,3],[9,2,1,0,4]],[1,10,7,[10,9,7,4]],1,1]]
[[0,2],[8,[[9,4,9,2],10,[9,8],4],7,5,6],[6,5]]
[[],[4,[[7,1,3,7]],[]],[],[[[],2,[3],3],[[7,0],6],3,[7,4],[]]]
[[4,8,6,2],[[[]],6,10,[[4,10,5,0,1],6,6],[]],[1]]
[[[[7,8,0,9,3],[8]],[[6,10],[10],2,0,1]],[],[[1,[3,9,4],0,[]],[[],2],[8,[8],[5,7],[],9],[2,10],7],[3,[2,[3,8,5],3,2],6],[[1,[3],[4,10,3],5,[6,5]],[[]],2,[],4]]
[[[],[6,6,[10],7],[10,[10,8],5,[10,8,3]],[5,10,4,8]],[3,10,6],[[[2,2],[5,2],[3,0,10,0,4]],[[8,9,2,9,0],1],1,[[10],6,0,8]],[8,[10,6,[1,3,9]],7,8,[3,[6,10],[7,6,4,5,1],[10],3]]]
[[[[5,9],[1,1]],3],[],[6]]
[[6,[9,7],[[6,0,7,10],[10,6],[4,3,3,7],10,[4,6,4,4,10]]],[1,[[2,0,0],[7,0,10,1,7],[9]],[10],4],[[8,10,9,[6,7,0,2,7],10],[[6]],[],[9],[]]]
[[0,7,[[3],[0,3,6,8],[7,8,4]],[]],[3,[9,5],9,[4,5,[6,8,2],[7,3],7]],[]]
[[],[[[3],[5,7,10,7],9,[3,9,6,5,7]],[[10],[4,3,10,9,3],[]]],[[[0,5,7,3,2]]]]
[[10,7,0],[],[1,5,7,[],5],[1,4,[0,4,[3],[2]]],[[4],7,7,[9,1],9]]
[[2,[2,[],[5,7,2,1,6],[8,9],[7,7]],[]],[1,3,[[],[3,9]],[6,2]]]
[[3,3,0,[4]],[],[[7,0,[2,1,5,4,1],7,[0]]],[8,[6,3,4,7],10,[3]]]
[[[1,[1,8,8,10,0],[5,7,6],[5,1],8],[3,0]],[[7,[],9,6,[9]],4,[[2,3,0],6],[],5],[10,[],[[],10,[5,9,3,2]],[1,3,[],0]],[6,[[2],1,4,3,4],7,2],[1,[[3],10,3],6,9,[[3,8,3,8],2,[4],9,9]]]
[[[8,[3,8],[0,5],[8,8,2,4,7]],[4,[4]]],[1,7,8,2],[[1,7],[[3],3,[8,3],[6,4,2]],3,[[8,3,6,9,1],[4],[6,5,1]],[[3,6,1,5]]]]
[[4],[]]
[[5,[[0,9],[10,10,10,2,2],[1,5,8,2],[8,4,9,0]],9],[[6,[8,8,5,4,7],8,[],[7,9]],8,[],[[7],7,8,[2,2,0]]],[[[2,4],7],[8,6,[],[9,1]],[],[10],[[6,7,0,5,5],4,7,[5,1,9,10]]],[],[[[1,3,1,0],[7,7]],[6]]]
[[[[8]],6,[[6],[],9]],[[[1,3],2,4,9,7],[5,[4],0,1],6],[5],[[],1,[],[[8,1,2,10,7],[7,9],9,5,4],1],[]]
[[[],5]]
[[4,[],9,6],[2,1,[[4,5,10,0,1],10,1]],[],[7,[[2,2]],9,[[3,0,7,5,1],[1,10],2,[]]]]
[[[9,4,[2,2,5,1]],[7,0,[9,2,1,9,6],5,[7,8,0,5]],[[8]]]]
[[[4,6],[[],[],3]],[],[[[4],9,[9,2,5]],[6,[1,7,6],[9,3,1,2,9]],[[2,3,0],4,0],[2,4,[0]],4],[10,[3,10,6],[1,10,5],9]]
[[[0,8,2],6,[[4,0,4,7],[1],[2,8]],[[3],10,5,4,[8,0,9,4,0]],8]]
[[[],[],5,[[8,0]],0],[9,6]]
[[[]],[10,4],[10]]
[[],[[3,[]],[6,[6,6,2,2]]],[[0,9,10,7,[8,4]],6,5,[[1,8,2,2,10],9]],[[[8,7,0],5,3],4]]
[[],[4,[6,[2]],[[3,10],[3,2,0],3],[[],10,[9,8,0,2,9]]]]
[[[[6,1,0,10],9],[6,[2,4,10,10,10],3,6,[6]],[],7,5],[[],[7,[10],5],[[2,3,2],0],1],[[[],10,5],[[7],[],5,[8,1]],3,10]]
[[9],[4,[3,5],7,4,7],[[],[5,2,[1,4,0]],[6,[1,9,3,3],[]],6,10]]
[[[[3,2,0,5],4],[7,[3],[6,7,0,5],0]],[9,4,9,2],[[]],[[[2,7]],[10,9,8],8],[]]
[[],[4,[6,10],6,[[],7],[[3,0,5]]]]
[[[[1,3]]]]
[[],[[[],9],[5,[2,8],[6,7]]]]
[[8,4]]
[[4,[2,2,[1,8,3,6,5]]],[2]]
[[5,4,[[7,4,8]],1,0],[10,[],[[1]],[5,[]]]]
[[10],[],[3,1,[[],0,0],0],[[9,6],2,[[9,9,8,2]]]]
[[10,[4],[[],[5,5],7,[3,1,2,10,0],10],1],[3],[[],9]]
[[[[5,6,8,3]],1,[5],10],[[[2,3,5,3,6],0,10,[2,3,7]],[]]]
[[[[],[2,1,10],[],[4]],[[6,1,1],10,4]]]
[[8,[9,[2],[0,6,2,3,7]],4]]
[[[3,[6,5,1,6,10],[1,5,4,1,3]],[7],[],[10,10,4],[[9,4],[7,4],0,2,[2,5,6,7,4]]],[[],[8,4,3,[0,7,6,7,5],6],[[10]],[[1,7,9,5,8],[1,4,5,9,6]]],[6,2,[]],[]]
[[[[2,7],0,[2],[0,0,0,10],[]]],[2,[[2,8,9,3,3],4,4],9,[1],[10,3,[8,7],[9,6],5]],[[[],[9],[6,5,3]]],[[0,[7,3,0],[],[]]]]
[[],[[4,0,[5,0],[8,9,4],[10,6,9,6,1]],[0,[1,3,10,9],0,5],1]]
[[[10],[[9,1,1,3],8,10,6],[[0,7,6,7],8,[7,10],[10,8,0,2,8],[7,7,10,1]],8,[2,0,[4,9,6],4,[2,5,5]]],[10]]
[[10,[],5],[3]]
[[[[3,5,7,8,5]]],[[[8],[2,7,8,2],[8,6],[5,9,10,2]]],[[],[[]],10,[[7,5],6,[]],[9,[5,3,8,0],5,5,2]]]
[[[[9],4]],[5,9,8,[]],[[]]]
[[],[[[4,2,4]]],[4,9,8,[3,0,[3,6,3,1,5]]]]
[[7,[[1,9,7,5,0]],[]],[1,[6],3,9],[3,2,1,[[2]],8],[[[10,5],[8],10]]]
[[],[8,5,[[]]],[],[[9,0],[],2,9,8]]
[[2,0,[5,3],6],[[],[10,[0,5,9,9,10],7,[5,8,1,8],[8]]]]
[[[]],[[0,6,[7,8,0],3,[9,6,2,5,2]]]]
[[],[[],[]],[[[],2]],[1,9,2,8,6]]
[[],[[[9,2,5],[3],3],1],[7,[[]],[7,6,[7]],[[],[8,0,2,9,9],5,7],1],[[2,[7,4,4],3],[[6,9],[1,10,0,7]],[5],10,3],[]]
[[[],[[0,4,5,4,6],1]]]
[[2,5,6],[[[4,7,4,6]],8,4,4,[[8,4,3],[5,1,8],5,[6,4,0,6,0]]]]
[[6,[[1,5],0,3,7],[],[]],[],[[[1,3,8,0],[6,2,1,0],9,1]],[0,[[0,9,1,7]],[0,1,[1,6]],7]]
[[[3,[4,2,8,0]],0],[0,[[8,3,5]],[7,7,[],10,[0,2,2,4,6]]],[6,[[6,9,8]],[0,[4,9,6,0,9]],[],6]]
[[],[6,10,[],[[0,1,5],1],0],[[]]]
[[[[3,10,1,6],[5,0,9,9],[10,10,10]],6,[3,9],8],[[[1,7,2,6],[],9],6,3,[8,9,[5,5],[0,5,9,4,5],[]]],[10],[[2,0],[[0,1,2],[],[10,5,2],4],2,[[6],[],0,[1,5],2]]]
[[[9,6,[5,8,9]]]]
[[4,[[7,0],1,[8,0],1,7],[],[[2],[1,6],[0,5,3],[0]],[[8,10,5]]]]
[[3,6,[[],2,1],4,[[1],5,9,[10,0,0,5]]],[[1,[2,1],6,10,1],8,[3,[4,0],4,1],[]]]
[[6,9,1],[],[2,4],[[2,5,[]],[[6,7,10,5],4,9],5]]
[[[0,3,4,8,[0,9]],8,10],[[[4,0],[8,8,2,9],[],5,1],[5,[0,0,5,9],[5,10],7],8,[4,[3,0,4,7,0],5],[[9]]],[5,1,6,10],[]]
[[6,[1,2,10,[]]],[[],10,1,9,[[9,5,7],3,[4,5,10,5],5,[1]]],[]]
[[[[10,7],1,1,4],10,6,[7],[10,5,[]]],[1],[[[8,2,5,7],[],[],8],[],[6,4,[],[10,8]]],[9,1]]
[[4,[[],1],[5,[6],0,1,[9,0]],[[7,6,2,1,10],[0,5],[3,4],1,[8,2,4]],[9,3,1,[]]],[]]
[[[[0],1,[5],7,[4,0,1,7,1]],[10,10,[1,9,9,4,6],9],[[4],6,[0,0,10,0]],4]]
[[0,10,[0,[10,10,6,7,1]],4,[[0],[7,10,5]]],[]]
[[10,[],6,[10],[10,[2,5,4],3,3,0]],[9]]
[[],[[[7,1,2,9,4]],8,[8,5,7,3,[9,10,4,9,1]],[3,[6],[1],7],10]]
[[[],[0,8,[3,6]],10,[[10,0],[6,8,5],2,8,[5,10,2,0,5]],10],[[[6,0]],5,8]]
[[7,[[10,0,4],7],[0,[3,7,7,10,3],10,[2,4,2,0,10],6]]]
[[5,5,9]]
[[3,[10,[10],4,0]],[[[3,7,7],[0],[]],0],[[10,6,9,7],[5,[3,7]],[[7,9,8],0,5],10],[],[0,5,10,8]]
[[0,[10,1],10],[8],[7,[4,3,5,[2,5,6,3]],[[2,0,10,4],[7],[9,9,6],[1,5]]],[]]
[[],[],[7,[2,9,0]],[]]
[[[[3,5,0],9],1,7,9],[1,[[9,2],[5,3,0,10],[9],0,[0,8]],[[10,0],7,[4,8],1,0],[[7,7,3]]]]
[[],[],[],[],[[4,1,6,[],10],[[7,2,2,1,1],[],[5],[8,8,7]],1]]
[[0,[[8,9],[10,0,9],5,5]],[[]]]
[[10,[10,9,[10,0,2,2,2]]],[[1,5,[10,9,7,6]],3]]
[[0,6],[10,[[4,5,7,0],3],2],[]]
[[[[8,10,3]],[[10,3,10,4,0],5,[1,5],2],3],[6,[5,[3,10,3,4],[1,1,10,0,6],2],10,[],[[10],7,6,2,10]],[[[7,10],4,2,[],[5,0]]]]
[[],[]]
[[[3,[10,2]],[[2]]],[[[8,5],[0],4,[],[5]],[4,[7,2],[9,1,8,7],[7,7],5],[],[10,[8,7,5,3],3,[],[8,4,2,7,2]],[[1,8,4,5]]]]
[[0,[3,8,9,8],[1,6,1]],[[],[],[0,[4],5,5,[1,7]]],[3,[[6,1],2],[],[[7,10,4,4],[6,9,9]]]]
[[7,[9,9],7,6]]
[[1,[]],[[],0],[3,[6],[[6],1,5,3]],[1,[],[[5,4,9,10],5,5],[],[[1]]]]
[[6,0]]
[[[[2,3],4,[6,4,5,5]],9]]
[[5,10],[10,6,[0,[7,4],[2,3,6]],0]]
[[3,[3,3,1,[5,2,1,5],[8,6,2]],[[9,10,4],2]],[7,[[5]]],[[]],[6,[],[[10,2,7]],[[9,7,3,6]]],[[[8,7,7,5,5]],5,8,2]]
[[6,9],[3,[1,9,[]],10]]
[[[]],[3,10,[[2,4,2,1],7,9,3,[0,7,1,7,4]]],[[8,5,[],[0,2,7],9],7,7,[],[[],[9,7,7,2],[10,0,3,2]]],[[],[4,[6],6,[0,7,1,4,3]],2,[[1,6],0,[6]]],[[],1,[4,10,[3,8,9,2,8],5],[0,1,8,[3,4],8],[[10,8,2],1]]]
[[9],[]]
[[9,[1,7,4]],[[[6,10,3,3,4],8,1,[8,2,2,1,1],2],[[4,9,9,0],[9,1],[7]]]]
[[7,[[0,4,7],[5,1,9,7,6]],5]]
[[5,1,[[4,7,0,8,4],0],3,[]],[[[2,1],[8,3]]],[[],[],[[4,7],3,4,1,[5,6,6,0]]],[[4,9,10],2,[6,[1,10,9]]]]
[[[4,[8,8,4,2],[2]],[[5,8,4,5,6],[2,4]],2],[[],8,[[6,1,0,9,0]],[2,6,[7,1,10,9,7],6,3]],[[0,6,[6,5]],10,10]]
[[3,[9,[6,2,1,7],9,5],8,9],[],[],[]]
[[6],[],[7],[[[6,4,0],[10,7,1,2,0],[7,6,7,7],[3,6,10]],8]]
[[3,4,1],[4,4],[],[[1],5,5,10,[]],[[8,0],[8],[[5,1,10],3],[4],[[10,2,3],3,5]]]
[[3,[1,2,[10,2,4,4],[],5]],[0,[],6],[10,[],[[],[1,4,10]],2]]
[[1,[5,[7,7,6],[10,8,10],9,[8,8,10]]],[],[[[3],[7]],[9,[4]],7]]
[[8,3,[7,4,8,[7,3,0]],10]]
[[[8,0],[7],2]]
[[[0],[6,8,9,2,[6]]],[[[2],10,3,[2]],8,2,2,3],[[5,5,[10,10,3,7],[9,1,7,8,7]],[10,1],[[1,10,7],6,[8,5,1,6],5]],[]]
[[[],2]]
[[],[[4]]]
[[0,10,4],[[2],0,10],[]]
[[[],[4],[[],7,5],0,[10,8]],[[9,[9,1,5,6,4],6,10,[2,1,9]],4],[[],[]],[6,[[]],0,5]]
[[7,[1,2,0]]]
[[9],[[[9,3],8,[4,2,7,2,2],2,[10,6,1,0,8]],[3,2],[9],[7]],[[0],[[4,7],[],3,[],3],2,9,[]],[[],9,[2],3]]
[[3,2,[[7,0,3],[9],[1]],[8]],[],[[[],[10,8,4]],9,[],[]]]
[[4,8,[6,3,[9]]],[[[],3,6,[7,3,3],[5,3,8]],[9,[],5,6,[6,0,2,4,4]],2,8],[]]
[[10,7,8,7,3],[[[9,8,2,1],[0,5],[9]]],[[[7,3,7,7,3]]],[[7,[],8],[9],[2,[1,4,8],[3,4,2,4,5],[],9],[9,[7]]],[[],5,[9,[10,6,5],[0,2,8]]]]
[[1,[0],1],[]]
[[[[7,5,2,5,8],[8,10,1,4,6],10,[10,10,5,1],8],[[2,4,8,1],[],3,0,[2,4]],[[2,0],7,7,[4,3,6]],6],[],[[[6],1],[0,[0,9,3],3]],[5,6,7]]
[[[],[],[[4,0,3],[],[3,3],[1,2,5,4,6],[5,8,0]],[7,[5],10,10,1]]]
[[],[[[1,1,5,3],6],4,8,7],[1,[[7],[]],10,0,[]],[[[],[5,2,2,5,4],8],8,2],[5,[9,[10,5,2,9,8],8],10,10]]
[[3],[[[6,4]],9,1],[6,8]]
[[],[[[5],[5,3,2,10,7],10,[7,9,1,5],2],[6,8,[6,8,1,0,10]],[[]]],[[],4,[[],[5,2,10,1],0,8],4,10],[[],[3,[0,6,0],[5,1,4,4],3,[3,1,9,2]],[3,2,3,2,[6,6,7,6,5]],[],9]]
[[5,9,3,[],[9,7,[]]]]
[[[0,9,8,[10,3],[10]],1,[3,[10,3,4,5],[8,4,2,3,6],[9,8,10,5,8]],[8,[5,3,7],[6,2,2],[5,9],[7,9,4]],[10,5,10]],[3],[1,0,[[8,8],[]]],[9,[],[5,8,[5,2,9,2,0],[10,4]],[[9,9,8,4,0],5],[]],[[[],[8,2]],[[9,9,6,6,7],[4],2,[]],[7,9]]]
[[[6,[1],6,[1],9],[7,[6,2,1],[3,1,1,7]],[[9,5,1],5,[1,2,2,8,5],2,2]],[[]],[[9,6,4,0]]]
[[[],[[2],[1,5],[7,10,0,9,2],8,9]],[4,[8],4,6]]
[[2,6,6],[10,10,4]]
[[[[1,7],5,0],3,10,3],[1,[7],0,[[9,6,3],[10,0,5,7],[10],[5,10]],3],[10,[]],[5,[6,2,10,7,[1]]]]
[[3,[3,2,[8,6,2,6,10],[0],[]],[]],[5,[[],[8],[8],[8,5,2],[9,8,10,8,9]],7,[0,[7,6,7,2]],9]]
[[],[4],[[[10],[2,3,4],[7,3,4,0]],3,[10]],[3,[[4],6,10],[3,10,7,[],3]],[5,4,0,[],6]]
[[[[0,7]],[9],[[],[],5,[7,6,8,0]],3]]
[[3,[[3,5],6,8],7],[[[3,4]],[],[0,[8,3,2,3,3],0,[5,10,3,7],[0,6]],[[2,2,3,10,10],9,[0],[]],[]]]
[[3],[5,7,10,10]]
[[10],[],[[0,[9,2,9,0],[5],[7,6,2],[7,3,6,4,9]],10,[8],2,7],[[[7,3,2,3,9],[7,5,2,9],[10,10,3,4,8],[2,7,9,8],0],[[10,3,1,1],[0],6]]]
[[[10,7,8]],[[],[1,[8,4,0]],2,7],[],[[[8,9,6]]]]
[[[]],[3,0]]
[[6,4,[2,9,10],[[5],4,[],7],2]]
[[],[4,9,3,10],[4],[[[10,7],4,[8,10,4,2]],6,[5,3,5,1,[7,9,4]],[[]],[]]]
[[7,[[4,7],7,[2,8,2]],5,7,[[5,0,7,8,0]]],[[5]],[[0,[3,9]],8,[1,4,2],[[10,1,3,5,0],[4],[],3]],[[[6,4],[4,9,9,4]],[],[]]]
[[5,[0,[6,8,7,3],2],[9,4,[7],[0,3,7]],3],[3,[[9,6]],[[],[4,7,6,8,0]]],[2,5],[9,2,5]]
[[[[1,3]],8],[5,8,6,[0,[6,6,4],[]],7],[[7],[[],3,7,1],[],[[9,10,6],[5],[6,7,6],[3,3,3,8],[]],[[],7]],[],[7,[8,[1,8,1,0]],[4,1,[2,5],1],[[6,10]]]]
[[[10,9,[0,10,10,1]],[[9],[10,0,2],4,9]],[[[4,8]],0,[5,[3],4,3,4],3],[],[],[[]]]
[[4,6,[[10,0,2,6],[3,5,8],3],3],[],[],[],[8]]
[[[],[[],4,10],9],[[3,[],[8,6,9],9,1],1,10,[[1,4,6],[0],2],[[1,7,9,7,0],[3,10],2,[2],[2,9]]]]
[[],[[1,[6,2,10]]],[],[[[7,9,2,8],[5,1,2],9],3,[10]]]
[[[2]],[10,[10,6,8],8,[8,0,10,2],10]]
[[2,8]]
[[[[5],[9,9,6],[1,8],[5,4,6,0,2]],[[5,9],[]],[7,[4,2,3,4],6]],[],[1,9,7,[6]]]
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():
with open('input') as fd:
data = list()
for line in fd:
temp = line.strip().split('->')
temp = [tuple([int(j) for j in i.split(',')]) for i in temp]
data.append(temp)
return data
def get_dir(a, b):
return tuple([np.sign(j-i) for i, j in zip(a, b)])
def calc_pos(a, b):
return tuple([i+j for i, j in zip(a, b)])
def create_field(data):
field = dict()
for rocks in data:
for i in range(len(rocks)-1):
d = get_dir(rocks[i], rocks[i+1])
pos = rocks[i]
while True:
field[pos] = "rock"
if pos == rocks[i+1]:
break
pos = calc_pos(pos, d)
return field
def process_sand_part1(field):
start = (500, 0)
pos = start
end = max([key[1] for key in field.keys()])
while True:
next_pos = calc_pos(pos, (0, 1))
if next_pos in field:
next_pos = calc_pos(pos, (-1, 1))
if next_pos in field:
next_pos = calc_pos(pos, (1, 1))
if next_pos in field:
field[pos] = 'sand'
next_pos = start
if next_pos[1] == end:
break
pos = next_pos
def process_sand_part2(field):
start = (500, 0)
pos = start
end = max([key[1] for key in field.keys()]) + 2
while True:
if start in field:
break
next_pos = calc_pos(pos, (0, 1))
if next_pos in field:
next_pos = calc_pos(pos, (-1, 1))
if next_pos in field:
next_pos = calc_pos(pos, (1, 1))
if next_pos in field:
field[pos] = 'sand'
next_pos = start
if next_pos[1] == end:
field[pos] = 'sand'
next_pos = start
pos = next_pos
def part1():
data = load_input()
field = create_field(data)
process_sand_part1(field)
result = sum([1 for value in field.values() if value == 'sand'])
print("Result 1: ", result)
def part2():
data = load_input()
field = create_field(data)
process_sand_part2(field)
result = sum([1 for value in field.values() if value == 'sand'])
print("Result 2: ", result)
def main():
part1()
part2()
if __name__ == '__main__':
main()
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
495,26 -> 495,27 -> 507,27 -> 507,26
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
502,42 -> 502,45 -> 496,45 -> 496,51 -> 507,51 -> 507,45 -> 506,45 -> 506,42
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
506,30 -> 510,30
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
548,117 -> 553,117
503,33 -> 507,33
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
539,149 -> 544,149
489,38 -> 489,39 -> 503,39 -> 503,38
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
533,111 -> 538,111
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
489,38 -> 489,39 -> 503,39 -> 503,38
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
510,76 -> 510,78 -> 503,78 -> 503,84 -> 521,84 -> 521,78 -> 516,78 -> 516,76
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
544,114 -> 549,114
502,42 -> 502,45 -> 496,45 -> 496,51 -> 507,51 -> 507,45 -> 506,45 -> 506,42
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
533,161 -> 538,161
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
547,161 -> 552,161
510,76 -> 510,78 -> 503,78 -> 503,84 -> 521,84 -> 521,78 -> 516,78 -> 516,76
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
531,100 -> 531,102 -> 524,102 -> 524,105 -> 538,105 -> 538,102 -> 535,102 -> 535,100
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
510,76 -> 510,78 -> 503,78 -> 503,84 -> 521,84 -> 521,78 -> 516,78 -> 516,76
549,146 -> 554,146
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
546,149 -> 551,149
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
514,73 -> 524,73 -> 524,72
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
502,42 -> 502,45 -> 496,45 -> 496,51 -> 507,51 -> 507,45 -> 506,45 -> 506,42
539,155 -> 544,155
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
557,152 -> 562,152
553,149 -> 558,149
499,53 -> 499,54 -> 509,54 -> 509,53
535,133 -> 535,136 -> 530,136 -> 530,140 -> 547,140 -> 547,136 -> 540,136 -> 540,133
502,42 -> 502,45 -> 496,45 -> 496,51 -> 507,51 -> 507,45 -> 506,45 -> 506,42
510,76 -> 510,78 -> 503,78 -> 503,84 -> 521,84 -> 521,78 -> 516,78 -> 516,76
514,73 -> 524,73 -> 524,72
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
535,133 -> 535,136 -> 530,136 -> 530,140 -> 547,140 -> 547,136 -> 540,136 -> 540,133
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
534,117 -> 539,117
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
502,42 -> 502,45 -> 496,45 -> 496,51 -> 507,51 -> 507,45 -> 506,45 -> 506,42
543,152 -> 548,152
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
510,76 -> 510,78 -> 503,78 -> 503,84 -> 521,84 -> 521,78 -> 516,78 -> 516,76
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
542,146 -> 547,146
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
509,33 -> 513,33
535,133 -> 535,136 -> 530,136 -> 530,140 -> 547,140 -> 547,136 -> 540,136 -> 540,133
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
502,42 -> 502,45 -> 496,45 -> 496,51 -> 507,51 -> 507,45 -> 506,45 -> 506,42
506,36 -> 510,36
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
500,36 -> 504,36
535,133 -> 535,136 -> 530,136 -> 530,140 -> 547,140 -> 547,136 -> 540,136 -> 540,133
535,133 -> 535,136 -> 530,136 -> 530,140 -> 547,140 -> 547,136 -> 540,136 -> 540,133
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
550,152 -> 555,152
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
536,158 -> 541,158
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
495,26 -> 495,27 -> 507,27 -> 507,26
535,133 -> 535,136 -> 530,136 -> 530,140 -> 547,140 -> 547,136 -> 540,136 -> 540,133
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
537,114 -> 542,114
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
530,114 -> 535,114
502,42 -> 502,45 -> 496,45 -> 496,51 -> 507,51 -> 507,45 -> 506,45 -> 506,42
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
545,143 -> 550,143
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
499,53 -> 499,54 -> 509,54 -> 509,53
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
489,38 -> 489,39 -> 503,39 -> 503,38
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
531,100 -> 531,102 -> 524,102 -> 524,105 -> 538,105 -> 538,102 -> 535,102 -> 535,100
510,76 -> 510,78 -> 503,78 -> 503,84 -> 521,84 -> 521,78 -> 516,78 -> 516,76
531,100 -> 531,102 -> 524,102 -> 524,105 -> 538,105 -> 538,102 -> 535,102 -> 535,100
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
495,26 -> 495,27 -> 507,27 -> 507,26
512,36 -> 516,36
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
531,100 -> 531,102 -> 524,102 -> 524,105 -> 538,105 -> 538,102 -> 535,102 -> 535,100
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
527,117 -> 532,117
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
531,100 -> 531,102 -> 524,102 -> 524,105 -> 538,105 -> 538,102 -> 535,102 -> 535,100
531,100 -> 531,102 -> 524,102 -> 524,105 -> 538,105 -> 538,102 -> 535,102 -> 535,100
536,152 -> 541,152
531,100 -> 531,102 -> 524,102 -> 524,105 -> 538,105 -> 538,102 -> 535,102 -> 535,100
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
497,23 -> 497,21 -> 497,23 -> 499,23 -> 499,17 -> 499,23 -> 501,23 -> 501,20 -> 501,23
535,133 -> 535,136 -> 530,136 -> 530,140 -> 547,140 -> 547,136 -> 540,136 -> 540,133
541,117 -> 546,117
499,53 -> 499,54 -> 509,54 -> 509,53
516,97 -> 516,94 -> 516,97 -> 518,97 -> 518,87 -> 518,97 -> 520,97 -> 520,92 -> 520,97 -> 522,97 -> 522,94 -> 522,97 -> 524,97 -> 524,95 -> 524,97 -> 526,97 -> 526,89 -> 526,97 -> 528,97 -> 528,89 -> 528,97 -> 530,97 -> 530,94 -> 530,97 -> 532,97 -> 532,91 -> 532,97
540,111 -> 545,111
527,130 -> 527,122 -> 527,130 -> 529,130 -> 529,121 -> 529,130 -> 531,130 -> 531,129 -> 531,130 -> 533,130 -> 533,121 -> 533,130 -> 535,130 -> 535,122 -> 535,130 -> 537,130 -> 537,128 -> 537,130
543,158 -> 548,158
503,67 -> 503,59 -> 503,67 -> 505,67 -> 505,60 -> 505,67 -> 507,67 -> 507,60 -> 507,67 -> 509,67 -> 509,58 -> 509,67 -> 511,67 -> 511,60 -> 511,67 -> 513,67 -> 513,59 -> 513,67 -> 515,67 -> 515,61 -> 515,67
536,108 -> 541,108
510,76 -> 510,78 -> 503,78 -> 503,84 -> 521,84 -> 521,78 -> 516,78 -> 516,76
540,161 -> 545,161
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import re
def get_dist(a, b):
return sum(abs(i-j) for i, j in zip(a, b))
def load_input():
sensors = list()
beacons = list()
pattern = re.compile('Sensor at x=([-\d]+), y=([-\d]+): closest beacon is at x=([-\d]+), y=([-\d]+)')
with open('input') as fd:
for line in fd:
line = line.strip()
match = pattern.search(line)
sensors.append((int(match.group(1)), int(match.group(2))))
beacons.append((int(match.group(3)), int(match.group(4))))
return sensors, beacons
def part1():
sensors, beacons = load_input()
line = 2000000
positions = list()
for sensor, beacon in zip(sensors, beacons):
d = get_dist(sensor, beacon)
d_y = abs(sensor[1] - line)
d_x = d - d_y
if d_x >= 0:
x_min = sensor[0] - d_x
x_max = sensor[0] + d_x
positions.append([x_min, x_max])
positions.sort(key=lambda x: x[0])
fp = [positions[0]]
for pos in positions[1:]:
if fp[-1][1] >= pos[0]-1:
if fp[-1][1] < pos[1]:
fp[-1][1] = pos[1]
else:
fp.append(pos)
result = sum([j - i for i, j in fp])
print("Result 1: ", result)
def part2():
sensors, beacons = load_input()
x_limit = 4000000
y_limit = 4000000
for y in range(y_limit+1):
positions = list()
for sensor, beacon in zip(sensors, beacons):
d = get_dist(sensor, beacon)
d_y = abs(sensor[1] - y)
d_x = d - d_y
if d_x >= 0:
x_min = sensor[0] - d_x
x_max = sensor[0] + d_x
positions.append([x_min, x_max])
positions.sort(key=lambda x: x[0])
fp = [[0, 0]]
for pos in positions:
x_max = pos[1] if pos[1] < x_limit else x_limit
x_min = pos[0] if pos[0] > 0 else 0
if fp[-1][1] >= pos[0]-1:
if fp[-1][1] < pos[1]:
fp[-1][1] = x_max
else:
fp.append([x_min, x_max])
if fp[-1][1] == x_limit:
break
if len(fp) == 2:
x_sol = fp[0][1]+1
y_sol = y
break
result = x_sol*4000000 + y_sol
print("Result 2: ", result)
def main():
part1()
part2()
if __name__ == '__main__':
main()
Sensor at x=2302110, y=2237242: closest beacon is at x=2348729, y=1239977
Sensor at x=47903, y=2473047: closest beacon is at x=-432198, y=2000000
Sensor at x=2363579, y=1547888: closest beacon is at x=2348729, y=1239977
Sensor at x=3619841, y=520506: closest beacon is at x=2348729, y=1239977
Sensor at x=3941908, y=3526118: closest beacon is at x=3772294, y=3485243
Sensor at x=3206, y=1564595: closest beacon is at x=-432198, y=2000000
Sensor at x=3123411, y=3392077: closest beacon is at x=2977835, y=3592946
Sensor at x=3279053, y=3984688: closest beacon is at x=2977835, y=3592946
Sensor at x=2968162, y=3938490: closest beacon is at x=2977835, y=3592946
Sensor at x=1772120, y=2862246: closest beacon is at x=2017966, y=3158243
Sensor at x=3283241, y=2619168: closest beacon is at x=3172577, y=2521434
Sensor at x=2471642, y=3890150: closest beacon is at x=2977835, y=3592946
Sensor at x=3163348, y=3743489: closest beacon is at x=2977835, y=3592946
Sensor at x=2933313, y=2919047: closest beacon is at x=3172577, y=2521434
Sensor at x=2780640, y=3629927: closest beacon is at x=2977835, y=3592946
Sensor at x=3986978, y=2079918: closest beacon is at x=3998497, y=2812428
Sensor at x=315464, y=370694: closest beacon is at x=-550536, y=260566
Sensor at x=3957316, y=3968366: closest beacon is at x=3772294, y=3485243
Sensor at x=2118533, y=1074658: closest beacon is at x=2348729, y=1239977
Sensor at x=3494855, y=3378533: closest beacon is at x=3772294, y=3485243
Sensor at x=2575727, y=210553: closest beacon is at x=2348729, y=1239977
Sensor at x=3999990, y=2813525: closest beacon is at x=3998497, y=2812428
Sensor at x=3658837, y=3026912: closest beacon is at x=3998497, y=2812428
Sensor at x=1551619, y=1701155: closest beacon is at x=2348729, y=1239977
Sensor at x=2625855, y=3330422: closest beacon is at x=2977835, y=3592946
Sensor at x=3476946, y=2445098: closest beacon is at x=3172577, y=2521434
Sensor at x=2915568, y=1714113: closest beacon is at x=2348729, y=1239977
Sensor at x=729668, y=3723377: closest beacon is at x=-997494, y=3617758
Sensor at x=3631681, y=3801747: closest beacon is at x=3772294, y=3485243
Sensor at x=2270816, y=3197807: closest beacon is at x=2017966, y=3158243
Sensor at x=3999999, y=2810929: closest beacon is at x=3998497, y=2812428
Sensor at x=3978805, y=3296024: closest beacon is at x=3772294, y=3485243
Sensor at x=1054910, y=811769: closest beacon is at x=2348729, y=1239977
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import networkx as nx
import itertools as it
import re
from copy import deepcopy
limit_combos = dict()
def load_input():
data = list()
with open('input') as fd:
pattern = re.compile('Valve (\w+) has flow rate=(\d+); tunnel[s]? lead[s]? to valve[s]? (.+)')
for line in fd:
match = pattern.search(line.strip())
valve = match.group(1)
rate = int(match.group(2))
neighbours = list(map(lambda x: x.strip(), match.group(3).split(',')))
data.append((valve, rate, neighbours))
return data
def create_power_set(data):
result = dict()
for i in range(1, len(data)):
for combo in it.combinations(data, i):
key = tuple(sorted(combo))
result[key] = [0, 0]
return result
def create_graph(data):
graph = nx.Graph()
for item in data:
node = item[0]
graph.add_node(node, flow=item[1], w=0, wm=-1, valves=set())
for neighbour in item[2]:
graph.add_edge(node, neighbour)
return graph
def shortest_valves(graph, start):
shortest_valves = dict()
valves = [node for node, values in graph.nodes.items() if values['flow'] != 0]
valves.append(start)
for valve in valves:
shortest_valves[valve] = dict()
for nv in valves:
if nv != valve:
shortest_valves[valve][nv] = nx.shortest_path_length(graph, valve, nv)
return shortest_valves
def process_part1(nodes, valves, node, pressure, time, remaining, path=list(), depth=0):
cycles = 30
if path:
path.sort()
key = tuple(path)
if pressure <= limit_combos[key][0] and time >= limit_combos[key][1]:
return path, pressure
else:
limit_combos[key][0] = pressure
limit_combos[key][1] = time
path.append(node)
path.sort()
max_pressure = pressure
max_path = path.copy()
for valve in remaining:
length = valves[node][valve]
tt = time + length + 1
if tt >= cycles:
continue
tr = remaining.copy()
tr.remove(valve)
tp = pressure + nodes[valve]['flow']*(cycles-tt)
tpath, tpressure = process_part1(nodes, valves, valve, tp, tt, tr, path.copy(), depth+1)
if tpressure > max_pressure:
max_pressure = tpressure
max_path = tpath
return max_path, max_pressure
def process_part2(nodes, valves, node, pressure, time, remaining, path=set(), depth=0):
cycles = 26
if path:
temp = list(path)
temp.sort()
key = tuple(temp)
if pressure <= limit_combos[key][0] and max(time) >= limit_combos[key][1]:
return path, pressure
else:
limit_combos[key][0] = pressure
limit_combos[key][1] = max(time)
path.update(set(node))
max_pressure = pressure
max_path = path.copy()
active = 1 if time[0] > time[1] else 0
for valve in remaining:
length = valves[node[active]][valve]
tt = deepcopy(time)
tt[active] = time[active] + length + 1
if tt[active] >= cycles:
continue
tr = remaining.copy()
tr.remove(valve)
tn = node.copy()
tn[active] = valve
tp = pressure + nodes[valve]['flow']*(cycles-tt[active])
tpath, tpressure = process_part2(nodes, valves, tn, tp, tt, tr, path.copy(), depth + 1)
if tpressure > max_pressure:
max_pressure = tpressure
max_path = tpath
return max_path, max_pressure
def part1():
data = load_input()
graph = create_graph(data)
start = 'AA'
valves = shortest_valves(graph, start)
global limit_combos
limit_combos = create_power_set(list(valves.keys()))
remaining = set(valves.keys())
remaining.remove('AA')
path, pressure = process_part1(graph.nodes, valves, start, 0, 0, remaining)
result = pressure
print("Result 1: ", result)
def part2():
data = load_input()
graph = create_graph(data)
start = ['AA', 'AA']
valves = shortest_valves(graph, start[0])
global limit_combos
limit_combos = create_power_set(list(valves.keys()))
remaining = set(valves.keys())
remaining.remove('AA')
path, pressure = process_part2(graph.nodes, valves, start, 0, [0, 0], remaining)
result = pressure
print("Result 2: ", result)
def main():
part1()
part2()
if __name__ == '__main__':
main()
Valve EG has flow rate=21; tunnels lead to valves WZ, OF, ZP, QD
Valve OR has flow rate=0; tunnels lead to valves QD, CR
Valve VO has flow rate=0; tunnels lead to valves FL, OY
Valve BV has flow rate=0; tunnels lead to valves AA, KK
Valve OF has flow rate=0; tunnels lead to valves EJ, EG
Valve YZ has flow rate=0; tunnels lead to valves EL, AW
Valve EL has flow rate=16; tunnels lead to valves YZ, RD
Valve EJ has flow rate=0; tunnels lead to valves YI, OF
Valve FM has flow rate=0; tunnels lead to valves VX, FX
Valve FL has flow rate=22; tunnels lead to valves VO, FH
Valve QD has flow rate=0; tunnels lead to valves OR, EG
Valve XC has flow rate=0; tunnels lead to valves UA, GV
Valve WZ has flow rate=0; tunnels lead to valves FH, EG
Valve AT has flow rate=0; tunnels lead to valves FX, OZ
Valve MZ has flow rate=0; tunnels lead to valves UA, YI
Valve WI has flow rate=0; tunnels lead to valves OH, WW
Valve YD has flow rate=0; tunnels lead to valves OZ, WW
Valve QX has flow rate=0; tunnels lead to valves OY, YI
Valve AA has flow rate=0; tunnels lead to valves BV, ZE, PE, XL
Valve VX has flow rate=0; tunnels lead to valves FM, GQ
Valve VN has flow rate=0; tunnels lead to valves TU, OQ
Valve RD has flow rate=0; tunnels lead to valves OY, EL
Valve QR has flow rate=0; tunnels lead to valves QQ, OZ
Valve CD has flow rate=0; tunnels lead to valves WW, RJ
Valve VA has flow rate=20; tunnel leads to valve DE
Valve RJ has flow rate=0; tunnels lead to valves CR, CD
Valve UA has flow rate=19; tunnels lead to valves XC, MZ, KY
Valve WW has flow rate=4; tunnels lead to valves YD, PE, WI, DY, CD
Valve MC has flow rate=0; tunnels lead to valves ZP, XY
Valve XY has flow rate=24; tunnel leads to valve MC
Valve FH has flow rate=0; tunnels lead to valves FL, WZ
Valve DE has flow rate=0; tunnels lead to valves VA, FX
Valve DY has flow rate=0; tunnels lead to valves WW, YI
Valve FX has flow rate=14; tunnels lead to valves DE, FM, AT, OQ
Valve UU has flow rate=0; tunnels lead to valves AR, AW
Valve OY has flow rate=13; tunnels lead to valves RD, VO, AR, GV, QX
Valve CS has flow rate=0; tunnels lead to valves MG, OZ
Valve KY has flow rate=0; tunnels lead to valves UA, AW
Valve KK has flow rate=0; tunnels lead to valves BV, TU
Valve GQ has flow rate=18; tunnel leads to valve VX
Valve ZV has flow rate=0; tunnels lead to valves YI, LS
Valve QQ has flow rate=0; tunnels lead to valves CR, QR
Valve AW has flow rate=25; tunnels lead to valves YZ, KY, UU
Valve OH has flow rate=0; tunnels lead to valves WI, TU
Valve CR has flow rate=8; tunnels lead to valves OR, ZE, RJ, LS, QQ
Valve TU has flow rate=7; tunnels lead to valves MG, VN, OH, KK
Valve ZP has flow rate=0; tunnels lead to valves EG, MC
Valve AR has flow rate=0; tunnels lead to valves UU, OY
Valve OZ has flow rate=10; tunnels lead to valves YD, XL, CS, AT, QR
Valve GV has flow rate=0; tunnels lead to valves XC, OY
Valve PE has flow rate=0; tunnels lead to valves WW, AA
Valve ZE has flow rate=0; tunnels lead to valves AA, CR
Valve XL has flow rate=0; tunnels lead to valves OZ, AA
Valve YI has flow rate=15; tunnels lead to valves QX, MZ, EJ, DY, ZV
Valve OQ has flow rate=0; tunnels lead to valves FX, VN
Valve MG has flow rate=0; tunnels lead to valves TU, CS
Valve LS has flow rate=0; tunnels lead to valves CR, ZV
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
SHAPES = [[(0, 2), (0, 3), (0, 4), (0, 5)],
[(0, 3), (1, 2), (1, 3), (1, 4), (2, 3)],
[(0, 2), (0, 3), (0, 4), (1, 4), (2, 4)],
[(0, 2), (1, 2), (2, 2), (3, 2)],
[(0, 2), (0, 3), (1, 2), (1, 3)]]
def load_input():
with open('input') as fd:
data = fd.read().strip()
return data
def calc_start(shape, y_max):
result = [(y+y_max+4, x) for y, x in shape]
return result
def move_down(shape):
return [(y-1, x) for y, x in shape]
def process_jet_gas(shape, gas):
d = 1 if gas == '>' else -1
return [(y, x+d) for y, x in shape]
def is_shape_in_field(field, shape):
result = False
for pos in shape:
if pos in field:
result = True
break
return result
def parts():
data = load_input()
field = set(((0, j) for j in range(7)))
y_max = 0
jet_count = 0
prev_max = 0
# Preparation for part2
value = 0
steps = 1000000000000
# Period must be manually determined
period = 87*100
period_value = 13405
init_value = 13404
init_step = period
rem_step = steps - ((steps - init_step)//period)*period - init_step
rem_value = 0
for i in range(20000):
# Determine period
# if i%(100*87) == 0:
# Example Period
# if i%(40*7) == 0:
# print(i)
# print(y_max - prev_max)
# print("")
# prev_max = y_max
shape = calc_start(SHAPES[i % len(SHAPES)], y_max)
while True:
gas = data[jet_count % len(data)]
jet_count += 1
next_shape = process_jet_gas(shape, gas)
xs = [x for _, x in next_shape]
if not(min(xs) < 0 or max(xs) > 6):
if not(is_shape_in_field(field, next_shape)):
shape = next_shape
next_shape = move_down(shape)
if is_shape_in_field(field, next_shape):
break
else:
shape = next_shape
field.update(set(shape))
y_s = [y for y, _ in shape]
y_ms = max(y_s)
y_max = y_ms if y_ms > y_max else y_max
# Required for part2
if i == init_step + rem_step - 1:
rem_value = y_max - init_value
# Part 1
if i == 2022-1:
result = y_max
print("Result 1: ", result)
value = init_value + period_value*((steps - init_step)//period) + rem_value
print("Result 2: ", value)
def main():
parts()
if __name__ == '__main__':
main()
>>>><<><>><<<<>>>><<>>><>><><<>>>><<<<>>><<<>>>><<<>><<>>><<<<>>><<>>>><><><<>>>><<<>>><<<><<>>><<<<>><<<<>>>><<<<>>>><<<>>>><<<><><<<>>><<<>>><<<<>>>><<<<>>>><>><<>><<<>><<>><>>><<<<>><<<<><<<<><<>>><<<>><<<<>><<<><>>><<<<>>>><<<>>><<<>><>>><<<<><>>>><<<><<<>>><<<><<>><<<<><<<>>>><<<<>><<<<>>><<<<><<<>>><<><>>><>>><>>>><><<<<>>><<>>><><>>><<<>>><<<<>>><><<<<>>><<<<>>>><<><>>><>><<>><<>>>><<<<>><<<<><<<<>>><>>>><<>>><<><<<>>>><<>>><<<<>><<<>>><<<<>>>><<>>>><<>>><<<<>>>><<>>>><<><>><<<<>>><<<<>><<<><<<><<<><<>>><<<<>>>><<<<>>>><<<><<<>><<>>><>><<>><>>>><>><<<<>>><<>>><<<>>><<>>>><>>><>>><<><<<>>>><<<<>>><<<<>>><<>>>><<<<>><<>>>><<<>>><>>><<<><>>><>>>><<>>>><<>><><<<<><<<>>><<>><<><<>>>><<>>>><><<<<>>>><<<<><<<><>>><<<>><<<>>>><>><<<<>>><><<><<<<>><<<<>><<<<>>><><<<><<<>>><<<<>>><>><<<<><><<<>>>><<<<><>>>><<<>>>><<><<<><>>><<<><<<<><>>><<<>><<<>><<<><><<<>>><<><<<<>>><<<>>>><<>><>><<<>>><>>>><<<<><>>><<>>>><>>>><<>>>><>><><>>><<<>>><<<>><<>>>><<<>>>><><<>>>><<>>><<<<>>><<<<>>><<<<>><<<>><<<>>><<>><<<>><>><<<>><<>>><<>>>><<<>>><<>>>><>>>><<<<>><<<><<><<<>>><<<><<<<>>>><<<<><<<>>>><<<>>>><<<>>>><>>>><>><<<<>><<<<>>>><<<<>><<<>><><>>>><<>>>><<>><<<>>>><<<<>><<<<>><<>>>><<>><<<<>>><<<<><<<<>>><>>><><<<>>><>><<>>>><<<<><<>><<>>><<<<>>>><<>>><>>>><<><<>>><<>>><<><<>><><<<<>><<<>>><>><<<>>><><<<<>>>><>>>><<<>>><<<>><<<>>><<<<>>><>>>><<<>>><<<>><<<>>>><<>>>><>><>><<<>><<<<><<<<>><<<<>>><>><<<<>><<>><><<>>><<<>>>><<>>>><<<>>><<>>><>><>><<><<<>>><<<><<<>><><><<<>><>>>><<>>>><<<<>>><<<><>>><<<><<<<>><<<><<>>><<<<>><><<<>>>><<>>>><>>>><<>>>><<<<>>><><>>>><>><>>><<<<><<<>><<<<><<<>>>><<<<>>>><>>>><>>><<<<><<<>>>><<<>><<<><<<><<<<><<<<>>>><<><<>>>><<<>><<<<>>><<<>>><><<<><<<>>>><<<<>>><<<><>>>><<<<>><<<<>>>><>><>>>><<<<>>>><<<>>>><<>>><<<>>>><>>><<<>>><<<>>>><>>>><<<>>><<<>><><<<>>>><<<>><<<<>>><>>><<<>>>><<<<>>>><<<><<<><<>><>>><<<>>><<<><<<>><<><<<<>>>><<<<><<>>><>><>><><<<>>>><<<<>><<<<>><<<<>>>><><>>><<<>><<>>><<<<>>>><<<><<<><<<>>>><<<><<>>><<<<>>>><<><>>>><<<>>><<<<>>><<<<>><<<>><<<<><<<<>><>>><>>>><>><<<>>>><><<<<>>><>>><<>>>><<>>><<<<>>>><<<><<><<<<>>><><<>>><>>><<<>><<<>><<>>><<<>>>><<<<>>><<<<><<>>>><<<>>><><>>>><>>><><<<<><<>>>><><<<>>><<>>><><>>><<<<>>>><<<<>>>><<<>>><<<<>>><<<>>><><>><<<><<>>><<>>><<>>><<<<>>>><><<<>>>><<>><<>>>><><<<>>><<><<>>><<<<>>>><<<>><<<><<><>>>><<<>><>>>><<<<>>>><<>>>><>>><>>><<<>><<<<>>><<<><<<<>><<<<>><<<>><><<>>>><<><<<>>>><<<<>><<<<>>><<<>>>><<<>>><<<><<<<>><<<<>>>><<><<>>><>>><<<>><>><<<<>>>><<<>>>><<<><<>>>><<>>><<<<><<<<>>><<<>>><<>><<<<>><<<<><<<>><<<>><>><<>><>>><<<<>><<>>>><<>><<>><<>><<<<>>>><<>><<<<><<<>><><><<>><<<><>>>><<<>>><>>><><>><<<>>>><<>><<>><<>>><<<<><<><>><<<<>>>><>>>><<>>><><<<<>><<<<><>><<<>><<><>>><<>>><<>>>><<<>><<<>>>><<<<>>><<><<<>>><<>>>><<<>>><<<<>><<>>><<<<>><>>><<<<><<<>>>><>><<><><<<<>>>><>>>><<>>>><<<>>><<<>><>>><<>>><<<>><><<<>>>><>>><>>><>><<<<>>>><<><<<<><<>><<>><<><>><<>>><<<>>><<<>>>><<<<>><><<><><<<><<<>>><<>><>>><<>>><<<<>><<<>><<>>>><>>>><<<>>>><>>><<<>>><<<<><<>>><<<<>>><<>><<>>>><>>><<>><<>>><<<><<>>><<>>><<<>>><<<>><>><<<>><<<<>>><>>>><<<<>>><>>><<<>><<<<>>>><>>><<><<<<>><><<><<><>>><><>><<<<>><<<<><>>>><<>>><<<<>>><>><<>><>>><<<<>><<>>>><><<<<>>>><<<<>><<<>>><><<><<>>>><<>><>>><<>><>><><<><<<>><<<<>>><><<>><>><<>>>><<>><>><<<<>>>><<<<>><<><>><<<<>>><<<>>>><<<>><<><<>>><<>>><<<>>>><<><<<<>>><<><<<<>>>><<<<><<<>>><><<>>><<<<><>><<>><<<<>>><<<<><<<>>>><<<>>><<<><<<>><>><<><<<>>>><<>><<><>>>><<>>>><<<<><<<>>>><<>>>><<><<<><<<>>>><<<<>>>><<><<<><<>><<<<>>><<<>>><<>>><<<>>>><>>>><>>><>><<<>>>><<<>>><<><<<>><<<><<<><<<<><>><>>><<<>>><<<<>>><<<><<<>><>><<>>><<>>>><<<<>>>><<>>><<<><<<>>><<<<>><><<>>>><<>>>><<<<>>>><<<>><<<>>>><>>><<<>><><<<<>><<>>><<>>><>>><<<<>>>><<><<<<>>>><<<<><<<<>>>><><<>><<<<>>>><<<<><<<>><<<><>>>><<<><<<>>>><<>>><><<>>><<>>>><<<<>><<<>><<<<>><<<<>><>><<<<>>><>><<<<><<><>>><><<<<>>><>><>>><<<>><<<>><>>>><>>>><<>><<<<>><<<>><<<>>><<<>>>><><<><<><<<<><<>>><<>>>><<<>><<<>><>>><<<<>><<><>>><>>><<<<>>>><>>>><>><<<>><<>><<<>><<<<>>>><<<>>>><<>>><<>><<<><<<>>>><<<>><>>><<><>>>><<<>>>><>><>>><><>>>><<<<>><>><<<>>><<<><>><<<<>>><>>>><<<><<<<><<<<>><<>>><><<<>>><<>>><<<>>>><<<<><<<<><>>><<<<>><>>><<<<>>>><>>><<<<>>><>>>><>>>><<<<>>><<<<>>>><<<<>>><>>><<>>>><<<<>><>>><<<>><<<<>>>><<<<>>>><<<><><<<><><<><>><<<><<>>><<<><<>>><<<<>>>><<>>>><><<>>>><<>><<<<>><>>>><<<<>>><<<>>>><>><<<<>>>><<<>>>><<<>>><<<<><<>><<<>>>><>>>><>>>><<>><<>>>><><>>><<><<>><<<<>>><><<<<><<>>><<<>>><<<>>>><<<<>><<<><>><<<>>>><<<>>><<<><<<<>>>><<<<><><<<>>>><<<>>><<<<>>>><>><<<<>>><<<>>>><<>>><>><<><><>>><<<>>>><<<<><<>>>><<<>>><<<>>>><<>><<<>>><<<<>>>><<>>>><<>>>><>><<<>>>><<>>>><<>>><<<>>><<>><<><<<<><<>>>><<<<>>><><<<><<<<>>><<<>>>><<>>>><><<>>><<>>><<<>>>><><>>><<<><<<>><<<<><>>><<<<>><<<>>>><<<>>>><<<>><<>><<<>><<<<>><<>><<>>>><<<<><<<>><>><><<><>>>><<<<>>><<<>>>><<<<>>><<<><<>><<<<>>><<<<>>>><<<<>>>><<<>>>><<<<>><<<<>>><<>>><>>><<<><<<<>>><>>><<><<<><<<<>><<<>>>><<<>>>><<<<>><<<>><>>><<<<>>>><><><<>>>><<><<<>>><<<>><<>><>>><<>><<<>><<<>>>><<<>>><<>><<<>><<<<>>>><<<<>>>><<<>>>><><><>>><<>>><<>>>><<>>><<<<>>>><<>>><<>><<<>>><<<>>>><<>>><>>>><>><<>>><<<>><<<><>>>><>>><<>>>><>><<<<><<<>>>><<<>><<<>><<<><><><<<<><>>><<<>>>><<<<>><<<<>>><>><<<>>><<<><<<<>>><<>><<>>>><><>><<><<><<<>><<><>>><<><<>>><<<<>>>><<<<><<<>><<><<<<>><<<<>>><<>>><<>>>><<<<>>>><<<>>>><<>>><<>>>><<<<>><>>><<><<><<>><<<><>><<<<><<<>>>><<>>><<<>>><<>>>><<<<>>>><<>>><<<<>><<<>>>><<<>>>><<<<>>>><<<>>>><<<<>>>><>><<<<>>><>>>><>>><>><<>>><<<<>>>><<<>>>><>>>><<<><<<<>><<<>>>><><<>>>><>><<<>>><<<>>>><<><<>>>><>>><>>><>>><>><<<><>>>><<<<>><<>><<<>><>>>><<<<>><<<>>>><<<>><<<<><<<<>>><<<<>>><<<<>>><<<>><<<<>>>><<<<><<<<>>>><>>>><<<><<<<>>>><<>><<<>>><<<>>>><>>><<<<>>>><<>>><>><<><<<>><<<>><<<>>><>>>><<<<>>><<>>>><<<<><<<<>>>><<<<>>>><<<<>>>><<<>><<>><>>><<<<>>>><<<<>>><><<<<>>>><>>><<>>>><<>>>><><<<<>>>><>><>>>><<>>>><>><<>>><<<>><<>>><<><<<<>>>><<<<>><><<<>>><<<>><>><<<<>><>>><<<<>>>><<<<>>>><><><<<>>>><<<>>><<<<><<<>>>><>>><<>>><<<<><>>>><>>><<<<>>>><>>><<<<>>>><<<<><<<<>>><<<<>>>><<<>>>><<<>><<<<>>>><>><<<<>>><>>><<<<>>>><>><>><<<<>><<<>>><><>>><<><<<<><<>>>><>>><>>><>><>>><<<><><>>>><>>>><<>><<<<>><<<>><<<<>><>>>><<<<>>>><<<>>><<>>>><><<>><<<>><<<>>>><<><>>><<>><<>>>><<<>>><<>>><<>>><>><<<>>><<>>><<<<>>><>>>><<<><><<<<>><<<<>>><>>>><><>>>><<<>>>><<<>>><<<<>>>><<<<>>>><<>><<<>><>>><>>>><<<<>><<>>><<>><<<>>>><<<>><<<<><<>>>><>><>><<<<>>><<<><<>>>><<<<>>><<<><>>><<<><<<>>>><<><>>>><<<<><>>><><<<<>>>><<>>>><>>>><<>>>><>>>><>><<<<>>>><>><>>>><<>>><<<>>>><<<>><><<<<><<<<>>>><<>>>><<<<>>><<>>>><<>><<<>>>><<>><>>><<<<>>><>>>><><<<><<<>>><<<<><><<<>>><><<>>><<><<<<>>>><>>>><<<>>>><<>>><>>>><<<<>>>><<<>><>><<<><>><<<>>><>>><>>><><<<>>>><><<<<>>><<<<>>>><<<<>>><<<<>>><>>>><<<<>>><<>><<<<>><>>><<><<<><<<><<<<>>>><<<><<<<>>><<>>>><<>><<<<>>>><<<<>>>><>>><<<<>>>><>>>><<>>><><<<>><>><>>>><><>><<<<>><<<<>>>><<><<<<><<>>><>>>><<><<<<>><><<<>>><<<><>>><<><<>>><<<<>>><<<>>><<<<><<<>>>><<<<><<>>>><<<><<>>><<<><><<<<>>>><<<>>><>>><<><<<>>><<<>><<>>><>><<>><>>><>><>><>>>><<<>><<<<><>>>><<<>>><<<>><<<><><<>><<<>>><<<<>>>><>><<<><<<><<<<><<>><>><<<<>>>><<<>>><<><<<>>><<<><>><>>><>>>><><>>><<<>><><<<<>><<<><<<<>>><<<<>>><<<>>>><<>><<>>>><<><<<>>><<<<>><<>>>><>>>><<<<>><<>><<<>>>><<<>>><<<>><<<<><<<><<>>>><<<>>>><<<>>>><<>>><<<<>>><<>>>><<>>><><>>>><<<>>>><<<><<>>><<<><<<<>><<<>><<>>>><<>>>><<<>>>><<>><>>>><<<<>><>><<>>>><<<<>>><<<<>>>><<<<>>><<><<<>>>><<<<>>><<>><<><<><<>><<<<><<<<>>><>>><<>>><><<<<>><>>><<<<><<<<><<<>>>><<><<<>>>><<<<>>>><>>><>><><><<<<><>><<<<>><<<<>>><<>>>><<<><<<<><<<<>>><<>><<>>>><>><<>><<><<>>>><>>>><><<<<>>>><<<><>>>><<<<>><<>>><<<<><<<<>>><<<<><>><<<<>>>><<>>><<>>>><<<><<<>><>>><<<>>>><>><<<>><><<<>>>><><>>>><>>><<<>>>><>>>><>>>><<<><<>>><<><<<<>>><>><<><<<><<<>>><>>><>>><<>><<><>><><>>><<><<<<><<>>>><<<>>><>>><<<<>>>><<<>>><<<><<<>>><<>><<<>><>><<>><<<><<<<>><<>>>><<<<>>>><<><<>>>><<<<><>>>><<<<><><>>><<<>><<<<><<>>>><<<>><<<>>><<<<><>><<<><<>>>><<<<>>><<<>>><>>>><<><<>>><<>><<<><<<<>>><>>><<>><>>>><>><<<>>>><><<<<>>>><<<>>>><>><<<>>><>>><<>>>><<<<>>>><<<>>><<><<<<><<<<>>><>>><><<<<>>>><<<><<<>>>><<<<>><<>>><<<<>>>><<>>><<<<>>><>><<<>>>><>>><<<<><<<<>>>><<<<>><<><>>>><<<<>>><<<<>><<>>>><><<<>><>>>><<<><>><<<>>>><>><<>>>><<<>>><>><<<>><>><<<><<>>><<<<>>><<<><<<>><><<<>><><<<<>>><<<<><<<>><<>>><<>><<<><<<><<<<>>>><<<><<<><<<<><>>><><<<>>><<<<>>><<<>>><<<>>>><<<<>>><<<><<>><>>>><<>><<<>><<<<>>><>><<>><<>>>><>><>>><<<<><<<><>><>>><><<>><<<><<>>>><>><<<>><<<<><<<>>>><<>><<<<>><<<<><<<>>><<<<><<<<>><<>><<<>>>><<>>>><<<>>><<><<>>>><<<><<><<<<><<<>><<>>><<<<>><<>><<<>>>><<>>>><<<<>>><<<<>>><<<<>><>><<<<>>>><<>>>><<<<><<>>>><<><><><<<<>><<<>><><<<<>>><>>>><<><<<<>><<<<>>><><<<<>><<<>><<>><<<<><>><<<>>>><<<><<<<>>>><>>>><<<<>>><<<>>><<<<><<<>>><<<<><<>><<>>>><>><<<<><<<<>>>><<<<>>>><<>>>><<<>>><<>><<<>>><<<<>>>><<<<><>>><<>><<<<>><><<<<>>><>>><<<<>><>><<><<>>><>>><<<<>><><<<>><>><<<>><<<<>><<>><<<>><>><<>><<<>><>>>><<<<>>>><>>>><<<>><<<>>><<>><>><<<>>>><<<<>>>><>><>><<><<<<>>>><<><>>>><>>><<<>>>><<<<><<<<>><><<<<>>>><>>>><<>><<<<><<>>><<<<><>><><<<>>><<>>><>>>><><<<<><<<<>>><>>><>>>><<<>>>><>>>><<><<<>>><<>><<<>>><>><>><<<<>><<>>>><<<><><<<<><<>>><<<<><<<><<<>><>>><<<>>>><>><<<><<<<>>><<<<>>><<>><<>><>>>><<<<>>>><>><>>><>>>><<<<>><<<<>>><<<><<<>>><><>>>><<<>>><>>>><<<>>>><<<<>><<<<><<<<>>>><<>>>><>>><<<>>><<<>><<<<>><<<>><>><><>>><<><>>>><<<<>><<>><<>>><<>>>><<<<>>>><<<<><><<<<>><<<>>><<><<><<<<>>>><<>>>><<<>>>><>>><<>>>><><<<<>><<>>><<>>>><<><<>><>><<<>>><<<>>>><>><>><>>><<<<><<<>><<<<>><<<<>>><><>>><>><<>><>><>>><><<>>><>>><<<>>><>>><>><<<<>>>><<>>><>><<<>>>><><<>>>><<<>>>><>>>><<<>><<<>><<>>><<<>><<<<><<<><<<<>><<>>><>>><<<>>>><<<>><<<>><<<><<>><<<<><<<>><<<<><<<<><<<<><<<<><>>>><<<>>>><<<<>>>><<<><>>><<>><<<<>>>><>><<<<><>>>><<<<>><<><<<><>><>>>><<<><>>>><<<><<<><<<<>><<<><<<<><<<>>><<>>>><<>>><<<<><<<<><><<<<><<<>><>>><><>>><><<<<>>><<>>>><<<<>>><<<<>>>><<<>><>>><<<<>><>>><<<><<<><<>><<<><<>><<>>><<><>>><<<<><>>>><<<>><<<>>>><<<<>>><<<<>>><<<<>>><<>>>><>><>><>><<>><<<>>><>>><<><<>>><>>><<<>>>><<<><>><>><<>>><<<>><>>>><<<<>><<<<>><<<<><<<>><<>>><>>>><<<<>><>>><<<<><<<<>><>>><<>>><<<<>>><<<>>><><<<<>
this documentation is autogenerated. Add a README.adoc
to your solution to take over the control of this :-)
#!/usr/bin/env python3
import networkx as nx
import numpy as np
def load_input():
data = set()
with open('input') as fd:
for line in fd:
line = line.strip()
data.add(tuple([int(i) for i in line.split(',')]))
return data
def get_neighbors(field, point):
x, y, z = point
neighbors = []
x_max, y_max, z_max = field.shape
for i in range(-1, 2):
for j in range(-1, 2):
for k in range(-1, 2):
if abs(i) + abs(j) + abs(k) == 1:
if x+i >= 0 and y+j >= 0 and z+k >= 0 and x+i < x_max and y+j < y_max and z+k < z_max:
neighbors.append((x+i, y+j, z+k))
return neighbors
def parts():
data = load_input()
graph = nx.Graph()
x_max = max((coord[0] for coord in data))
y_max = max((coord[1] for coord in data))
z_max = max((coord[2] for coord in data))
cube = np.full((x_max+3, y_max+3, z_max+3), False, dtype=np.bool_)
it = np.nditer(cube, flags=['multi_index'])
for x, y, z in data:
cube[x+1, y+1, z+1] = True
side_count = 0
it = np.nditer(cube, flags=['multi_index'])
for val in it:
x, y, z = it.multi_index
if not val:
graph.add_node((x, y, z))
neighbors = get_neighbors(cube, (x, y, z))
for i, j, k in neighbors:
if not cube[i, j, k]:
if val:
side_count += 1
else:
graph.add_edge((x, y, z), (i, j, k))
print("Result 1: ", side_count)
# Part 2
src = (0, 0, 0)
tree = nx.bfs_tree(graph, src)
lava_nodes = set(graph.nodes).difference(set(tree.nodes))
side_count = 0
it = np.nditer(cube, flags=['multi_index'])
for val in it:
x, y, z = it.multi_index
if val:
neighbors = get_neighbors(cube, (x, y, z))
for i, j, k in neighbors:
if not cube[i, j, k] and (i, j, k) not in lava_nodes:
side_count += 1
print("Result 2: ", side_count)
def main():
parts()
if __name__ == '__main__':
main()
6,7,3
2,9,11
7,5,16
12,12,2
17,8,14
9,4,3
8,10,2
3,14,7
15,14,10
5,13,4
4,6,15
12,16,7
9,6,18
3,10,13
10,12,17
7,3,12
10,3,4
12,17,6
8,8,18
6,14,6
15,6,14
5,16,9
2,5,12
11,16,13
4,8,14
10,8,2
1,9,11
6,17,11
16,13,11
10,1,9
8,4,5
3,10,5
3,4,9
6,5,15
14,3,9
3,15,10
7,4,14
13,7,16
4,15,4
10,3,13
11,17,8
16,12,8
13,12,2
13,4,6
12,13,5
10,2,7
13,16,15
16,12,11
10,2,12
14,4,13
13,13,5
14,7,7
6,4,6
5,16,10
3,9,16
11,3,8
3,6,7
2,12,10
7,14,15
13,13,2
6,16,11
16,13,5
14,3,11
12,5,2
11,8,15
8,12,2
2,10,10
18,12,7
8,16,13
16,12,7
5,2,8
9,9,17
13,6,14
6,14,15
3,8,5
7,10,2
17,14,8
5,14,12
1,8,11
13,5,4
16,9,6
15,6,16
3,4,11
5,4,13
8,15,15
3,3,8
8,9,1
8,2,11
16,10,4
11,1,11
14,14,11
8,3,13
3,6,5
14,16,8
15,15,5
5,12,16
3,14,10
14,5,7
12,2,9
4,7,15
12,3,5
3,13,13
8,8,4
4,11,4
14,17,11
10,17,11
6,11,2
4,9,14
6,16,4
15,15,6
4,10,3
7,7,2
6,5,16
4,7,4
7,3,8
11,2,10
6,8,18
2,6,7
16,14,10
9,2,9
13,4,8
13,9,15
11,5,14
3,11,13
13,12,16
7,3,13
13,13,16
11,2,12
6,15,7
5,12,3
7,4,15
16,4,8
16,15,14
8,2,13
12,10,3
16,13,14
16,7,8
11,4,4
4,10,15
3,13,8
12,17,12
10,4,3
11,6,3
8,15,4
10,17,12
5,9,18
4,2,11
10,14,4
5,15,13
11,7,3
10,13,3
4,15,6
2,10,13
15,15,9
7,17,7
10,15,16
15,16,11
9,3,12
13,11,2
8,6,17
8,5,14
6,11,17
13,17,14
3,9,15
15,7,5
3,10,15
3,15,13
16,13,6
14,6,14
14,3,12
9,1,11
9,7,16
5,13,3
11,9,18
14,15,11
4,14,4
15,14,12
12,16,8
5,6,4
8,16,15
11,16,10
7,15,15
7,2,8
3,8,12
7,8,17
16,11,6
11,11,2
14,4,7
13,16,14
13,7,4
12,16,12
16,7,10
10,14,17
8,4,4
6,10,16
17,11,11
16,5,10
10,17,8
11,10,3
8,16,5
4,6,12
12,15,15
14,7,15
2,13,13
17,9,11
9,18,7
5,7,15
2,12,6
5,9,17
11,17,11
2,11,12
16,4,9
15,6,4
5,4,9
2,7,8
13,12,14
12,1,10
9,5,13
3,9,6
5,3,8
2,13,11
7,17,8
10,15,5
13,7,17
16,10,10
7,5,14
7,8,2
16,9,14
3,13,5
6,11,13
8,5,16
6,4,10
6,6,17
4,15,9
14,9,3
3,14,6
3,12,5
12,15,12
7,17,6
7,9,3
4,17,10
8,7,3
10,16,12
16,5,7
4,8,10
5,6,10
3,7,10
16,7,14
2,8,12
1,8,8
8,7,16
3,7,6
6,15,10
5,10,5
5,3,11
14,5,6
8,5,11
8,13,16
14,15,13
14,2,8
8,15,5
18,7,9
15,3,10
9,2,8
13,15,5
5,16,7
3,5,12
5,6,12
7,4,5
4,11,5
16,12,5
8,3,6
17,9,6
10,9,2
1,11,7
15,11,15
10,4,12
16,10,5
11,12,18
18,12,10
16,14,7
12,13,2
4,3,8
17,11,13
14,6,16
3,7,5
12,11,18
12,2,11
6,6,2
14,5,16
15,7,12
16,5,12
8,6,15
8,17,8
9,15,14
8,3,10
7,4,13
11,11,18
5,5,4
8,11,2
13,10,14
7,6,4
5,16,8
2,9,6
18,12,9
3,8,13
7,8,1
13,16,12
13,6,3
5,15,5
7,15,7
3,11,11
3,5,11
9,1,10
5,4,7
10,7,17
12,10,16
3,10,4
16,10,7
7,16,14
15,10,14
4,6,14
9,16,7
18,11,13
13,4,16
10,14,3
3,12,11
14,11,4
17,11,14
14,16,9
18,12,11
14,14,8
16,12,10
17,5,8
14,13,6
7,15,13
15,12,13
7,11,17
13,10,2
6,4,11
6,14,4
12,10,4
3,6,13
6,16,10
16,12,6
4,12,10
15,17,9
2,8,9
7,3,9
5,11,15
4,5,12
8,8,3
5,9,3
3,8,10
13,15,14
5,6,6
3,7,12
6,14,3
16,7,15
6,12,2
11,16,5
18,7,8
11,3,15
4,13,4
17,7,11
12,9,17
2,7,10
10,16,6
12,7,17
3,12,8
6,12,3
11,5,15
9,6,15
14,4,12
4,10,6
6,17,7
13,2,8
9,1,7
5,6,15
17,12,13
7,6,3
14,8,17
6,2,9
15,4,13
11,15,4
14,16,12
9,18,9
5,6,13
13,17,12
12,17,5
13,13,4
2,9,9
6,10,3
14,13,4
15,4,7
12,4,4
6,10,17
15,6,6
5,15,6
16,6,6
9,11,2
12,14,4
3,14,8
14,9,16
12,3,9
10,15,6
6,15,5
12,16,10
5,14,4
6,6,14
12,9,2
2,10,12
14,10,17
14,17,13
14,7,5
9,7,15
14,16,7
4,14,12
11,5,4
15,6,8
4,11,6
3,12,10
11,6,17
7,9,17
17,7,13
9,15,3
8,16,8
8,14,3
3,9,14
2,11,9
13,2,12
11,15,5
7,5,15
13,3,13
11,4,6
3,10,12
9,10,3
13,5,5
4,12,4
13,4,13
8,16,6
14,8,3
7,9,2
3,7,9
6,3,6
5,15,4
4,13,10
7,7,4
9,2,11
4,7,14
12,6,15
5,14,7
6,15,12
13,14,14
15,4,11
7,15,4
16,14,9
3,11,4
9,18,11
17,9,5
18,11,6
2,10,8
4,14,11
12,10,2
19,8,10
9,17,12
10,17,7
6,12,12
4,13,14
11,4,2
16,11,15
9,13,3
7,8,15
8,14,13
12,3,12
16,13,9
10,16,14
10,15,14
10,17,6
4,11,3
10,3,7
10,11,17
8,18,6
14,3,6
17,12,7
17,10,11
11,7,1
6,16,7
16,9,10
5,2,12
13,3,10
15,4,9
17,9,10
15,13,7
14,4,14
12,8,2
5,16,6
4,15,10
9,12,16
14,17,7
14,12,6
3,8,9
6,3,13
16,8,11
9,7,18
12,4,6
14,6,15
10,10,1
6,15,9
4,6,4
14,4,11
9,3,11
4,15,8
16,9,15
15,3,8
8,3,8
2,5,8
4,10,4
12,15,14
11,16,11
6,8,15
5,3,10
17,9,9
6,4,14
4,5,8
17,9,13
15,13,8
9,13,17
7,17,10
13,9,17
2,13,9
15,10,5
10,2,8
6,11,16
9,1,8
10,8,17
13,5,14
13,13,15
6,3,8
9,8,18
10,16,11
7,13,14
12,6,16
16,14,6
10,16,4
16,7,5
15,12,15
8,5,3
13,13,3
17,6,8
9,6,2
6,7,4
6,3,3
7,18,9
4,4,10
8,4,16
6,9,17
10,1,7
13,16,11
4,16,9
11,12,2
9,6,3
4,16,10
8,13,3
14,12,14
11,18,12
10,4,4
5,11,4
10,10,17
4,15,7
17,12,10
10,3,3
11,8,1
14,13,16
15,13,12
6,8,3
12,6,4
15,5,5
12,14,3
6,15,6
11,13,16
16,8,9
14,10,15
10,17,10
8,4,14
12,7,2
6,7,2
13,15,15
7,6,15
5,16,11
16,16,9
15,14,9
4,5,3
9,4,15
11,2,6
2,9,8
14,17,8
4,16,11
14,6,4
15,6,5
11,13,2
12,4,14
12,3,8
15,12,4
9,2,14
14,9,5
6,2,12
15,16,12
4,10,16
8,6,16
5,12,4
12,8,17
15,11,14
9,18,8
15,14,11
4,9,4
5,13,15
16,4,10
6,14,12
16,12,4
5,8,14
4,4,9
11,3,4
14,5,5
11,3,6
14,3,7
4,5,7
9,9,2
9,2,6
8,18,9
9,3,14
16,8,13
9,17,7
11,2,9
13,9,14
1,8,10
17,8,6
17,12,8
3,6,8
12,14,16
4,13,15
2,6,10
4,4,15
12,9,16
17,7,9
15,13,4
12,4,10
6,8,17
7,10,1
8,4,6
13,14,13
11,18,10
4,7,11
3,8,14
8,1,11
6,8,4
12,14,14
7,2,9
14,14,3
17,9,7
13,5,15
4,13,13
10,8,1
13,11,5
14,17,12
1,9,5
14,15,5
7,4,6
1,11,11
10,5,3
15,5,8
5,12,2
9,16,6
11,3,14
13,10,17
5,14,15
2,10,9
15,5,6
8,7,2
7,11,2
5,14,5
6,3,9
13,3,14
13,15,6
7,8,18
17,9,8
11,14,3
9,9,1
11,3,7
7,6,16
9,16,9
8,4,13
8,13,17
9,3,4
13,5,3
12,4,2
15,14,5
13,13,6
16,15,7
5,2,7
14,14,13
11,17,13
15,9,16
15,12,3
1,12,9
8,11,18
9,17,9
16,14,13
4,7,5
13,8,16
18,9,9
6,13,3
6,16,6
10,17,9
9,15,15
11,17,6
7,6,8
11,15,6
10,1,10
15,8,4
6,16,5
4,14,5
9,7,2
14,14,6
8,14,5
12,11,14
4,8,3
17,11,8
15,11,16
10,18,7
6,13,16
17,13,7
4,14,8
5,5,7
16,12,12
13,14,3
15,15,11
5,5,3
3,9,9
14,3,13
16,14,12
3,11,7
11,9,16
17,7,6
3,7,13
3,12,3
3,11,6
14,15,8
7,3,6
3,7,4
18,8,9
6,8,14
12,17,10
15,5,14
13,7,18
2,12,11
4,12,16
7,15,5
6,4,8
8,15,13
10,10,3
2,13,12
2,7,6
10,9,17
10,18,10
16,5,9
9,16,3
13,7,3
6,17,12
7,3,15
16,11,14
11,16,6
16,12,13
8,11,17
6,10,15
6,11,3
2,8,6
10,16,7
3,10,14
3,11,5
5,10,3
13,2,9
12,11,17
6,16,14
6,13,4
4,11,15
6,15,4
9,13,2
13,12,13
10,10,2
8,3,5
13,9,18
7,13,16
5,14,6
11,3,5
6,3,7
8,2,10
12,12,3
6,13,14
8,7,1
9,16,13
9,17,6
17,7,8
5,4,15
17,13,6
3,11,12
16,8,15
10,4,14
13,7,2
4,12,6
2,9,13
9,18,10
11,18,7
17,10,13
14,13,12
14,16,10
14,10,14
12,16,13
10,6,16
2,5,10
6,4,13
9,14,16
4,12,12
16,13,8
14,10,16
16,5,8
3,15,12
3,8,4
13,16,9
8,13,2
4,11,8
12,3,7
2,11,7
11,1,9
13,9,16
8,3,7
2,6,8
8,10,17
4,3,9
9,18,6
16,10,12
17,8,12
16,6,12
3,8,7
5,13,16
17,11,9
7,13,17
11,17,10
4,5,11
15,13,6
12,14,17
8,8,19
13,17,7
8,17,14
5,4,8
11,15,15
4,13,5
6,13,15
16,6,8
2,12,9
7,4,11
2,10,7
13,10,3
7,17,13
16,10,6
8,6,5
8,7,17
14,6,5
11,5,2
13,3,5
5,8,4
2,11,13
12,8,16
8,10,1
11,17,14
9,5,2
5,11,3
15,7,6
11,8,18
10,4,13
13,11,17
9,2,10
16,8,4
5,4,10
9,17,8
9,13,6
14,14,14
12,2,8
5,11,14
12,1,12
13,12,4
12,6,3
4,8,13
9,9,18
6,2,10
9,2,7
10,2,9
4,3,12
14,14,4
15,14,6
7,3,7
10,2,13
14,13,13
3,14,9
1,11,10
8,18,10
17,13,10
7,2,7
18,8,11
3,15,7
4,9,15
9,6,16
3,14,12
6,5,12
9,14,2
3,8,11
9,11,16
11,17,9
11,14,4
8,12,18
4,12,13
10,13,16
6,15,8
13,15,11
7,16,7
10,5,13
13,12,15
10,2,14
14,16,11
11,18,9
10,17,13
9,1,9
12,11,2
1,8,9
8,7,15
15,4,12
6,10,2
11,10,1
13,2,5
2,11,5
7,10,16
10,2,6
5,3,9
5,7,16
12,5,4
3,10,2
14,16,6
9,7,17
11,14,15
10,16,5
17,10,6
5,9,2
4,3,13
6,16,9
10,13,2
15,5,13
18,8,8
9,3,5
10,6,3
17,11,6
8,15,14
13,3,9
11,7,17
12,9,3
12,11,16
12,5,14
14,15,6
8,3,11
16,13,10
9,6,17
17,10,8
9,3,6
11,5,3
12,16,14
13,6,4
11,9,2
13,6,2
7,10,5
8,17,7
9,5,17
14,15,9
10,14,5
6,2,8
6,15,14
18,11,9
11,2,11
4,5,6
18,11,12
3,14,11
5,15,14
4,6,3
2,11,14
11,10,15
10,18,8
17,8,11
11,3,11
7,13,3
9,2,12
18,9,10
17,13,8
17,10,14
5,5,14
17,6,7
15,5,12
2,8,13
10,1,11
13,2,10
17,15,8
11,10,2
9,10,2
11,5,13
5,5,13
4,12,5
9,15,6
2,9,7
14,2,10
16,4,11
4,11,14
7,4,3
17,13,9
7,2,10
5,16,14
11,14,16
16,4,12
15,12,5
2,13,14
7,16,10
4,13,11
17,7,7
13,3,7
6,8,2
5,16,12
9,15,4
7,12,3
15,11,6
10,5,2
11,1,10
6,17,14
3,6,10
15,6,15
10,11,1
4,16,7
9,2,4
14,4,5
12,11,15
16,5,13
7,5,5
6,18,9
5,9,15
4,4,11
5,6,3
7,14,2
1,11,13
15,14,7
16,9,4
17,10,5
17,6,12
5,13,12
4,16,5
7,6,17
2,14,10
15,9,15
12,4,13
12,17,11
8,9,3
14,5,15
12,12,16
4,4,5
8,17,6
6,4,15
16,7,16
9,7,1
9,17,11
12,4,15
17,10,9
3,10,9
7,10,4
15,6,12
15,7,8
5,6,14
2,5,9
5,15,15
5,8,3
14,5,10
4,14,10
7,10,3
3,9,10
13,16,10
10,18,11
9,8,1
9,10,1
15,15,8
8,7,4
17,5,9
6,6,3
13,14,16
11,9,17
3,12,13
13,17,8
12,14,10
4,7,7
14,13,15
14,10,4
7,4,4
3,3,10
17,7,12
4,4,7
3,15,8
9,4,5
9,5,15
12,2,13
3,6,9
14,13,5
5,3,14
13,16,13
15,3,13
9,4,4
3,7,11
5,7,3
2,6,11
15,13,5
12,15,4
15,6,7
14,3,8
13,13,17
14,5,4
10,4,16
13,14,15
15,12,14
4,13,6
11,15,3
9,1,12
3,5,10
10,16,13
3,7,14
3,12,12
15,5,7
13,15,7
17,11,12
14,3,10
10,11,16
5,14,9
2,12,8
17,8,8
6,5,13
1,12,11
9,16,5
9,17,14
6,15,11
6,14,13
13,14,4
17,12,11
5,4,16
7,16,12
4,5,13
8,6,2
13,8,2
1,11,8
4,4,13
6,12,16
1,10,10
9,10,15
8,12,3
6,17,8
15,5,9
5,15,12
6,3,11
5,14,13
5,4,11
8,9,17
10,2,10
6,4,5
11,6,2
15,13,14
10,3,16
15,8,3
14,13,14
7,16,5
9,5,4
9,16,16
11,12,17
15,9,11
10,3,15
4,15,13
10,12,18
13,16,6
7,2,11
14,6,3
6,5,6
1,9,10
8,17,11
3,7,7
14,11,5
13,9,1
7,13,2
12,12,17
7,16,6
8,9,16
12,1,8
15,14,14
17,12,14
15,3,12
8,18,7
13,12,3
5,8,15
15,8,5
3,10,7
11,17,5
4,11,13
4,16,12
3,8,6
4,7,6
5,7,13
6,17,6
4,8,16
5,7,2
14,2,9
11,4,15
8,14,14
16,10,13
17,11,7
11,10,18
11,6,4
17,8,9
9,4,14
16,11,12
13,10,4
8,5,4
8,17,10
17,9,12
16,9,11
13,13,1
12,7,3
13,2,13
12,8,15
3,15,11
12,2,10
5,4,5
16,15,13
4,15,14
4,15,12
7,13,11
14,5,9
5,13,6
16,7,4
7,14,6
9,15,9
5,14,14
6,17,10
12,1,11
2,10,11
3,11,14
7,17,11
10,3,12
16,13,12
10,9,18
3,9,3
11,7,15
4,4,12
6,7,15
2,14,8
6,2,13
3,13,11
11,11,1
16,7,13
16,6,15
5,3,6
1,9,13
4,7,16
11,12,3
7,4,7
3,13,12
12,18,10
8,17,9
12,17,7
17,12,6
19,9,11
12,3,15
7,11,3
5,14,10
12,13,16
11,7,2
10,15,11
15,9,13
16,9,13
16,4,13
14,16,13
10,15,12
3,4,8
12,7,16
12,3,14
6,16,12
12,17,9
5,10,16
7,16,13
4,11,2
10,2,11
6,9,2
9,13,16
5,4,12
11,2,7
4,15,11
12,2,12
11,3,3
8,8,17
13,4,11
8,9,2
9,12,18
2,11,10
4,10,5
16,11,4
13,15,10
13,14,6
13,16,5
10,14,16
4,10,13
16,10,9
6,12,4
5,10,2
16,7,9
15,9,7
16,10,14
11,13,4
4,11,11
13,12,17
2,13,7
15,11,4
3,13,10
10,1,8
17,8,13
4,3,11
13,16,7
8,17,15
7,10,17
3,5,6
8,16,7
15,15,10
18,11,10
2,12,7
12,6,1
18,5,7
8,16,10
14,5,14
2,11,6
7,12,1
12,3,4
7,14,16
9,6,5
16,15,9
5,17,9
9,17,10
6,6,16
10,9,1
14,12,15
8,2,14
5,15,8
7,7,16
13,13,14
16,12,9
6,14,14
12,11,4
9,13,15
18,6,10
7,8,3
8,2,5
10,5,16
2,9,15
18,7,10
6,16,13
8,2,12
13,14,2
14,11,2
5,13,7
7,5,6
16,6,14
12,4,3
10,3,14
10,4,15
14,4,10
12,13,14
11,6,5
7,12,16
8,16,14
15,4,5
10,12,2
11,10,16
14,9,12
9,14,4
4,8,17
9,11,3
13,17,11
4,4,14
7,7,17
12,15,13
4,13,7
5,8,5
11,16,14
10,3,5
17,10,10
3,8,8
14,7,16
6,2,11
4,14,9
2,8,10
5,16,13
15,5,11
3,4,12
4,14,15
9,14,5
17,8,7
9,2,13
4,8,4
3,12,14
8,15,7
12,16,4
12,2,14
17,6,13
18,8,10
5,6,5
5,10,14
4,6,6
16,14,8
3,4,10
14,11,15
8,16,11
10,12,16
13,8,18
7,5,4
11,15,16
14,14,15
2,8,8
13,6,16
10,5,15
9,10,16
13,16,8
5,9,14
5,5,6
16,5,14
3,11,8
9,11,17
9,3,15
12,3,10
4,6,5
15,3,9
4,12,3
17,7,10
15,13,10
2,7,12
12,18,9
13,15,9
16,6,11
8,8,2
1,9,8
16,11,5
7,13,4
17,12,5
1,9,12
2,14,11
8,15,3
13,5,13
10,4,10
14,9,13
11,11,17
3,14,14
6,9,3
2,12,4
3,9,5
9,8,2
15,7,16
15,7,15
9,19,9
17,12,9
15,13,13
10,5,4
17,8,15
11,13,14
10,7,2
9,1,14
15,3,11
17,14,11
5,17,12
12,5,3
1,10,8
2,11,4
16,9,12
2,6,9
4,5,10
7,17,12
5,12,15
14,6,6
7,3,14
5,10,17
6,3,14
15,10,4
3,6,12
4,9,7
8,1,10
10,6,17
14,12,4
15,16,13
9,15,7
17,6,9
5,11,6
12,10,18
16,6,9
8,13,4
16,15,10
3,13,7
9,9,16
13,9,4
8,2,8
12,3,13
12,6,5
4,12,15
9,3,13
16,6,5
16,13,15
2,8,11
7,14,3
4,11,12
7,3,5
15,12,6
3,5,9
7,10,15
8,4,8
10,10,16
15,10,8
12,9,18
5,5,15
7,15,14
4,7,8
2,8,7
4,14,6
10,12,1
13,15,13
18,11,11
5,9,6
6,11,15
13,8,14
11,16,16
5,4,6
12,15,5
14,13,3
17,13,11
14,7,4
16,11,8
15,5,4
2,12,13
5,14,3
2,7,11
8,3,4
7,9,1
16,6,7
12,14,5
1,12,10
7,4,12
4,5,14
13,4,5
11,7,16
14,9,4
16,11,11
13,5,6
17,11,10
1,10,6
13,11,1
16,8,7
5,10,4
12,1,9
10,1,6
16,3,8
4,6,7
9,14,3
3,6,11
9,5,16
14,14,5
14,12,16
18,9,11
11,7,18
9,4,13
5,9,4
5,9,16
12,4,16
9,15,5
4,7,2
7,11,15
10,8,15
12,3,11
11,2,13
12,15,6
13,9,3
3,9,12
4,9,16
4,14,13
13,10,15
16,5,6
1,12,7
6,9,16
7,1,9
11,13,13
13,5,16
10,1,12
13,15,4
18,6,9
12,13,4
17,14,10
6,15,13
9,3,9
9,17,13
14,8,4
11,3,12
13,14,12
3,4,14
14,15,7
11,4,11
9,4,9
3,10,6
16,7,6
13,17,13
3,10,3
11,4,14
9,15,16
15,15,13
12,13,15
6,7,17
4,14,7
11,17,7
11,15,7
18,9,8
18,10,11
14,15,15
11,12,16
6,5,7
15,10,3
7,15,16
11,6,16
4,8,6
6,15,15
10,9,16
16,10,3
3,15,9
3,9,4
3,5,7
15,4,4
1,8,12
5,14,11
11,4,16
9,11,1
10,8,18
4,6,9
7,3,4
17,10,7
2,12,12
16,9,9
12,15,11
16,9,7
8,6,18
9,14,1
7,14,4
7,17,9
14,12,13
16,5,11
1,12,13
14,4,6
10,15,4
12,14,13
6,17,9
2,7,14
3,5,13
13,11,3
13,10,16
5,2,13
3,13,15
9,16,14
3,13,14
5,6,8
2,11,11
16,8,12
1,7,8
14,7,6
12,8,3
7,15,6
9,12,2
14,10,6
12,7,1
9,13,4
10,3,11
6,3,12
5,12,6
10,17,5
16,4,7
10,11,4
4,11,16
7,4,8
2,10,5
13,4,14
15,3,6
14,1,12
7,1,8
7,11,16
7,15,10
15,4,8
4,5,5
0,11,11
2,12,5
14,17,9
13,18,10
7,16,11
12,5,13
9,10,17
17,5,11
7,4,16
2,5,6
4,2,10
5,3,13
17,12,12
13,6,8
5,12,11
11,14,13
18,10,9
6,5,9
1,10,9
17,8,5
12,10,17
9,5,3
4,8,7
5,7,5
6,12,14
7,6,2
12,13,3
12,6,2
11,5,16
4,13,12
6,4,7
6,9,5
13,2,11
1,9,14
10,12,15
7,3,10
7,11,18
15,8,11
18,9,7
2,8,14
4,7,13
9,14,14
16,14,14
14,11,3
8,16,12
1,8,5
5,17,11
0,9,10
13,5,12
9,14,17
8,9,18
7,8,16
12,5,15
3,11,9
5,10,15
4,9,17
13,3,12
8,15,16
13,3,11
2,9,12
6,12,15
13,8,4
8,15,6
14,5,13
7,5,17
5,15,7
10,16,16
10,11,2
3,11,3
3,13,9
6,8,12
8,3,15
5,4,14
9,15,2
18,10,12
2,10,6
11,18,11
8,14,16
6,2,7
10,14,14
17,9,14
5,13,8
16,11,13
14,9,2
6,7,16
2,7,13
10,13,17
15,4,10
17,13,12
16,14,11
9,10,18
1,11,6
7,3,3
13,17,10
10,6,4
1,9,9
8,3,14
10,15,3
11,2,5
9,19,11
10,14,15
16,8,8
19,11,10
5,8,16
8,11,3
5,7,12
11,15,13
16,9,8
14,16,5
4,11,7
14,10,5
1,11,9
13,1,11
17,8,10
6,11,4
3,12,6
6,7,18
17,5,10
3,7,3
12,5,16
14,10,3
13,6,6
8,1,7
6,14,16
3,12,15
6,8,16
3,9,7
9,4,12
4,16,8
15,13,16
13,17,9
4,16,13
9,12,15
15,16,10
8,17,5
12,19,9
12,5,6
6,9,1
1,11,12
13,3,15
13,9,2
14,12,5
10,14,18
10,7,1
9,8,17
3,9,11
10,15,8
4,5,9
6,16,8
16,11,10
15,14,4
13,2,6
10,14,12
14,5,12
2,8,5
8,4,2
5,17,8
14,15,12
15,7,7
8,10,18
2,7,9
8,17,12
18,9,6
13,4,15
13,15,3
2,16,8
4,6,13
6,10,5
5,12,14
15,5,15
9,13,18
15,15,7
9,17,5
14,6,7
7,16,4
7,18,12
9,11,18
4,12,17
8,8,1
2,13,8
11,3,13
15,11,13
15,7,14
13,11,16
7,2,5
4,9,12
6,5,5
16,8,5
6,1,11
10,16,9
10,7,4
12,12,1
15,8,16
2,14,12
3,7,8
11,17,12
18,8,7
13,3,8
7,16,9
9,5,1
9,0,9
10,18,12
2,15,10
3,4,7
2,11,8
14,9,15
15,4,6
16,8,3
5,3,12
16,7,7
7,11,4
3,11,15
2,7,5
10,18,6
1,7,10
10,5,14
15,10,15
7,3,11
16,15,8
16,5,15
13,6,15
6,4,4
17,10,12
15,8,13
14,15,14
10,8,16
17,7,5
6,5,4
5,6,7
10,3,8
8,10,15
16,10,15
19,10,9
16,6,13
7,14,14
17,4,10
7,16,8
15,9,3
4,7,10
2,5,11
12,4,7
16,8,6
5,13,9
12,10,15
13,14,5
14,8,2
16,11,9
8,2,9
1,7,9
11,14,17
14,9,17
17,11,5
8,7,18
6,3,15
16,13,13
15,12,10
10,5,6
14,11,14
17,14,9
12,17,8
12,18,11
17,5,12
12,3,6
8,6,4
12,5,5
8,18,12
14,8,5
15,13,9
15,2,8
4,3,7
11,5,5
18,12,8
11,8,3
10,3,10
4,4,8
9,16,12
12,1,6
9,12,1
5,2,9
11,3,10
12,5,17
15,14,8
16,3,10
6,12,1
11,11,3
17,14,12
10,4,11
12,11,1
5,5,9
15,6,11
3,6,6
9,17,4
11,12,5
15,14,13
14,6,13
7,7,3
12,7,18
8,14,15
17,6,11
1,5,12
2,12,14
14,7,3
12,6,17
13,11,4
11,6,1
15,7,3
12,2,6
6,13,2
8,1,8
10,7,3
6,3,5
15,7,4
6,5,14
15,15,12
11,7,4
11,4,12
12,15,16
10,7,16
14,8,16
8,12,17
6,4,16
11,14,2
1,10,11