master
Karl Spickermann 1 year ago
parent ad87697b41
commit 38756e9f01

@ -0,0 +1,100 @@
package main
import (
"AOC2021/src/helper"
"fmt"
"os"
"strconv"
"strings"
)
type foldingInfo struct {
alignment string
length int
}
func main() {
args := os.Args[1:]
input, err := helper.GetInput(args[0])
if err != nil {
fmt.Println(err)
}
var points [][2]int
var folds []foldingInfo
for _, row := range input {
if helper.ContainsCharacter(row, ",") {
splitRow, _ := helper.MapToNumber(strings.Split(row, ","))
xValue := splitRow[0]
yValue := splitRow[1]
points = append(points, [2]int{xValue, yValue})
}
if helper.ContainsCharacter(row, "=") {
splitRow := strings.Split(row[10:], "=")
aligment := splitRow[0][1:]
length, _ := strconv.Atoi(splitRow[1])
folds = append(folds, foldingInfo{aligment, length})
}
}
part1(points, folds)
part2(points, folds)
}
func part1(points [][2]int, folds []foldingInfo) {
step1 := foldPaper(points, folds[0])
set := make(map[[2]int]struct{})
for _, point := range step1 {
set[point] = struct{}{}
}
fmt.Println(len(set))
}
func part2(points [][2]int, folds []foldingInfo) {
for _, fold := range folds {
points = foldPaper(points, fold)
}
printPaper(points)
}
func foldPaper(points [][2]int, fold foldingInfo) [][2]int{
var newPaper [][2]int
for _, point := range points {
newPaper = append(newPaper, foldPoint(point, fold))
}
return newPaper
}
func foldPoint(inputPoint [2]int, fold foldingInfo) [2]int {
direction := 1
if fold.alignment == "x" {
direction = 0
}
if inputPoint[direction] > fold.length {
inputPoint[direction] = fold.length - (inputPoint[direction] - fold.length)
}
return inputPoint
}
func printPaper(points [][2]int) {
maxX := 0
maxY := 0
for _, point := range points {
if point[0] > maxX {
maxX = point[0]
}
if point[1] > maxY {
maxY = point[1]
}
}
paper := make([][]rune, maxY+1)
for i := 0; i <= maxY; i++ {
for j := 0; j <= maxX; j++ {
paper[i] = append(paper[i], ' ')
}
}
for _, point := range points {
paper[point[1]][point[0]] = '#'
}
for _, row := range paper {
fmt.Println(string(row))
}
}

