+15
.editorconfig
+15
.editorconfig
···
1
+
# EditorConfig is awesome: https://EditorConfig.org
2
+
3
+
# top-most EditorConfig file
4
+
root = true
5
+
6
+
# Unix-style newlines with a newline ending every file
7
+
[*]
8
+
end_of_line = lf
9
+
insert_final_newline = true
10
+
11
+
# 4 space indentation
12
+
[*.cxx]
13
+
indent_style = space
14
+
indent_size = 4
15
+
+2
-2
Justfile
+2
-2
Justfile
···
22
22
23
23
# Run tests for a specific day. Defaults to today's day-of-month.
24
24
test day=default_day: sync
25
-
day=$(printf '%02d' "{{day}}"); meson test -C build "day${day}"
25
+
day_raw="{{day}}"; day=$(printf '%02d' "$((10#$day_raw))"); meson test -C build "day${day}"
26
26
27
27
# Run a day's solution on the "real" data set.
28
28
run day=default_day: sync-release
29
-
day=$(printf '%02d' "{{day}}"); meson compile -C build-release "run-day${day}"
29
+
day_raw="{{day}}"; day=$(printf '%02d' "$((10#$day_raw))"); meson compile -C build-release "run-day${day}"
30
30
31
31
# Clean the build folder. Useful... sometimes.
32
32
clean:
+1000
data/08/input.txt
+1000
data/08/input.txt
···
1
+
47571,21070,9804
2
+
26014,44873,23440
3
+
21436,20018,6336
4
+
86942,19462,93901
5
+
49070,89301,48095
6
+
35616,79795,87684
7
+
46059,52360,21723
8
+
815,59491,16082
9
+
36997,51041,15723
10
+
48823,39495,7825
11
+
51753,4208,6052
12
+
54168,42076,29285
13
+
20754,25389,97173
14
+
59500,82003,9597
15
+
50009,95623,78606
16
+
16875,26902,85926
17
+
94936,11855,20459
18
+
29649,39961,5964
19
+
75013,82858,46898
20
+
41418,34129,78316
21
+
53899,91211,30110
22
+
23881,28275,96163
23
+
57427,65737,22498
24
+
61932,26265,53341
25
+
66932,22206,44871
26
+
21918,87742,17383
27
+
6367,78929,46730
28
+
45731,28754,95626
29
+
99274,72570,7847
30
+
30049,55955,65389
31
+
29114,49335,69452
32
+
93501,53260,46406
33
+
90751,50824,44853
34
+
17876,94582,42247
35
+
76370,58963,43822
36
+
7098,80312,49281
37
+
84161,27963,78109
38
+
26305,54455,7015
39
+
20715,36202,93555
40
+
53829,86237,93455
41
+
82380,63810,94552
42
+
89368,99839,21849
43
+
87497,47331,94985
44
+
15162,51381,770
45
+
95313,7542,11728
46
+
53233,25116,16166
47
+
39381,93503,98765
48
+
44807,73664,70213
49
+
64971,93696,88679
50
+
57739,609,67547
51
+
20052,59602,10551
52
+
97480,93610,27749
53
+
64800,39151,87207
54
+
20649,60628,94244
55
+
39906,63714,7798
56
+
63509,47318,9956
57
+
4450,90472,41313
58
+
63768,62774,11958
59
+
10544,27294,3096
60
+
36575,34168,46729
61
+
15982,19416,54354
62
+
79358,80933,60698
63
+
28189,14011,71324
64
+
99923,71592,65177
65
+
95588,3920,27088
66
+
20412,59125,6914
67
+
64359,62132,47563
68
+
80252,13527,57773
69
+
55512,16749,62123
70
+
29926,23937,64662
71
+
39571,82975,19998
72
+
45426,9316,91331
73
+
44477,20201,75955
74
+
2271,90540,17806
75
+
50227,93207,93092
76
+
11411,51340,57663
77
+
97754,96323,37130
78
+
98986,72665,15300
79
+
56185,47869,72908
80
+
41878,1363,14758
81
+
17185,33485,94935
82
+
56299,27990,23411
83
+
56452,5027,31447
84
+
29500,44948,51617
85
+
80321,14706,47434
86
+
11412,5698,63814
87
+
20894,72581,79096
88
+
16983,21117,47752
89
+
70243,75746,49340
90
+
8209,66696,24132
91
+
68345,8500,13353
92
+
66274,29803,36754
93
+
73740,3744,81183
94
+
93764,84714,68608
95
+
95758,92527,3581
96
+
1595,75495,24023
97
+
46264,54482,91932
98
+
88312,9307,89820
99
+
52494,90230,12337
100
+
13233,52655,32914
101
+
4316,69743,11655
102
+
60985,41967,58045
103
+
148,48360,76118
104
+
9168,81733,47376
105
+
7509,59153,81292
106
+
9286,92278,40935
107
+
6689,8277,65867
108
+
77303,26813,98281
109
+
97274,74605,8928
110
+
64111,1255,72466
111
+
47709,95260,99519
112
+
76389,53573,75496
113
+
91718,92565,80380
114
+
96354,38927,53770
115
+
54341,34652,75607
116
+
4883,54110,88424
117
+
7132,40749,94152
118
+
12116,58680,18862
119
+
82365,88948,64824
120
+
17238,81714,99059
121
+
7750,63178,72867
122
+
97873,63681,11835
123
+
29111,86352,22560
124
+
22221,10434,97955
125
+
33953,31092,14817
126
+
25563,63991,7561
127
+
91343,83184,43020
128
+
30333,91579,24170
129
+
43793,38500,78262
130
+
91079,65108,91185
131
+
9241,37569,48652
132
+
32460,746,63944
133
+
27812,99211,48865
134
+
33771,79759,60765
135
+
47927,66642,17212
136
+
21386,6415,23249
137
+
37948,8261,87194
138
+
43984,30104,67605
139
+
21734,65992,73999
140
+
86262,95474,9534
141
+
59214,83053,21772
142
+
90581,53940,87498
143
+
8241,19458,85268
144
+
58944,35703,85983
145
+
59911,38963,75410
146
+
99952,28406,68011
147
+
44037,55766,58629
148
+
4033,63003,64904
149
+
80639,28101,43807
150
+
56561,21523,8735
151
+
54799,81572,967
152
+
72303,47576,77866
153
+
73283,18699,89146
154
+
16438,5180,57306
155
+
85275,58630,78887
156
+
73122,12677,20791
157
+
23579,72966,44771
158
+
77605,53061,89981
159
+
44904,96197,31499
160
+
25606,69589,99058
161
+
90709,92773,25475
162
+
13674,79937,55109
163
+
30367,3176,72024
164
+
73198,59340,47212
165
+
66561,11630,359
166
+
81408,91758,96519
167
+
84170,22261,90978
168
+
61563,94745,30976
169
+
98606,76722,59057
170
+
72801,32395,14427
171
+
78479,39897,7663
172
+
97123,13861,46867
173
+
72658,62349,8080
174
+
14154,66620,28768
175
+
4557,99680,63147
176
+
2146,49024,61993
177
+
14654,3716,91456
178
+
66004,116,66251
179
+
2322,16850,71882
180
+
33229,94451,8875
181
+
29805,23309,81315
182
+
50029,36838,21929
183
+
82209,590,52032
184
+
21747,2975,97024
185
+
49535,18114,20733
186
+
3618,28912,40469
187
+
96636,97224,98582
188
+
57756,40775,84060
189
+
34034,79567,87609
190
+
25778,12133,5076
191
+
83296,8348,96603
192
+
70987,83036,78511
193
+
74585,66133,47503
194
+
45046,4953,14146
195
+
73068,56031,53588
196
+
53556,96933,17970
197
+
34304,44725,61677
198
+
81552,5207,10274
199
+
75676,34240,54779
200
+
26235,58317,78470
201
+
49044,58067,48983
202
+
41488,57392,13388
203
+
94175,28337,69652
204
+
22770,10382,52096
205
+
8129,73930,74894
206
+
27652,5751,2110
207
+
90856,9187,3182
208
+
71313,45401,62757
209
+
34566,84469,64732
210
+
59016,52067,4406
211
+
21917,26138,45029
212
+
97263,71628,37478
213
+
59537,72454,41174
214
+
4539,20633,62147
215
+
64138,74645,12101
216
+
83582,87586,79578
217
+
20401,60949,46910
218
+
70557,448,53317
219
+
85318,94930,54753
220
+
70992,94321,97929
221
+
25168,46035,84153
222
+
60606,1952,11388
223
+
21193,43019,39906
224
+
96635,25530,84545
225
+
374,52915,33797
226
+
4568,83473,12379
227
+
48299,44457,82027
228
+
83266,6879,32563
229
+
40391,95543,82502
230
+
38721,83550,86705
231
+
16498,3509,47973
232
+
46405,83872,84187
233
+
82310,92631,8186
234
+
96936,37313,2996
235
+
81772,60821,57329
236
+
71034,95270,59124
237
+
55347,49238,48950
238
+
38397,67390,4520
239
+
63155,14251,65728
240
+
76221,52730,58846
241
+
72010,46346,1935
242
+
10706,67290,12780
243
+
14173,89327,94873
244
+
81847,1935,70812
245
+
662,50973,84260
246
+
5755,43879,46625
247
+
24597,45916,35947
248
+
79693,44291,14249
249
+
57132,19072,4563
250
+
65615,47356,5321
251
+
51448,68876,39994
252
+
97074,47951,9852
253
+
84316,82211,79901
254
+
98008,94765,89135
255
+
66447,25627,42794
256
+
97780,52819,8822
257
+
21586,98713,27242
258
+
56338,25461,57018
259
+
21307,99640,86841
260
+
57220,4743,51006
261
+
54794,89524,22565
262
+
73269,13665,65911
263
+
91607,73120,69334
264
+
58479,41460,10925
265
+
48014,39814,63837
266
+
34417,90040,85444
267
+
7194,36015,93413
268
+
7868,97501,37561
269
+
91080,17487,79945
270
+
69784,87574,12615
271
+
3132,23539,47343
272
+
53840,21079,56691
273
+
14928,70069,77892
274
+
84516,59600,18173
275
+
94950,16419,10539
276
+
95786,75343,20956
277
+
77478,9485,20339
278
+
61532,12904,76720
279
+
57961,93013,50244
280
+
89776,75175,5051
281
+
65822,70073,28510
282
+
40531,35936,69847
283
+
59523,70583,52831
284
+
40175,32972,23371
285
+
90438,35912,38646
286
+
9190,71603,2301
287
+
89914,64437,39884
288
+
19231,20532,21738
289
+
20291,28387,29046
290
+
61401,12081,48512
291
+
70367,83299,72938
292
+
83775,15129,69950
293
+
65702,40589,28248
294
+
67004,66912,6380
295
+
92528,51355,9539
296
+
78714,75787,68757
297
+
11715,10091,10377
298
+
20186,48397,99790
299
+
92315,41383,55587
300
+
92772,78647,24218
301
+
27061,61947,52007
302
+
56991,14015,55863
303
+
61421,37878,69228
304
+
92103,39528,29743
305
+
72506,97359,35180
306
+
53018,24457,19496
307
+
3710,47703,24976
308
+
22916,27182,6379
309
+
42884,85646,26272
310
+
82100,98605,30769
311
+
1821,91791,94846
312
+
83792,55739,65047
313
+
46214,65415,81282
314
+
66988,40521,21596
315
+
45494,52681,57995
316
+
2212,70960,79823
317
+
33321,19720,39301
318
+
19669,55897,20490
319
+
9730,6780,10006
320
+
55897,67619,63154
321
+
85947,46340,80569
322
+
17833,80348,39175
323
+
53730,29488,16550
324
+
97827,97934,56043
325
+
79680,52251,79901
326
+
15440,84026,45232
327
+
34900,47716,88735
328
+
31175,30778,37122
329
+
653,6797,65269
330
+
39498,56985,61145
331
+
13639,4464,54937
332
+
36506,73704,92509
333
+
87986,54749,53371
334
+
86831,89128,24572
335
+
30369,50407,58265
336
+
44688,73717,6276
337
+
34669,23598,35669
338
+
38200,44889,66909
339
+
5804,48890,22794
340
+
33804,15381,41749
341
+
31083,32018,9933
342
+
41887,64511,29207
343
+
86779,64028,44144
344
+
82940,57300,4258
345
+
11837,83350,22362
346
+
53566,55374,15050
347
+
94542,42256,70529
348
+
57924,9304,52928
349
+
37874,91291,5924
350
+
27458,33422,50557
351
+
40032,20648,34773
352
+
19329,95504,64776
353
+
43060,59066,72108
354
+
38735,37842,70331
355
+
34756,30542,72483
356
+
8645,64076,29678
357
+
14422,9744,59856
358
+
36690,33825,5724
359
+
28010,71813,49198
360
+
79220,57332,56033
361
+
85797,27675,39216
362
+
20001,86620,15888
363
+
46676,25791,13225
364
+
31040,8856,9734
365
+
69598,20191,54257
366
+
31748,94398,62648
367
+
56233,47124,70615
368
+
86810,74097,63829
369
+
55402,87748,14049
370
+
64651,2504,94470
371
+
27971,25371,34425
372
+
7225,62165,53127
373
+
77869,9942,69819
374
+
72986,43646,21958
375
+
13212,64016,58505
376
+
99141,27615,61691
377
+
21479,16593,66867
378
+
13086,99145,53945
379
+
39562,70835,13715
380
+
77232,8696,6263
381
+
43493,37183,20948
382
+
90373,8567,28002
383
+
54144,51686,74721
384
+
20266,92932,54157
385
+
77664,69955,28639
386
+
18112,57499,37970
387
+
15268,17169,42698
388
+
32468,30659,49133
389
+
34070,13151,91140
390
+
87010,95748,2013
391
+
46275,45143,53050
392
+
10494,54292,36448
393
+
50234,76183,70819
394
+
80526,16331,62884
395
+
6032,43454,88976
396
+
1797,46200,32248
397
+
26840,76571,42950
398
+
27949,6053,95123
399
+
40843,57826,7905
400
+
62034,4876,80293
401
+
9905,9552,83286
402
+
75639,43573,56302
403
+
77035,5633,66609
404
+
11388,10209,68548
405
+
58492,99441,377
406
+
40265,14242,48084
407
+
4968,53030,15790
408
+
3046,79682,31531
409
+
71977,44774,83696
410
+
30341,61916,1749
411
+
30350,11026,837
412
+
44840,32588,63636
413
+
88505,10183,71612
414
+
32489,46938,18115
415
+
12210,5579,13040
416
+
17211,56521,90358
417
+
12646,96369,22505
418
+
34639,2499,36923
419
+
59882,65605,45102
420
+
77122,1567,96902
421
+
32974,16234,91201
422
+
52678,75753,35067
423
+
25434,92606,39762
424
+
93863,32581,75702
425
+
55269,32940,90736
426
+
31196,79296,2411
427
+
32139,5425,88534
428
+
42087,6540,70085
429
+
47680,12084,40442
430
+
82708,7433,75986
431
+
70100,43677,91632
432
+
75563,23981,42045
433
+
62069,50198,16274
434
+
91806,43797,19221
435
+
94941,43234,34002
436
+
93098,75133,93017
437
+
48110,24269,17706
438
+
90038,11689,72942
439
+
70544,38775,33456
440
+
2341,41646,83120
441
+
80223,44823,83163
442
+
23490,69775,90768
443
+
27119,88592,42351
444
+
49695,70167,79602
445
+
19734,54281,76912
446
+
3279,5818,16862
447
+
81007,57021,81242
448
+
81876,58981,63066
449
+
43321,31203,33556
450
+
31841,1330,10307
451
+
7949,71731,55618
452
+
26908,18268,30532
453
+
30285,88907,22633
454
+
24152,45805,60561
455
+
79302,72702,76457
456
+
24447,34767,60079
457
+
43353,98225,81031
458
+
68030,16759,9191
459
+
10141,12438,160
460
+
23463,5953,51134
461
+
15644,40590,57515
462
+
7584,17705,36278
463
+
45766,1900,6245
464
+
86762,62967,34062
465
+
54341,66546,41201
466
+
78187,91320,38408
467
+
37740,21065,4798
468
+
69745,98152,82847
469
+
58165,40210,7664
470
+
57808,97649,77099
471
+
59203,67064,43833
472
+
46238,42254,26635
473
+
42951,88292,67386
474
+
36255,71840,99352
475
+
86904,78475,63880
476
+
54625,41741,21814
477
+
51844,76869,66151
478
+
25449,1275,32406
479
+
53191,93381,13297
480
+
5047,32201,16966
481
+
78811,90884,23148
482
+
7102,60280,11362
483
+
74647,66893,26489
484
+
59242,8613,34456
485
+
28920,62015,38343
486
+
27722,65056,73880
487
+
84968,18892,48779
488
+
33795,33661,27615
489
+
95964,60359,73002
490
+
47608,24948,90615
491
+
83227,61252,77096
492
+
19549,49439,77542
493
+
38483,9359,99684
494
+
78665,15778,25976
495
+
13515,34388,9467
496
+
27094,30181,47555
497
+
77474,87811,56069
498
+
11371,79142,62321
499
+
35008,74101,91095
500
+
62614,92190,30576
501
+
45410,96553,90163
502
+
54834,29978,70659
503
+
73603,93724,29451
504
+
89408,16626,97888
505
+
61381,98593,92817
506
+
41656,60287,40274
507
+
42710,95785,86735
508
+
40148,27444,62101
509
+
38839,2726,156
510
+
53884,39879,77757
511
+
50182,33953,83335
512
+
4024,39407,78713
513
+
71201,69212,47612
514
+
72814,63909,21368
515
+
25091,8651,21835
516
+
66834,49263,47463
517
+
5794,19003,38757
518
+
25736,83973,63167
519
+
67326,69732,77723
520
+
55857,72729,21881
521
+
50893,26818,86959
522
+
21374,85006,32064
523
+
46247,5364,83390
524
+
64814,27275,70599
525
+
55152,54557,13088
526
+
24181,58143,23758
527
+
13931,48317,38065
528
+
66846,58449,51695
529
+
17876,21013,65658
530
+
99456,42478,6183
531
+
2146,27003,13244
532
+
79344,99111,98338
533
+
95675,22459,34986
534
+
67511,11973,23633
535
+
99088,18678,44464
536
+
17574,15741,74468
537
+
52103,86699,84509
538
+
78626,11978,41367
539
+
47184,33523,33023
540
+
62769,24411,39138
541
+
87083,10852,31442
542
+
71856,70552,41731
543
+
22827,20002,50990
544
+
3114,77254,71048
545
+
90444,55101,96536
546
+
12030,39124,9112
547
+
94730,50534,98462
548
+
65481,15521,6185
549
+
95416,25512,66803
550
+
30379,44564,35308
551
+
62359,30836,858
552
+
4783,30816,54071
553
+
93777,17819,93849
554
+
86860,48488,79960
555
+
38540,2096,26954
556
+
23403,55836,96988
557
+
92987,29804,88423
558
+
55332,20896,27899
559
+
10502,40551,24563
560
+
52516,39967,73612
561
+
99221,5902,84311
562
+
27715,4077,71754
563
+
26862,39283,2862
564
+
91760,34382,78320
565
+
49179,7364,82913
566
+
78199,2221,93708
567
+
61153,9597,79648
568
+
5073,82720,11302
569
+
61822,12463,66129
570
+
4315,14262,34326
571
+
77730,8771,72616
572
+
44595,64796,26351
573
+
61178,31519,77512
574
+
15747,87199,83147
575
+
16945,74163,59198
576
+
87054,85958,93672
577
+
28777,63191,29253
578
+
14354,8173,49003
579
+
52594,74550,96034
580
+
38416,18312,17255
581
+
73466,43537,40330
582
+
56769,52928,16350
583
+
96188,24420,61532
584
+
92933,42686,80599
585
+
74947,24413,55186
586
+
13898,41541,45573
587
+
5903,9073,21540
588
+
31417,19227,24337
589
+
5684,18176,63010
590
+
40224,43390,75761
591
+
98842,81166,44187
592
+
60881,32949,51308
593
+
53788,17800,23102
594
+
634,7754,1148
595
+
10482,71646,44004
596
+
7876,40227,62958
597
+
34829,29713,27785
598
+
68001,35821,96923
599
+
12827,8515,47275
600
+
54025,36049,42296
601
+
50915,34964,4004
602
+
23993,52708,56057
603
+
14674,10455,38981
604
+
31864,82531,59991
605
+
47438,24692,70707
606
+
92477,3072,40434
607
+
43571,76861,58998
608
+
80011,43036,49467
609
+
78019,90390,53249
610
+
53615,57975,45625
611
+
1702,24160,35037
612
+
35805,90333,23305
613
+
37707,79539,11741
614
+
2905,31052,78344
615
+
76311,17530,7380
616
+
44106,13061,19110
617
+
94819,93976,56394
618
+
12610,69169,81221
619
+
53121,60839,43572
620
+
21724,18243,70406
621
+
53261,60232,97572
622
+
28546,53689,69683
623
+
12694,57936,65968
624
+
82882,35505,12859
625
+
66837,55685,71303
626
+
11623,65623,62165
627
+
90587,26879,99017
628
+
27843,99230,84416
629
+
18509,40083,47141
630
+
32637,34159,3665
631
+
58801,76994,2826
632
+
73093,1048,47133
633
+
26146,25503,49013
634
+
7857,22552,93407
635
+
49429,99842,3603
636
+
54820,29343,21395
637
+
64989,49335,40131
638
+
40602,70291,18076
639
+
32379,67852,85939
640
+
20612,72997,59130
641
+
14587,34614,74057
642
+
72896,28351,44524
643
+
85587,53315,64171
644
+
36796,65835,69821
645
+
83564,79081,95423
646
+
56047,43325,37106
647
+
74816,99621,54441
648
+
70201,80468,22097
649
+
58402,85776,84389
650
+
4333,87626,83957
651
+
95489,48004,48147
652
+
37140,48179,76671
653
+
12264,22325,77463
654
+
70235,26337,43215
655
+
46901,79727,68156
656
+
23161,20519,23792
657
+
59846,24712,14913
658
+
88611,29379,9015
659
+
39654,50052,26737
660
+
56287,59461,66472
661
+
88871,52617,18550
662
+
79113,24225,16655
663
+
10981,25969,55227
664
+
8510,67023,66310
665
+
32241,81237,37402
666
+
13931,70565,9485
667
+
79335,45054,82935
668
+
49671,91517,34724
669
+
92078,48871,72204
670
+
56332,34226,55585
671
+
24562,71347,66647
672
+
82680,47080,28954
673
+
96352,1933,91494
674
+
72322,67853,89273
675
+
65082,14009,14444
676
+
1530,93847,47174
677
+
57820,18394,44986
678
+
22059,67185,79553
679
+
54557,53617,82442
680
+
46335,94730,72199
681
+
1962,12383,95849
682
+
65542,7955,29447
683
+
65144,38401,90221
684
+
35508,96042,82430
685
+
59163,14334,70945
686
+
70460,53300,52123
687
+
34023,78099,25284
688
+
19821,58522,74364
689
+
78588,13592,91207
690
+
89449,57983,53125
691
+
12631,60064,18667
692
+
23148,69953,14387
693
+
98065,60673,84824
694
+
3390,41925,34979
695
+
4661,22151,32161
696
+
42596,95326,23249
697
+
82168,82291,87225
698
+
78988,98863,79186
699
+
6992,45268,16858
700
+
69975,2042,57466
701
+
34943,27480,95116
702
+
8672,88889,10200
703
+
67403,28635,76571
704
+
46559,40091,74483
705
+
32881,7955,1367
706
+
51198,10001,96743
707
+
64130,56646,87474
708
+
80325,76483,89384
709
+
57046,60012,101
710
+
15077,16678,7927
711
+
3728,94382,39608
712
+
15964,69261,26463
713
+
83716,84460,70427
714
+
37320,30284,25700
715
+
46415,18770,63022
716
+
53399,28785,13774
717
+
74314,24151,28583
718
+
57140,15836,8623
719
+
71056,64222,65027
720
+
81218,79768,87696
721
+
22604,98045,70064
722
+
58915,75139,69740
723
+
56457,97339,81568
724
+
52208,10114,12451
725
+
74661,63103,4369
726
+
66959,4518,62250
727
+
49440,99642,8009
728
+
1807,65914,78391
729
+
27868,87246,62097
730
+
28780,60481,87911
731
+
27347,46484,10107
732
+
79586,4525,90940
733
+
17376,89075,64772
734
+
86798,5050,78881
735
+
40056,44781,7813
736
+
59740,19006,96758
737
+
84464,39836,33204
738
+
15036,29703,16044
739
+
40650,23464,33328
740
+
27586,94834,79957
741
+
72347,33172,98871
742
+
14928,56291,35185
743
+
19170,98017,88766
744
+
69095,39961,3157
745
+
14921,52255,4091
746
+
77408,21152,57035
747
+
15144,47264,61817
748
+
41243,87263,23238
749
+
49725,50503,70957
750
+
72742,49967,58307
751
+
62427,6785,17789
752
+
49372,10110,79026
753
+
73493,89522,62465
754
+
88764,83921,83214
755
+
85906,51672,39417
756
+
59951,8945,94301
757
+
66027,79004,89099
758
+
7721,79152,13019
759
+
31354,81139,71349
760
+
94292,22483,23272
761
+
83134,50745,53565
762
+
64572,51568,54087
763
+
35576,40786,82339
764
+
71536,29869,62731
765
+
82761,89931,9438
766
+
30326,6389,41591
767
+
88438,4028,46263
768
+
43045,39921,83709
769
+
19525,88390,6197
770
+
94923,78355,59908
771
+
66648,53480,72957
772
+
10316,95770,80697
773
+
64258,78272,34499
774
+
9602,14890,55144
775
+
32620,44416,74996
776
+
74381,54598,75987
777
+
68025,31961,88390
778
+
80103,84533,18000
779
+
52588,26228,18397
780
+
85996,65143,44905
781
+
58927,60922,53393
782
+
63291,59103,83939
783
+
44399,42038,79279
784
+
66706,53739,81533
785
+
97850,28487,74736
786
+
11409,45929,74659
787
+
76366,10982,68153
788
+
45192,22217,8001
789
+
12567,79477,83157
790
+
99016,29496,15868
791
+
99441,48371,39632
792
+
13125,33481,67353
793
+
14041,98765,696
794
+
57667,56475,65880
795
+
73596,42904,3828
796
+
40033,2119,49966
797
+
47248,88788,35167
798
+
12448,95861,56639
799
+
52634,66539,44159
800
+
78326,13152,13323
801
+
84603,97333,88368
802
+
25207,75486,41433
803
+
48253,93053,34986
804
+
43208,54954,83110
805
+
76374,5075,87221
806
+
91156,42808,47615
807
+
19242,85722,11737
808
+
49409,18079,11095
809
+
2164,15802,99410
810
+
51637,23686,84491
811
+
8799,33160,78581
812
+
45410,37478,85256
813
+
48724,80570,70207
814
+
5337,32514,2350
815
+
25825,34176,15584
816
+
23758,37015,71970
817
+
67949,45676,17850
818
+
69889,22576,9602
819
+
49666,25941,51764
820
+
82425,36914,85367
821
+
71935,5950,24079
822
+
99034,60825,28744
823
+
47463,71130,7873
824
+
65916,77191,67546
825
+
52639,64934,27059
826
+
25286,43802,54243
827
+
21765,82892,46133
828
+
83714,55468,26432
829
+
8234,25559,71966
830
+
69309,17480,92126
831
+
86058,99047,87034
832
+
70891,95150,42356
833
+
9190,82148,93273
834
+
88920,38914,57393
835
+
62428,31091,34420
836
+
34320,75262,48894
837
+
71159,98023,37547
838
+
16134,23614,55280
839
+
69673,12353,1603
840
+
49368,97222,43249
841
+
84405,95532,66840
842
+
37839,3437,48182
843
+
22393,71847,80523
844
+
93911,50316,60776
845
+
43028,3938,60629
846
+
27619,3021,9514
847
+
77399,27707,8919
848
+
57263,83406,68290
849
+
22053,30972,96730
850
+
53940,36034,57408
851
+
41239,99148,63259
852
+
57045,78769,10005
853
+
58374,63114,26580
854
+
50821,77483,49296
855
+
82959,42165,29481
856
+
96273,24985,2153
857
+
49241,7520,19081
858
+
50757,94282,77801
859
+
38752,75862,20439
860
+
26794,19821,90257
861
+
60011,47770,15012
862
+
99084,34347,79964
863
+
69079,11566,60069
864
+
75589,80080,46358
865
+
2731,39043,87971
866
+
81258,93577,27120
867
+
98782,3083,31148
868
+
21067,10434,97759
869
+
17633,90336,18283
870
+
42288,35286,35492
871
+
97043,85410,6868
872
+
15744,47437,31523
873
+
39150,72388,66272
874
+
29176,54342,60288
875
+
17332,51184,31921
876
+
98546,6055,85092
877
+
25437,71642,66423
878
+
10807,74499,22047
879
+
65389,64539,92105
880
+
13522,94556,95640
881
+
88993,44952,15621
882
+
44035,68710,12057
883
+
34173,62229,34852
884
+
48462,14122,96488
885
+
42631,98310,94112
886
+
28817,73863,45216
887
+
99285,74724,42942
888
+
32630,41705,74013
889
+
52914,89386,95045
890
+
3556,18655,22825
891
+
2197,65519,88154
892
+
56784,5609,52806
893
+
4401,90031,71062
894
+
89583,17186,94403
895
+
36613,70447,35887
896
+
93664,54419,41441
897
+
96846,91670,87650
898
+
52315,40033,99990
899
+
75452,67163,63407
900
+
44113,22893,12942
901
+
65470,67631,10701
902
+
18129,39210,64248
903
+
41498,571,37885
904
+
27692,49007,90764
905
+
65234,44201,37549
906
+
98101,76266,62596
907
+
89892,60472,76556
908
+
44543,72496,99023
909
+
37655,77646,27591
910
+
61180,40551,94668
911
+
45105,30201,36649
912
+
1620,31850,73921
913
+
58609,32384,11624
914
+
22892,66188,2899
915
+
62972,33611,70756
916
+
98837,98135,5464
917
+
66354,96306,20181
918
+
90856,2587,42432
919
+
43583,72337,78299
920
+
8702,45615,61530
921
+
65039,22806,64843
922
+
20120,41245,2180
923
+
30525,30948,54581
924
+
98879,57234,78496
925
+
41667,25886,83297
926
+
55523,71875,31645
927
+
92425,62653,32116
928
+
98157,24050,87488
929
+
15418,7193,9628
930
+
24897,83358,13207
931
+
77311,85920,40203
932
+
93757,20098,21627
933
+
23158,29915,65544
934
+
96552,55054,86728
935
+
63301,54813,44068
936
+
9332,69606,9495
937
+
74920,57406,77815
938
+
39925,15384,17409
939
+
76192,66369,4419
940
+
7579,48260,96351
941
+
59656,30550,75934
942
+
67737,67440,2241
943
+
49823,35541,55277
944
+
49428,19266,20196
945
+
39982,30538,15958
946
+
97713,42981,17162
947
+
44913,5665,26625
948
+
68888,94239,48645
949
+
20780,45996,92313
950
+
95933,17224,21793
951
+
63415,21295,8067
952
+
55039,38657,95442
953
+
75331,70835,14103
954
+
54143,10508,68882
955
+
43973,68618,68679
956
+
70531,12478,99652
957
+
35890,82580,8365
958
+
82110,41720,78025
959
+
47005,86989,64248
960
+
82238,51772,65545
961
+
63597,41735,96550
962
+
27146,93957,15649
963
+
49435,67306,14087
964
+
85150,43746,62836
965
+
69372,82749,49615
966
+
60686,63853,9791
967
+
25514,76765,56150
968
+
40131,55748,98207
969
+
74245,17028,5951
970
+
30561,94489,18399
971
+
70284,31612,20113
972
+
40691,63157,12305
973
+
98572,87740,48052
974
+
4913,93685,72983
975
+
4390,29821,52250
976
+
27517,82896,47853
977
+
95298,50022,36325
978
+
15917,50554,71325
979
+
2439,13008,41417
980
+
63228,43487,2803
981
+
27655,25186,81653
982
+
1750,16142,28036
983
+
795,65209,42189
984
+
43047,74977,86760
985
+
9260,32662,4268
986
+
89945,53054,67979
987
+
66023,27710,75801
988
+
34051,71757,96026
989
+
74547,84567,40114
990
+
55156,40862,19705
991
+
88279,57251,52701
992
+
97760,82882,52581
993
+
71440,82452,62216
994
+
12542,33903,6417
995
+
68098,28185,12970
996
+
19268,67975,24536
997
+
83973,44435,89151
998
+
96679,29711,69197
999
+
17807,80459,30036
1000
+
82541,92402,2312
+20
data/08/test.txt
+20
data/08/test.txt
···
1
+
162,817,812
2
+
57,618,57
3
+
906,360,560
4
+
592,479,940
5
+
352,342,300
6
+
466,668,158
7
+
542,29,236
8
+
431,825,988
9
+
739,650,466
10
+
52,470,668
11
+
216,146,977
12
+
819,987,18
13
+
117,168,530
14
+
805,96,715
15
+
346,949,466
16
+
970,615,88
17
+
941,993,340
18
+
862,61,35
19
+
984,92,344
20
+
425,690,689
+199
src/08/solution.cxx
+199
src/08/solution.cxx
···
1
+
#include <algorithm>
2
+
#include <cmath>
3
+
#include <fstream>
4
+
#include <iterator>
5
+
#include <map>
6
+
#include <print>
7
+
#include <ranges>
8
+
#include <set>
9
+
#include <vector>
10
+
11
+
#include "common/getinputpath.h"
12
+
#include "common/istest.h"
13
+
14
+
const int STEPS = is_test() ? 10 : 1000;
15
+
16
+
struct Box {
17
+
int x;
18
+
int y;
19
+
int z;
20
+
21
+
float euclidean(Box& other) {
22
+
return std::sqrt(std::pow((other.x - this->x), 2) +
23
+
std::pow((other.y - this->y), 2) +
24
+
std::pow((other.z - this->z), 2));
25
+
}
26
+
27
+
bool operator==(const Box other) const {
28
+
return this->x == other.x && this->y == other.y && this->z == other.z;
29
+
}
30
+
31
+
bool operator<(const Box other) const {
32
+
return this->x < other.x || (this->x == other.x && this->y < other.y) ||
33
+
(this->x == other.x && this->y == other.y && this->z < other.z);
34
+
}
35
+
36
+
std::string to_string() { return std::format("{} {} {}", x, y, z); }
37
+
};
38
+
39
+
struct Connection {
40
+
Box a;
41
+
Box b;
42
+
float distance;
43
+
44
+
bool operator==(const Connection& other) const {
45
+
return (other.a == this->a && other.b == this->b) ||
46
+
(other.a == this->b && other.b == this->a);
47
+
}
48
+
49
+
bool contains(Box box) { return this->a == box || this->b == box; }
50
+
51
+
bool connected(Connection connection) {
52
+
return this->contains(connection.a) || this->contains(connection.b);
53
+
}
54
+
55
+
bool operator<(const Connection other) const {
56
+
return this->distance < other.distance;
57
+
}
58
+
};
59
+
60
+
Connection make_connection(Box& one, Box& other) {
61
+
return Connection{.a = one, .b = other, .distance = one.euclidean(other)};
62
+
}
63
+
64
+
// standard DSU
65
+
class DSU {
66
+
std::vector<int> size{};
67
+
std::vector<int> parent{};
68
+
69
+
public:
70
+
DSU(int n) {
71
+
parent.resize(n);
72
+
size.resize(n);
73
+
74
+
for (int i = 0; i < n; ++i) {
75
+
parent[i] = i;
76
+
size[i] = 1;
77
+
}
78
+
}
79
+
80
+
int find(int i) {
81
+
return (parent[i] == i) ? i : (parent[i] = find(parent[i]));
82
+
}
83
+
84
+
void unite(int x, int y) {
85
+
int s1 = find(x);
86
+
int s2 = find(y);
87
+
88
+
if (s1 == s2) {
89
+
return;
90
+
}
91
+
if (size[s1] < size[s2]) {
92
+
parent[s1] = s2;
93
+
size[s2] += size[s1];
94
+
} else if (size[s1] > size[s2]) {
95
+
parent[s2] = s1;
96
+
size[s1] += size[s2];
97
+
} else {
98
+
parent[s2] = s1;
99
+
size[s1] += size[s2];
100
+
}
101
+
}
102
+
103
+
std::vector<int> sizes() { return size; }
104
+
};
105
+
106
+
int main() {
107
+
auto path = get_input_path(DATA_FOLDER);
108
+
std::ifstream data_ifstream(path);
109
+
if (!data_ifstream.is_open()) {
110
+
std::println("Cannot open the file at {}", path.string());
111
+
return 1;
112
+
}
113
+
114
+
std::vector<Box> data{};
115
+
for (std::string t; std::getline(data_ifstream, t);) {
116
+
int x{};
117
+
int y{};
118
+
int z{};
119
+
120
+
auto first_comma_idx = t.find_first_of(',');
121
+
auto x_str = t.substr(0, first_comma_idx);
122
+
auto yz_str = t.substr(first_comma_idx + 1);
123
+
auto second_comma_idx = yz_str.find_first_of(',');
124
+
auto y_str = yz_str.substr(0, second_comma_idx);
125
+
auto z_str = yz_str.substr(second_comma_idx + 1);
126
+
127
+
x = std::stoi(x_str);
128
+
y = std::stoi(y_str);
129
+
z = std::stoi(z_str);
130
+
131
+
data.push_back(Box{.x = x, .y = y, .z = z});
132
+
}
133
+
134
+
long long estimated_conns = data.size() * data.size() - data.size();
135
+
std::print("Generating connections... est. {}", estimated_conns);
136
+
137
+
// replacing this with an unordered set would make things faster
138
+
std::set<Connection> connections{};
139
+
for (auto box1 : data) {
140
+
for (auto box2 : data) {
141
+
if (box1 == box2) {
142
+
continue;
143
+
}
144
+
145
+
Connection conn = make_connection(box1, box2);
146
+
if (connections.contains(conn)) { // connection already exists
147
+
continue;
148
+
}
149
+
connections.insert(conn);
150
+
std::print("\r");
151
+
}
152
+
}
153
+
std::println();
154
+
155
+
std::println("Sorting connections...");
156
+
std::vector<Connection> connections_vec =
157
+
connections | std::ranges::to<std::vector<Connection>>();
158
+
std::ranges::sort(connections_vec, [](Connection one, Connection other) {
159
+
return one.distance < other.distance;
160
+
});
161
+
162
+
std::println("Calculating three largest connected components...");
163
+
DSU dsu(data.size());
164
+
165
+
std::map<Box, size_t> data_idxs{};
166
+
for (auto [idx, box] : data | std::ranges::views::enumerate) {
167
+
data_idxs[box] = idx;
168
+
}
169
+
170
+
long long counter = 0;
171
+
Connection last_connected;
172
+
long long password_part_1;
173
+
for (auto conn : connections_vec) {
174
+
counter += 1;
175
+
if (dsu.find(data_idxs[conn.a]) != dsu.find(data_idxs[conn.b])) {
176
+
dsu.unite(data_idxs[conn.a], data_idxs[conn.b]);
177
+
last_connected = conn;
178
+
}
179
+
if (counter == STEPS) {
180
+
auto sizes = dsu.sizes();
181
+
std::ranges::sort(sizes);
182
+
std::ranges::reverse(sizes);
183
+
184
+
std::println("Three biggest: {}, {}, {}", sizes[0], sizes[1],
185
+
sizes[2]);
186
+
int s1 = sizes[0];
187
+
int s2 = sizes[1];
188
+
int s3 = sizes[2];
189
+
password_part_1 = s1 * s2 * s3;
190
+
}
191
+
}
192
+
193
+
long long password_part_2 = last_connected.a.x * last_connected.b.x;
194
+
195
+
std::println();
196
+
std::println("Eureka! {} / {}", password_part_1, password_part_2);
197
+
198
+
return 0;
199
+
}