Browse Source

day 13

main
Luna Lailatova 2 years ago
parent
commit
21b17417af
  1. 73
      day13.py
  2. 812
      input13.txt
  3. 21
      testdata13.txt

73
day13.py

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
import sys
check = True
inpx = []
inpy = []
inp2 = []
with open(sys.argv[1]) as f:
for i in f.readlines():
i = i.strip()
if i == '':
check = False
continue
if check:
temp1, temp2 = i.split(',', 1)
inpx.append(int(temp1))
inpy.append(int(temp2))
else:
i = i.replace('fold along ', '')
i = i.strip()
temp1, temp2 = i.split('=', 1)
inp2.append((temp1, int(temp2)))
maxx = max(inpx)
maxy = max(inpy)
class grid:
def __init__(self, maxx, maxy):
self._points = []
for i in range(maxy + 1):
self._points.append(['.'] * (maxx + 1))
def mark(self, x, y):
self._points[y][x] = '#'
def fold(self, axis, loca):
if axis == 'y':
for i in range(loca + 1, len(self._points)):
for t in range(len(self._points[i])):
if self._points[i][t] == '#':
temp = i - loca
self._points[loca -temp][t] = '#'
del self._points[loca:len(self._points)]
if axis == 'x':
for i in range(len(self._points)):
for t in range(loca + 1, len(self._points[i])):
if self._points[i][t] == '#':
temp = t - loca
self._points[i][loca - temp] = '#'
for f in self._points:
del f[loca:len(f)]
def count(self):
counter = 0
for f in self._points:
for g in f:
if g == '#':
counter += 1
return counter
gri = grid(maxx, maxy)
folds = 0
for i in range(len(inpx)):
gri.mark(inpx[i], inpy[i])
for i in inp2:
gri.fold(i[0], i[1])
folds += 1
print('Points after ', folds, 'fold(s):', gri.count())
for i in range(len(gri._points)):
print(gri._points[i])

812
input13.txt