@ -0,0 +1,860 @@
609,754
1101,140
1129,317
622,327
967,218
661,789
661,127
1183,596
649,280
932,693
1288,157
1111,372
781,219
994,236
1145,770
1153,395
755,289
502,406
850,126
902,58
907,5
268,700
646,436
1108,523
443,343
932,201
1115,105
1191,278
1241,203
1000,252
1290,403
144,597
927,448
782,630
131,705
333,367
38,613
1285,294
872,93
492,759
986,203
70,740
378,693
1004,319
731,235
479,875
1210,389
1215,215
214,122
599,660
500,254
8,478
120,29
70,809
373,248
1235,441
1293,345
454,686
985,469
1101,478
765,287
1029,309
667,203
1220,800
508,285
65,675
1078,663
592,677
236,122
462,564
1042,418
748,852
810,254
718,229
386,22
1191,728
432,872
392,28
972,259
336,416
1096,480
415,871
1241,427
165,441
510,673
750,313
1255,779
194,854
639,107
281,585
679,519
611,644
497,171
326,730
882,456
403,453
454,630
726,227
383,502
574,528
1120,593
214,256
165,422
425,115
795,323
673,602
5,827
1009,619
364,194
75,390
870,122
654,449
62,665
999,228
611,508
87,660
677,880
656,449
681,336
499,70
870,638
119,728
1185,498
28,406
1,796
334,210
803,445
17,345
58,194
1310,162
661,827
276,649
679,883
164,506
990,236
82,327
999,485
498,208
1228,119
529,732
252,544
579,403
808,592
251,665
912,602
502,722
85,75
440,122
755,12
898,766
878,22
924,22
679,277
1191,616
1278,775
1148,871
229,37
957,854
987,448
1285,518
1252,476
1295,857
822,285
731,627
199,74
82,775
1186,299
954,488
753,508
1232,593
1216,663
529,284
795,571
1118,226
467,617
691,36
181,317
994,658
651,894
1101,754
763,603
1088,872
45,528
937,224
1042,470
1066,648
1131,95
738,434
283,60
994,302
1268,865
795,287
75,179
1011,425
741,75
773,659
373,700
201,479
649,614
328,893
1103,728
1144,285
468,45
857,591
69,203
401,339
579,659
502,172
584,891
802,609
644,359
679,11
1260,201
194,505
507,485
738,350
170,882
84,511
1203,123
1240,533
811,70
736,687
856,686
698,417
726,592
572,544
1144,609
629,376
1039,840
455,148
580,224
848,778
684,45
1265,304
681,406
15,228
172,814
637,549
617,610
1185,610
1250,275
107,291
186,261
1247,299
467,123
350,582
782,432
38,505
843,617
1184,630
304,712
373,221
534,865
743,402
857,620
671,857
70,361
692,252
338,658
1121,144
1258,266
1058,843
773,211
1129,516
1088,22
15,86
343,676
70,1
55,794
691,91
982,893
1300,628
656,162
262,362
850,854
617,284
977,280
373,640
654,221
484,882
251,235
103,639
1293,292
1150,525
758,432
480,124
1235,504
1293,549
60,275
1036,317
512,231
599,794
783,148
350,518
45,252
1265,140
979,448
706,878
1203,686
288,837
180,138
572,431
199,148
530,408
711,794
1302,682
497,295
36,549
201,415
1009,432
94,663
1150,77
1096,638
803,87
211,775
320,12
166,609
629,558
572,366
1226,766
295,789
195,105
99,712
507,87
242,383
55,354
681,558
1135,313
192,226
895,871
508,609
1146,394
281,588
714,312
567,234
283,834
455,893
45,140
691,673
763,123
75,715
820,506
1285,40
242,712
475,1
453,722
965,793
475,212
201,610
333,280
934,103
570,488
1126,10
380,404
256,332
818,311
1179,257
725,19
131,49
947,283
84,128
402,798
544,68
835,1
637,345
846,77
117,445
599,107
755,371
596,582
216,93
32,775
999,409
50,693
184,231
343,436
768,17
507,409
880,379
1000,700
1266,824
529,675
119,278
284,477
1305,280
226,582
353,854
1238,360
1048,476
1079,887
960,518
619,445
530,75
863,390
972,770
759,191
1235,390
813,218
775,728
199,1
1283,649
800,221
1183,416
10,87
199,809
1272,505
1099,775
730,574
803,436
10,135
1118,330
1186,150
1200,600
179,95
1228,648
1218,673
731,403
780,744
763,238
1258,765
209,140
572,618
631,211
1081,115
584,592
432,868
787,413
700,518
555,12
1265,670
350,312
599,659
90,823
678,312
99,523
455,1
851,49
743,660
714,694
102,14
1183,484
870,548
242,800
759,255
200,712
110,404
1190,865
441,553
427,289
577,819
1198,521
1022,57
946,252
852,117
535,166
1146,871
937,130
1009,294
855,746
301,619
908,798
1255,100
1047,236
1004,127
683,649
596,312
189,592
584,85
107,603
734,705
1255,794
671,37
316,816
1183,148
599,802
999,555
131,845
842,630
1094,435
684,493
1038,257
17,292
1208,14
58,582
503,691
338,684
1225,75
818,759
227,289
649,815
835,95
447,838
468,630
196,119
1228,366
155,70
927,18
145,129
488,285
1255,660
338,236
684,401
1123,501
244,210
44,70
972,322
964,333
190,301
1260,878
555,289
738,17
574,687
821,322
294,119
1124,261
8,864
97,633
741,560
401,107
560,313
1252,200
1273,508
803,485
25,294
1193,449
266,520
927,100
848,668
1300,135
430,379
398,809
1285,376
70,533
800,673
869,553
552,432
736,207
227,658
202,523
1096,414
1300,807
611,386
1124,40
194,768
786,789
428,134
125,610
301,723
637,154
1114,119
1166,597
1253,276
373,757
842,854
447,56
338,592
1186,819
412,766
1042,700
529,50
932,130
914,469
766,765
1274,549
253,555
55,787
142,630
567,423
1054,292
584,816
870,775
530,744
560,761
376,791
127,746
142,679
383,354
1213,185
147,458
619,449
17,549
1292,113
830,115
1290,711
579,627
594,744
459,49
17,101
960,312
1114,103
962,331
510,221
960,648
808,40
1158,854
453,31
445,757
972,722
82,648
84,766
252,350
656,673
994,572
242,576
438,93
972,684
930,765
810,366
1245,219
796,630
912,85
851,553
590,362
522,768
1223,471
912,187
1000,194
455,61
1140,882
142,862
440,548
310,194
579,267
335,527
52,129
338,572
52,317
249,334
428,456
1240,592
649,127
1235,715
720,532
976,236
855,820
58,694
1019,803
1016,119
338,302
360,441
631,277
360,119
388,374
1054,332
398,292
1240,361
781,675
199,746
338,266
1068,94
1144,733
1191,838
1293,101
190,593
572,17
187,393
35,673
604,878
960,376
1285,742
1153,767
907,229
1236,171
74,798
529,844
304,742
1111,509
1186,75
330,789
902,836
507,807
594,150
1150,824
350,648
460,374
637,602
443,775
1029,585
1006,152
855,74
989,367
945,308
654,673
599,115
1148,388
1185,442
972,266
1247,485
57,618
1068,383
160,525
1006,182
82,528
542,877
189,144
515,607
950,329
335,367
927,502
808,722
790,513
147,893
1211,630
117,683
1247,261
380,577
338,628
1240,85
966,194
85,819
229,331
1115,789
100,57
534,641
857,722
867,551
15,779
1226,847
1101,11
701,590
1111,522
410,246
679,375
1275,673
161,453
1208,822
1163,458
244,684
169,767
490,506
25,40
1111,677
20,403
271,115
1094,660
527,333
92,673
838,745
1039,100
950,791
1279,161
401,787
291,49
883,68
644,583
1138,528
858,696
323,448
840,231
1150,593
165,472
885,709
1171,123
1275,91
410,210
664,10
200,182
363,283
529,610
1216,399
992,478
1266,70
194,40
681,376
753,277
857,303
1006,742
609,670
842,712
1131,767
579,665
1109,610
80,239
1240,816
69,427
557,386
781,284
494,824
160,77
36,252
838,149
325,469
611,610
599,0
612,635
979,446
887,887
974,478
609,130
551,479
345,101
343,781
880,462
726,533
164,871
1300,124
780,408
627,649
1246,362
1200,404
398,1
172,528
994,322
572,528
360,775
380,490
783,522
27,649
1278,329
1255,110
27,245
679,617
64,362
58,418
1230,574
281,254
408,126
701,140
659,448
971,721
766,129
671,115
1252,582
271,840
957,40
570,406
110,490
634,543
304,152
699,610
1131,212
1226,511
296,598
773,30
1223,660
693,586
84,847
1208,72
338,722
164,785
924,418
1240,740
75,504
330,105
455,746
842,264
818,358
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

@ -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