@ -0,0 +1,812 @@ @@ -0,0 +1,812 @@
470,705
331,196
1241,728
1034,161
181,850
999,484
480,680
798,33
226,86
475,226
113,287
770,702
47,35
848,312
1129,402
179,326
766,404
1258,717
470,494
723,434
418,291
100,298
994,316
423,434
985,292
721,261
528,572
595,567
909,665
411,292
1056,291
1051,434
311,484
462,312
187,273
715,567
114,819
634,861
79,318
912,344
1144,845
152,745
201,464
840,185
291,100
1084,31
1255,434
909,229
895,827
557,29
441,159
661,193
826,215
535,70
974,767
254,739
512,189
868,75
1076,9
700,86
684,515
356,422
348,344
605,341
360,586
383,824
239,393
751,12
253,229
403,759
166,273
1196,819
406,301
343,102
1119,618
333,892
711,789
283,70
418,603
380,714
756,255
20,375
1145,794
642,180
1140,273
984,451
763,619
196,427
869,159
460,96
35,548
512,709
1231,318
1163,21
465,275
32,187
212,296
718,835
1036,42
1002,672
108,492
321,892
294,0
252,350
377,733
1196,822
316,344
254,519
1168,49
1158,745
142,49
130,504
397,56
718,186
463,170
482,463
1032,752
649,193
512,158
895,501
1150,122
537,833
915,434
790,262
1058,539
764,44
512,861
493,296
472,422
44,86
1101,592
671,276
977,2
822,621
179,668
415,46
1067,154
895,169
475,728
231,434
156,103
1176,72
113,607
301,851
927,824
346,870
892,603
610,86
1114,19
295,353
402,350
1118,145
201,318
681,732
338,792
855,733
202,364
125,430
1140,285
917,309
1309,542
10,540
246,499
1038,178
209,609
242,16
10,214
20,519
276,173
540,520
192,582
681,891
830,680
600,44
895,848
1009,219
425,442
1049,185
994,166
1034,733
453,240
605,833
154,71
141,607
840,494
131,87
1084,86
1193,592
1163,166
847,724
329,318
567,46
850,798
554,255
817,598
723,658
1027,70
1154,103
822,273
704,290
985,72
386,593
1015,353
907,435
867,847
711,835
415,718
903,343
252,539
574,310
295,801
156,733
1173,395
736,218
700,360
865,144
1044,240
708,628
354,262
1298,42
987,250
857,430
184,185
1066,14
130,894
917,585
882,596
156,791
868,296
1248,29
1300,354
1180,504
542,385
710,850
172,407
1064,310
962,166
458,504
992,295
517,667
95,12
484,299
523,390
865,733
326,82
1300,91
69,728
470,548
1015,541
141,735
278,756
1237,140
642,714
728,71
1064,666
1128,477
301,403
677,159
340,266
984,812
972,792
212,374
828,463
987,810
1109,318
212,178
1275,548
1016,894
962,128
840,548
10,149
933,833
80,411
1136,883
676,766
421,632
242,786
131,721
274,189
407,576
80,35
393,361
425,421
184,397
1101,196
1154,411
529,878
711,518
1223,270
579,459
343,838
428,415
933,733
930,628
55,294
1226,336
378,721
435,553
546,492
1019,100
763,684
1076,885
1150,772
276,876
574,51
25,610
117,644
410,563
311,838
192,817
626,696
1309,352
604,18
1036,705
782,124
338,464
502,774
1243,882
950,756
1232,593
25,284
853,173
1295,614
1144,534
44,534
1118,312
954,515
410,747
806,348
1193,644
1248,59
700,836
247,318
1121,739
681,715
1185,430
759,103
459,504
981,292
1131,668
798,64
728,39
251,435
688,187
326,451
828,351
654,869
723,712
1300,680
442,598
1310,645
688,222
994,344
277,833
309,318
26,184
711,387
418,515
1109,436
274,705
1131,813
618,614
229,298
388,128
411,366
125,464
3,362
131,173
1216,772
830,540
572,115
922,576
830,214
520,184
895,718
808,203
443,847
729,453
781,240
1078,794
1282,144
196,390
502,203
992,711
557,588
934,828
1010,632
212,520
174,11
976,630
1066,147
913,822
731,459
213,93
244,270
306,791
254,155
103,103
671,52
1128,271
1010,262
62,708
412,556
5,193
294,446
828,95
201,458
838,271
47,859
314,628
425,473
571,654
994,540
567,841
236,575
141,287
197,621
480,206
868,534
435,822
62,59
363,346
1056,739
201,10
994,680
907,135
974,743
1168,64
380,180
247,103
1225,747
841,287
79,352
295,161
393,306
864,646
1158,149
348,128
348,469
189,739
199,285
318,711
888,794
1109,458
1068,108
463,724
397,822
1255,294
917,185
272,716
706,466
979,644
887,460
1053,838
1131,226
1173,787
979,196
557,865
441,735
1290,519
1044,576
1222,854
989,165
107,723
1238,155
67,460
1238,71
1213,726
443,47
316,166
711,105
498,273
70,102
65,585
475,442
599,789
32,873
1012,379
623,609
10,91
569,147
1067,814
580,798
321,2
209,196
967,410
1230,411
1282,870
731,87
736,859
294,894
546,402
334,630
559,12
651,196
65,261
1149,598
473,492
393,452
629,491
480,763
1202,44
1261,61
1056,519
992,127
972,430
740,562
344,290
882,479
45,644
1193,302
1113,273
58,525
718,865
400,515
1084,479
1074,603
835,450
316,728
480,373
1154,733
892,575
1097,129
353,59
1136,688
1128,422
547,619
587,182
962,344
622,707
626,198
1154,483
75,135
277,161
894,406
278,534
951,609
711,152
70,550
738,432
907,759
882,534
923,327
933,229
383,294
25,3
1009,851
507,614
174,883
295,129
276,428
446,86
318,767
703,859
1094,710
480,688
1184,124
336,127
923,567
790,184
1285,284
152,579
599,742
1197,287
639,500
467,273
785,495
300,262
855,285
277,285
267,567
403,459
1179,56
1029,801
551,103
1289,159
415,515
97,596
1109,884
885,227
166,534
213,129
927,70
472,623
1113,49
480,354
166,397
1034,721
629,610
376,590
442,411
676,861
1230,859
1068,878
278,590
49,161
899,528
759,791
1071,169
1230,758
1032,380
271,387
974,711
0,197
70,400
806,856
987,698
1038,380
395,460
793,107
376,828
405,152
78,301
256,550
1113,497
892,274
853,721
783,865
397,166
579,87
243,154
454,280
999,500
898,502
55,600
621,161
786,894
1144,808
192,134
1126,285
196,245
1290,833
1223,501
847,276
835,452
1228,523
653,542
413,250
1200,490
278,304
813,365
582,855
633,735
520,710
398,344
1145,122
740,332
1131,529
544,180
1039,61
363,548
981,740
830,521
674,865
736,676
300,632
671,170
572,299
185,607
907,459
1196,72
687,285
196,19
55,434
999,813
288,754
446,646
981,154
587,460
323,810
1126,497
110,714
512,326
830,354
1232,301
266,240
172,487
1208,152
618,280
766,714
721,633
316,680
987,523
147,614
672,380
467,173
253,665
840,189
673,878
944,754
278,75
1163,813
927,294
1310,197
1183,865
47,488
152,315
472,477
770,371
388,766
108,44
863,294
629,715
1043,775
924,593
1179,838
703,655
1213,596
985,766
830,11
1031,721
623,285
130,448
380,628
72,739
84,749
977,729
318,183
229,227
687,733
179,564
415,270
606,138
1274,280
295,541
1054,550
610,836
239,583
524,894
383,600
1102,808
830,883
828,543
686,845
252,544
832,490
1109,10
1009,267
869,765
822,360
928,716
1118,817
1063,103
10,680
497,813
295,609
1230,310
1042,145
1144,397
70,494
226,31
378,466
401,441
592,29
257,838
366,754
174,540
1253,49
78,593
903,576
764,828
382,716
793,499
1063,576
316,878
1128,417
1298,266
520,262
10,354
388,576
403,435
393,451
626,750
610,58
279,721
358,574
239,400
1010,184
1253,845
415,67
867,47
1032,75
1156,519
254,827
582,603
360,696
1071,311
246,666
353,851
838,477
320,182
835,220
1282,24
200,280
57,845
504,856
741,182
242,430
291,794
fold along x=655
fold along y=447
fold along x=327
fold along y=223
fold along x=163
fold along y=111
fold along x=81
fold along y=55
fold along x=40
fold along y=27
fold along y=13
fold along y=6

21
testdata13.txt

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
6,10
0,14
9,10
0,3
10,4
4,11
6,0
6,12
4,1
0,13
10,12
3,4
3,0
8,4
1,10
2,14
8,10
9,0
fold along y=7
fold along x=5
Loading…
Cancel
Save