aspik79

14370166?v=4

aspik79
: aspik79

About me

Nothing here yet. Update your profile at /profiles/aspik79.adoc

Day 01: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

main.ts
// Sonar sweeper solution by Christoph Jobmann

import { SonarSweeper } from "./sonarSweeper";

const sweeper = new SonarSweeper();
sweeper.RunSilver();
sweeper.RunGold();
sonarSweeper.ts
// --- Day 1: Sonar Sweep ---
import * as fs from 'fs';

export class SonarSweeper {
    private lines: string[];

    public constructor(){
        this.lines = this.Read();
    }

    public RunSilver(){
        let previous: number = 0;
        let count: number = 0;

        for (let index = 0; index < this.lines.length; ++index) {
            const i = parseInt(this.lines[index]);
            if (previous != 0 && i > previous){
                ++count;
            }

            previous = i;
        }

        console.log(count);
    }

    public RunGold(){
        let sumPrevious: number = 0;
        let count: number = 0;

        for (let index = 0; index < this.lines.length - 2; ++index) {
            const i1 = parseInt(this.lines[index]);
            const i2 = parseInt(this.lines[index + 1]);
            const i3 = parseInt(this.lines[index + 2]);

            const sumCurrent = i1 + i2 + i3;
            if (sumPrevious != 0 && sumPrevious < sumCurrent){
                ++count;
            }

            sumPrevious = sumCurrent;
        }

        console.log(count);
    }


    Read() : string[] {
        let input: string;

        if (fs.existsSync('day01/typescript/aspik79/input.txt')) {
            input = fs.readFileSync('day01/typescript/aspik79/input.txt','utf8');
        }
        else {
            input = fs.readFileSync('input.txt','utf8');
        }

        return input.split('\r\n')
    }
}
input.txt
104
111
124
139
142
141
144
151
152
154
157
156
157
149
123
118
129
133
134
130
124
102
103
105
104
99
100
101
103
116
114
129
135
147
149
148
149
137
140
149
159
157
159
165
164
170
176
180
192
198
200
202
203
202
211
212
230
233
237
229
226
229
234
242
245
244
242
256
258
262
267
269
285
274
279
270
302
305
308
320
323
324
323
325
358
361
367
364
363
351
352
350
349
355
356
359
367
375
405
413
417
425
428
436
437
438
430
429
430
431
442
451
459
460
473
481
482
483
485
491
501
499
532
533
538
540
514
505
511
508
509
507
519
521
492
493
498
497
499
510
508
501
507
509
528
529
539
545
546
575
577
599
600
602
609
634
635
637
652
660
692
677
676
679
682
683
684
688
687
688
709
708
710
713
714
729
724
723
725
728
727
722
728
759
760
764
771
754
768
761
767
798
791
811
812
831
834
842
854
855
863
864
868
882
887
891
899
902
903
906
908
915
943
937
941
928
941
928
922
924
940
950
949
950
951
947
948
955
958
960
963
956
955
957
960
965
966
967
968
969
977
945
929
925
926
939
943
944
956
965
961
968
967
966
970
968
973
975
990
1003
1005
1006
1009
1011
1009
1015
1016
1015
1000
1005
1009
1005
1011
1008
1017
1016
1017
1018
1013
1012
1015
1012
1003
1004
1005
1008
1016
1021
1023
1051
1052
1057
1059
1067
1064
1060
1062
1071
1065
1077
1079
1081
1085
1091
1089
1092
1093
1103
1083
1102
1111
1113
1120
1131
1132
1152
1153
1162
1161
1160
1145
1154
1159
1148
1160
1161
1162
1187
1193
1184
1192
1190
1191
1196
1200
1205
1207
1209
1208
1209
1210
1211
1223
1225
1226
1227
1217
1211
1212
1216
1209
1210
1219
1218
1219
1220
1219
1220
1215
1242
1246
1247
1233
1264
1297
1284
1288
1313
1333
1339
1334
1341
1345
1351
1350
1353
1349
1352
1351
1352
1353
1355
1333
1334
1335
1336
1337
1309
1316
1315
1316
1325
1343
1345
1347
1334
1337
1336
1337
1343
1346
1347
1342
1328
1326
1327
1328
1320
1324
1334
1336
1337
1338
1348
1350
1358
1374
1377
1380
1366
1368
1372
1376
1377
1380
1382
1392
1396
1402
1407
1408
1423
1428
1422
1424
1427
1440
1439
1438
1454
1460
1461
1462
1466
1471
1470
1448
1455
1460
1470
1480
1488
1497
1502
1503
1505
1502
1503
1510
1519
1523
1526
1527
1526
1530
1526
1536
1534
1539
1553
1557
1562
1569
1570
1584
1601
1564
1577
1582
1584
1585
1586
1589
1583
1595
1608
1612
1610
1605
1611
1615
1619
1620
1621
1624
1626
1628
1621
1635
1637
1645
1646
1656
1658
1657
1667
1672
1674
1675
1678
1692
1693
1696
1713
1714
1715
1734
1736
1738
1756
1757
1780
1772
1777
1776
1783
1786
1792
1791
1792
1797
1799
1794
1811
1795
1793
1780
1782
1791
1789
1800
1799
1797
1814
1812
1818
1842
1853
1871
1872
1876
1877
1882
1883
1874
1876
1879
1893
1894
1911
1877
1880
1883
1884
1887
1885
1892
1897
1912
1917
1931
1934
1935
1926
1930
1945
1943
1942
1943
1941
1943
1947
1941
1950
1955
1980
1981
1986
1987
2000
2005
1999
2009
2010
2006
1998
1999
2009
2016
2017
1984
1985
1986
1985
1988
2011
2018
2019
2023
2026
2034
2041
2043
2060
2068
2072
2079
2082
2083
2077
2109
2111
2118
2146
2149
2151
2148
2147
2137
2138
2128
2138
2139
2163
2164
2194
2196
2197
2198
2199
2201
2211
2242
2244
2248
2225
2226
2235
2231
2232
2233
2234
2237
2233
2232
2235
2217
2228
2234
2235
2234
2237
2238
2249
2250
2252
2273
2261
2278
2279
2275
2274
2273
2271
2284
2289
2282
2284
2282
2283
2286
2288
2302
2321
2360
2368
2369
2364
2373
2379
2378
2386
2391
2398
2399
2400
2401
2409
2416
2414
2413
2412
2418
2406
2429
2449
2446
2449
2438
2448
2450
2413
2422
2424
2425
2429
2430
2431
2426
2428
2431
2417
2419
2420
2427
2421
2424
2433
2434
2435
2436
2462
2440
2443
2442
2454
2455
2458
2447
2448
2450
2455
2462
2464
2472
2477
2482
2483
2501
2511
2516
2517
2514
2520
2521
2525
2539
2553
2554
2543
2548
2544
2552
2551
2553
2589
2588
2594
2599
2614
2615
2629
2630
2639
2644
2646
2665
2657
2668
2669
2681
2680
2684
2691
2693
2686
2681
2680
2683
2687
2694
2696
2698
2702
2690
2694
2693
2698
2707
2716
2714
2713
2714
2724
2747
2748
2750
2752
2760
2756
2757
2755
2756
2762
2765
2778
2777
2778
2777
2775
2778
2770
2762
2754
2755
2757
2770
2771
2784
2815
2836
2837
2838
2839
2847
2848
2850
2826
2806
2820
2826
2827
2832
2837
2848
2859
2866
2865
2873
2874
2876
2879
2886
2861
2865
2876
2875
2872
2874
2879
2889
2899
2908
2909
2915
2903
2915
2925
2918
2919
2920
2936
2932
2922
2923
2935
2940
2947
2969
2963
2940
2944
2945
2949
2964
2967
2968
2985
2986
2973
2974
2969
2970
2965
2966
2967
2953
2957
2956
2964
2977
2974
2983
2996
2994
2992
2999
2988
2974
2980
2985
2986
2993
3007
3008
3007
3014
3013
3031
3027
3029
3026
3027
3035
3036
3037
3052
3054
3055
3059
3057
3059
3058
3064
3063
3065
3066
3070
3072
3104
3111
3103
3111
3112
3138
3137
3150
3137
3138
3139
3142
3154
3156
3157
3158
3160
3152
3157
3143
3147
3159
3161
3162
3160
3163
3164
3160
3161
3167
3181
3182
3190
3191
3193
3192
3193
3205
3206
3216
3229
3230
3228
3230
3218
3198
3205
3233
3234
3222
3217
3221
3242
3243
3258
3275
3276
3281
3283
3304
3303
3307
3309
3308
3307
3304
3315
3328
3355
3375
3368
3374
3403
3404
3406
3409
3411
3409
3392
3400
3404
3405
3406
3403
3405
3408
3430
3439
3440
3458
3461
3469
3484
3490
3491
3492
3506
3511
3513
3524
3525
3534
3535
3491
3493
3509
3538
3540
3545
3544
3543
3552
3554
3559
3565
3567
3576
3580
3581
3589
3594
3607
3615
3618
3638
3657
3665
3664
3665
3658
3665
3667
3668
3682
3684
3687
3699
3712
3716
3720
3728
3744
3742
3740
3752
3763
3760
3757
3760
3762
3767
3758
3738
3739
3737
3738
3762
3767
3792
3820
3821
3822
3824
3825
3829
3821
3794
3800
3799
3801
3800
3820
3835
3836
3856
3859
3867
3871
3888
3889
3893
3898
3897
3894
3921
3917
3916
3917
3925
3922
3923
3930
3931
3932
3935
3936
3948
3947
3948
3961
3968
3998
3999
4000
4001
3994
3977
3979
3980
3976
3982
3988
3992
4000
4001
4007
4008
4004
4038
4025
4005
3986
3987
3989
3991
3983
3982
4004
4005
4012
4040
4060
4070
4064
4086
4096
4100
4109
4117
4125
4142
4148
4149
4154
4153
4161
4162
4155
4157
4159
4161
4186
4202
4201
4202
4201
4207
4209
4212
4214
4211
4212
4232
4233
4239
4250
4243
4242
4246
4247
4246
4245
4244
4251
4255
4259
4261
4262
4270
4252
4267
4271
4272
4275
4277
4276
4277
4261
4275
4278
4283
4304
4314
4316
4323
4325
4324
4331
4342
4348
4352
4353
4362
4389
4387
4362
4360
4373
4392
4393
4397
4399
4400
4405
4410
4405
4406
4414
4403
4410
4413
4417
4440
4441
4442
4443
4446
4459
4468
4467
4475
4474
4467
4473
4474
4473
4472
4480
4467
4468
4475
4477
4478
4479
4492
4493
4501
4504
4503
4510
4476
4482
4484
4485
4486
4497
4505
4512
4518
4519
4521
4524
4526
4533
4555
4558
4573
4575
4576
4564
4559
4562
4573
4572
4577
4580
4568
4569
4570
4576
4577
4578
4568
4575
4582
4589
4586
4599
4603
4587
4618
4600
4599
4598
4607
4596
4608
4610
4622
4626
4650
4664
4679
4675
4687
4685
4684
4685
4680
4706
4704
4693
4705
4712
4713
4712
4718
4728
4733
4735
4759
4758
4763
4764
4766
4767
4793
4794
4795
4796
4791
4780
4761
4768
4771
4777
4778
4789
4788
4789
4795
4802
4791
4789
4790
4789
4801
4809
4812
4806
4826
4835
4838
4840
4846
4853
4856
4858
4859
4864
4862
4865
4867
4868
4872
4875
4866
4859
4860
4857
4866
4872
4873
4872
4884
4887
4885
4895
4898
4902
4901
4902
4898
4887
4886
4901
4913
4914
4915
4918
4920
4918
4959
4958
4953
4982
4987
4972
4988
4999
4996
4997
5022
5040
5038
5037
5059
5062
5096
5097
5102
5127
5138
5176
5175
5179
5180
5181
5180
5213
5216
5215
5214
5219
5222
5225
5227
5249
5286
5287
5288
5302
5306
5307
5316
5326
5328
5327
5326
5327
5305
5309
5310
5305
5318
5319
5322
5323
5333
5355
5359
5369
5368
5359
5384
5387
5420
5442
5453
5455
5454
5446
5445
5448
5455
5474
5472
5478
5482
5483
5490
5523
5534
5535
5536
5535
5537
5538
5544
5547
5539
5540
5558
5559
5573
5574
5578
5576
5584
5610
5618
5609
5600
5602
5627
5637
5607
5603
5612
5608
5611
5622
5623
5625
5626
5628
5634
5646
5655
5658
5667
5678
5682
5685
5708
5712
5711
5718
5716
5719
5720
5722
5753
5757
5752
5753
5768
5774
5750
5730
5728
5733
5734
5729
5743
5744
5746
5748
5757
5771
5779
5759
5763
5783
5796
5797
5799
5815
5816
5817
5831
5838
5834
5840
5846
5852
5850
5858
5861
5864
5867
5870
5879
5903
5904
5930
5931
5936
5939
5941
5943
5936
5938
5943
5951
5962
5955
5950
5945
5946
5951
5950
5951
5950
5956
5957
5959
5975
5977
5992
5994
5997
5999
6011
6012
6013
6014
6013
6028
6032
6058
6064
6065
6078
6079
6080
6086
6089
6091
6077
6083
6051
6044
6058
6062
6069
6050
6048
6058
6086
6093
6094
6106
6107
6115
6114
6115
6112
6117
6131
6130
6132
6140
6164
6167
6163
6177
6180
6181
6183
6184
6186
6193
6196
6197
6200
6201
6198
6202
6203
6193
6211
6227
6222
6223
6222
6224
6207
6197
6198
6196
6204
6206
6207
6210
6209
6210
6209
6229
6232
6233
6235
6237
6232
6254
6268
6275
6290
6292
6300
6301
6295
6297
6298
6301
6308
6317
6318
6326
6319
6320
6319
6321
6329
6332
6331
6342
6348
6369
6370
6390
6420
6423
6436
6437
6452
6444
6445
6456
6457
6444
6448
6457
6489
6491
6502
6507
6510
6495
6497
6505
6507
6511
6513
6516
6520
6523
6532
6534
6535
6548
6561
6560
6566
6567
6586
6589
6592
6598
6602
6603
6621
6630
6632
6634
6660
6661
6662
6642
6657
6659
6655
6658
6661
6662
6663
6672
6661
6664
6665
6678
6682
6683
6669
6663
6658
6663
6680
6685
6686
6687
6693
6687
6680
6686
6694
6676
6675
6695
6698
6716
6717
6720
6728
6734
6735
6733
6743
6745
6758
6757
6763
6762
6761
6790
6793
6798
6799
6807
6808
6822
6828
6795
6793
6795
6790
6791
6794
6799
6808
6815
6827
6856
6857
6882
6883
6885
6886
6903
6902
6903
6904
6892
6893
6912
6893
6888
6887
6891
6892
6891
6898
6899
6900
6901
6900
6901
6913
6914
6918
6932
6944
6945
6960
6963
6961
6966
6968
6974
6979
6980
6981
6982
7003
7023
7034
7035
7068
7087
7088
7089
7098
7104
7093
7095
7102
7129
7120
7123
7153
7155
7157
7158
7157
7151
7167
7190
7208
7197
7200
7201
7224
7223
7217
7224
7225
7227
7228
7233
7234
7265
7266
7267
7286
7296
7297
7299
7295
7296
7297
7283
7259
7255
7259
7260
7267
7275
7273
7274
7277
7276
7289
7291
7297
7298
7299
7298
7300
7307
7308
7312
7332
7341
7342
7335
7348
7349
7345
7344
7345
7358
7357
7359
7397
7398
7401
7406
7425
7424
7429
7430
7433
7435
7436
7437
7430
7429
7439
7440
7454
7456
7438
7439
7421
7439
7438
7441
7421
7422
7424
7440

Day 02: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

main.ts
import { Dive } from "./dive";

console.log('day 2');

// Dive solution by Christoph Jobmann
const d = new Dive();

console.log();
console.log('Part 1:');
d.RunSilver();

console.log();
console.log('Part 2:');
d.RunGold();
dive.ts
// --- Day 2: Dive! ---
import * as fs from 'fs';

export class Dive {

    private lines: string[];
    private position = 0;
    private depth = 0;
    private aim = 0;

    constructor() {
        this.lines = this.Read();
    }

    /** Does the dive for the first part. */
    public RunSilver() : void {
        this.DoDive((c, n) => this.silverNavigation(c, n));
    }

    /** Does the dive for the second part. */
    public RunGold() : void {
        this.DoDive((c, n) => this.goldNavigation(c, n));
    }

    private DoDive(step: (c: string, a: number) => void) : void{
        this.position = 0;
        this.depth = 0;
        this.aim = 0;

        for (const line of this.lines) {
            // Recover command and amount an apply them to the step function.
            const tokens: string[] = line.split(' ');
            const amount = parseInt(tokens[1]);
            step(tokens[0], amount);
        }

        console.log('position: ' + this.position);
        console.log('depth: ' + this.depth);
        console.log('product: ' + this.position * this.depth);
    }

    private silverNavigation (command: string, amount: number) {
        switch (command) {
            case 'up':
                this.depth -= amount;
                break;
            case 'down':
                this.depth += amount;
                break;
            case 'forward':
                this.position += amount;
                break;
            default:
                console.warn(`token ${command} unexpected.`);
        };
    }

    private goldNavigation (command: string, amount: number) {
        switch (command) {
            case 'up':
                this.aim -= amount;
                break;
            case 'down':
                this.aim += amount;
                break;
            case 'forward':
                this.position += amount;
                this.depth += amount * this.aim;
                break;
            default:
                console.warn(`token ${command} unexpected.`);
        };
    }

    private Read() : string[] {
        let input: string;

        const prefix = 'day02/typescript/aspik79/';
        const path1 = prefix + 'input.txt';

        if (fs.existsSync(path1)) {
            input = fs.readFileSync(path1,'utf8');
        }
        else {
            input = fs.readFileSync('input.txt','utf8');
        }

        return input.split('\r\n')
    }
}
input.txt
forward 2
forward 6
forward 8
forward 7
down 5
forward 8
forward 9
down 2
forward 6
down 9
forward 1
forward 8
forward 6
forward 7
down 4
down 5
forward 1
up 5
down 7
down 7
down 1
up 2
forward 3
forward 2
forward 2
forward 5
up 5
forward 4
forward 9
forward 6
down 4
down 9
down 2
up 6
forward 9
up 7
forward 7
forward 5
up 3
forward 4
forward 9
up 5
down 3
up 6
down 5
down 4
up 6
forward 9
forward 6
down 9
up 3
down 7
up 1
forward 8
forward 3
forward 8
up 6
forward 7
forward 5
forward 8
up 2
forward 2
forward 7
forward 7
down 1
forward 7
up 7
down 3
forward 9
down 5
down 2
forward 5
forward 1
forward 4
forward 6
up 2
up 7
forward 2
forward 6
forward 7
down 9
up 8
down 9
down 3
up 8
down 3
down 2
up 6
forward 3
forward 9
down 4
forward 5
down 6
up 8
forward 1
down 6
down 6
forward 5
down 6
forward 8
up 7
down 3
forward 7
forward 3
forward 1
forward 4
forward 4
down 3
up 9
up 5
forward 1
down 2
up 4
forward 7
up 4
down 3
down 5
down 8
forward 4
up 8
forward 7
up 3
up 4
up 9
forward 1
forward 1
down 6
forward 1
down 8
up 4
forward 9
forward 9
down 6
forward 9
forward 8
down 2
up 3
up 3
down 9
forward 7
forward 8
down 4
forward 1
up 3
forward 3
down 3
down 9
down 5
up 7
up 2
forward 7
forward 2
forward 5
forward 4
down 7
forward 7
up 1
up 3
down 6
down 4
forward 9
forward 8
down 5
down 4
down 1
down 5
forward 9
forward 8
down 3
forward 5
forward 3
forward 6
down 6
forward 3
up 9
forward 4
down 7
forward 3
forward 7
forward 1
forward 5
down 1
forward 1
down 6
up 7
down 3
forward 2
down 4
forward 6
up 6
forward 8
forward 8
down 5
up 4
forward 7
forward 6
up 4
forward 6
down 1
forward 6
forward 2
up 4
down 6
down 7
forward 4
down 4
forward 1
down 3
forward 5
forward 5
forward 9
forward 3
up 7
down 7
forward 7
forward 5
down 1
down 1
forward 3
down 8
forward 1
forward 2
forward 9
forward 1
forward 3
down 3
up 4
forward 5
down 1
forward 3
up 7
forward 3
forward 6
up 6
up 3
forward 9
forward 5
down 2
up 4
up 3
forward 3
forward 7
down 1
forward 5
forward 5
down 1
forward 4
forward 2
down 1
down 9
down 7
up 1
forward 2
down 2
forward 3
forward 8
forward 4
forward 6
down 4
down 1
forward 5
forward 1
forward 7
down 8
forward 9
down 6
forward 3
up 5
up 1
up 7
down 5
forward 7
forward 5
forward 5
up 1
forward 8
down 8
down 7
forward 9
forward 9
down 3
forward 7
forward 2
down 1
down 6
down 1
forward 7
down 3
forward 1
forward 1
forward 6
forward 6
up 9
down 3
forward 9
down 8
forward 4
up 6
down 4
down 7
forward 5
up 3
forward 1
forward 8
up 6
up 3
down 2
forward 2
forward 5
forward 1
down 8
down 8
down 3
forward 5
forward 4
forward 4
forward 5
up 5
forward 2
forward 5
up 5
forward 6
forward 6
forward 9
up 5
forward 4
up 4
forward 8
down 8
forward 5
forward 2
forward 4
forward 3
forward 1
down 1
down 9
down 2
forward 4
down 3
down 6
forward 2
up 7
forward 6
down 4
up 9
down 1
forward 8
forward 1
forward 1
down 9
down 3
down 2
down 7
up 5
down 7
up 9
down 8
down 7
forward 9
forward 7
up 4
forward 5
up 9
down 4
forward 1
forward 9
down 7
up 9
forward 6
forward 4
up 8
down 2
forward 1
up 6
up 5
down 4
forward 8
down 3
down 5
down 6
up 1
up 9
up 7
up 5
forward 1
forward 3
down 7
forward 9
forward 2
forward 6
down 4
down 7
forward 3
down 1
up 5
forward 3
down 3
down 1
forward 1
forward 4
forward 8
down 4
down 1
forward 3
down 7
up 9
down 8
down 1
forward 2
down 6
down 9
down 9
forward 2
forward 8
up 2
down 5
down 9
forward 1
up 9
down 7
forward 8
down 7
up 4
forward 8
down 8
down 7
forward 6
up 7
down 4
down 9
forward 9
up 8
down 8
down 8
down 8
down 5
forward 2
up 9
down 2
up 7
down 7
down 3
down 6
forward 9
forward 1
down 1
down 5
up 4
down 5
forward 5
up 2
forward 5
down 5
forward 1
forward 9
down 9
forward 3
forward 3
down 8
down 2
down 8
forward 8
forward 7
up 6
down 4
down 5
forward 8
forward 4
forward 7
forward 1
down 9
down 4
down 2
forward 5
down 3
down 7
down 5
forward 8
up 1
down 4
down 7
down 7
forward 2
up 5
forward 5
up 2
up 4
down 9
forward 7
forward 6
forward 6
down 2
forward 7
forward 7
down 7
forward 8
down 2
up 9
down 1
forward 9
down 9
forward 3
down 9
down 2
forward 9
forward 8
down 7
up 2
forward 8
forward 1
up 2
down 7
up 7
down 8
up 1
up 4
up 2
up 3
down 7
forward 1
down 8
down 4
down 2
down 4
up 8
forward 8
down 2
up 5
up 4
forward 7
up 1
forward 3
down 8
down 4
forward 4
down 8
forward 2
down 1
up 9
forward 9
down 4
up 2
down 8
up 9
forward 6
down 7
up 7
forward 9
forward 1
down 8
forward 5
down 9
forward 6
down 9
forward 9
forward 1
down 8
up 4
forward 9
forward 3
down 9
up 8
forward 4
up 8
forward 7
down 7
up 6
down 7
down 2
down 7
forward 3
forward 2
down 6
down 2
down 7
up 4
forward 5
down 5
forward 2
up 3
up 8
forward 8
forward 1
forward 7
down 7
down 2
forward 1
down 7
down 7
up 2
up 7
up 7
forward 4
down 5
forward 5
forward 7
forward 7
down 7
down 8
forward 8
forward 8
up 3
up 9
forward 2
down 7
up 3
up 1
up 1
down 9
up 5
down 6
up 8
up 3
up 5
forward 7
forward 3
forward 8
forward 4
up 1
forward 2
forward 1
up 5
forward 9
forward 8
down 7
up 1
forward 7
down 8
forward 1
forward 9
forward 9
forward 9
forward 8
down 1
forward 8
forward 7
up 9
up 3
forward 8
forward 2
up 2
down 7
down 6
forward 4
forward 3
forward 6
up 7
down 9
forward 1
forward 4
down 1
forward 4
up 3
down 8
forward 1
up 6
forward 8
forward 2
forward 1
forward 8
forward 4
down 7
forward 4
forward 6
down 2
up 4
forward 4
forward 3
down 5
forward 8
forward 4
forward 5
forward 7
forward 6
forward 5
forward 9
down 4
down 9
forward 6
up 7
down 6
down 3
down 2
up 9
forward 7
down 4
down 5
forward 2
forward 3
forward 2
forward 9
forward 7
forward 8
down 9
down 7
down 9
down 7
forward 5
forward 2
down 5
forward 6
down 1
down 2
down 6
forward 9
down 3
up 6
down 4
down 5
forward 3
forward 7
down 8
forward 2
forward 5
down 9
down 3
up 5
down 6
forward 6
up 3
down 6
down 1
down 8
down 5
down 3
forward 3
up 6
up 7
forward 8
forward 9
forward 2
forward 6
forward 2
forward 3
down 7
down 3
down 3
down 6
down 2
forward 4
forward 3
forward 8
up 1
down 9
forward 5
up 3
down 7
down 6
forward 8
forward 1
up 6
forward 3
forward 1
up 9
forward 6
forward 3
down 9
down 4
down 9
forward 5
down 8
down 3
forward 1
forward 1
down 9
down 6
down 3
up 7
down 3
forward 5
down 2
forward 7
forward 2
forward 5
up 7
forward 4
forward 4
up 3
down 6
down 7
up 1
down 6
forward 1
forward 9
down 7
down 8
forward 5
down 1
down 9
up 5
up 4
up 3
forward 6
down 6
forward 4
forward 8
up 6
up 2
down 9
forward 2
forward 5
forward 1
forward 3
forward 9
up 3
forward 2
forward 1
forward 3
forward 3
up 9
forward 3
forward 7
down 6
forward 2
down 8
up 9
forward 8
forward 5
forward 2
up 8
down 9
up 5
forward 3
down 4
forward 1
up 9
down 4
down 5
up 4
down 6
down 4
down 6
down 4
forward 4
down 2
down 1
down 6
forward 2
down 1
down 3
forward 4
down 3
down 5
down 5
up 1
up 4
down 4
down 4
down 5
down 4
down 5
forward 5
down 8
down 5
down 5
down 9
up 1
up 5
forward 5
down 1
down 9
down 4
down 3
forward 3
down 2
forward 9
down 3
forward 1
down 9
down 5
up 7
forward 3
forward 1
forward 2
down 5
forward 8
down 3
down 3
forward 6
down 8
down 3
down 8
up 9
forward 3
down 6
forward 4
down 6
down 4
up 5
forward 1
up 6
up 2
forward 2
down 8
forward 7
forward 8
down 6
down 7
forward 7
up 3
forward 3
up 6
forward 3
down 1
down 7
forward 9
forward 5
up 1
forward 7
forward 1
down 3
forward 1
up 4
up 2
up 1
down 8
forward 9
forward 3
forward 4
up 7
forward 5
down 1
down 8
down 3
down 4
down 6
down 5
forward 4
down 4
down 2
down 4
down 3
down 3
forward 4
up 3
forward 6
down 7
forward 4
up 2
down 7
forward 8
up 9
forward 6
forward 8
down 1
down 6
forward 6
down 6
down 9
up 8
forward 8
up 5
forward 6
forward 9
forward 4
up 2
forward 3
down 7
down 8
down 4
up 8
forward 8
forward 1
up 5
up 4
up 1
down 9
down 9
up 2
forward 9
down 7
down 2
up 2
down 1
forward 6
forward 2
down 5
down 8
forward 6
down 2
down 3
forward 6
forward 7
up 8
down 4
forward 5
down 9
down 2
down 7
down 9
down 5
forward 9
forward 2
down 6
forward 7
up 6
forward 3
up 2
forward 9
forward 2

Day 03: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

read.ts
import * as fs from 'fs';

export function readLines(file: string, path: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split('\r\n')
}
main.ts
import { BinaryDiagnostic } from "./binaryDiagnostic";

console.log('day 3');

// Binary Diagnostic solution by Christoph Jobmann
var bd = new BinaryDiagnostic();
console.log(bd.EvaluatePowerConsumption());
console.log(bd.EvaluateLifeSupport());
binaryDiagnostic.ts
import * as r from './read';

export class BinaryDiagnostic {
    private lines: string[];

    constructor() {
        this.lines = r.readLines('input.txt', 'day03/typescript/aspik79');
    }

    /**
     * Part 1: evaluate the power consumption.
     * @returns the power consumption.
     */
    public EvaluatePowerConsumption() : number {
        let gamma = 0;
        let epsilon = 0;

        const bitCount = this.lines[0].length;

        for (let index = 0; index < bitCount; ++index) {

            const bits = this.lines.map(l => l[index]);

            // Count ones and zeros at current index.
            const zeros = bits.filter(b => b == '0').length;
            const ones = bits.filter(b => b == '1').length;

            const mostCommon = this.mostCommonBit(bits);

            // shift the decimal numbers before inspecting the next bit.
            gamma <<= 1;
            epsilon <<= 1;

            if (mostCommon == '1') {
                gamma += 1;
            }
            else if (mostCommon == '0'){
                epsilon += 1;
            }
            else {
                console.log(`equal count of ones and zeroes at index ${index} unexpected.`);
            }
        }

        return gamma * epsilon;
    }

    /**
     * Part 2: evaluate the life support value.
     * @returns the life support value.
     */
     public EvaluateLifeSupport() : number {
        let o2 = this.EvaluateOxygenGenerator(this.lines, 0);
        let co2 = this.EvaluateCo2Scrubber(this.lines, 0);

        console.log(o2);
        console.log(co2);

        const o2value = binaryToInt(o2.join(''));
        const co2value = binaryToInt(co2.join(''));

        console.log(o2value);
        console.log(co2value);

        return o2value * co2value;
    }

    /**
     * Recursively reduce the input according to additional input extracted based on the given index.
     * @param lines input lines.
     * @param index index that defines the current filter.
     * @returns filtered lines.
     */
    private EvaluateOxygenGenerator(lines: string[], index: number) : string[] {
        const bit = this.mostCommonBit(lines.map(l => l[index]));

        let result = lines.filter(l => l[index] == bit);
        if (result.length > 1) {
            //console.log('o2: ' + result.length + ' lines remaining.')
            result = this.EvaluateOxygenGenerator(result, ++index);
        }

        return result;
    }

    /**
     * Recursively reduce the input according to additional input extracted based on the given index.
     * @param lines input lines.
     * @param index index that defines the current filter.
     * @returns filtered lines.
     */
     private EvaluateCo2Scrubber(lines: string[], index: number) : string[] {
        const bit = this.LeastCommonBit(lines.map(l => l[index]));

        let result = lines.filter(l => l[index] == bit);
        if (result.length > 1) {
            //console.log('co2: ' + result.length + ' lines remaining.')
            result = this.EvaluateCo2Scrubber(result, ++index);
        }

        return result;
    }

    private LeastCommonBit(bits: string[]) : string {
        const zeros = bits.filter(b => b == '0').length;
        const ones = bits.filter(b => b == '1').length;

        return ones >= zeros ? '0' : '1';
    }

    private mostCommonBit(bits: string[]) : string {
        const zeros = bits.filter(b => b == '0').length;
        const ones = bits.filter(b => b == '1').length;

        return ones >= zeros ? '1' : '0';
    }
}

function binaryToInt(bits: string) : number {
    let result = 0;
    for (const b of bits) {
        result <<= 1;
        result += b == '1' ? 1 : 0;
    }

    return result;
}
input.txt
111111010011
110011001100
010011111000
101001100011
011011100110
110100011011
001000001010
011011101000
110011001000
001011101010
100000001000
001000000111
111110110101
101000100110
110101110001
101101010111
000010001001
101110010100
101000101011
010110100011
110010011001
110110011111
100111000001
100101010011
101011011001
111101110010
000111000001
000000000111
011010111101
101010100011
010001001011
100011010100
100000011110
000010110100
101001110100
000110110000
101100101000
111001100111
110100001110
001111000110
101111101110
011101111100
000010001111
010100101001
111101000001
110010111111
111011001111
001101011101
101001111001
111100000010
111101101111
001011000100
100010001011
111111001110
010010111011
000110010001
001011100001
011010101011
101011000010
100111010000
100110010101
010000100010
101101100011
100110000001
001011011010
101100111110
011101101111
110000011010
101111000100
100011000011
001110000101
011110110010
111110010001
010000111110
001101100001
001010101111
010011011000
101000101101
000110111100
000000100001
110000101000
000000001001
100001111111
100111111011
010011110010
110100101110
100101110001
000111011000
101101111000
000110001001
110001101110
111011001110
011001111010
011100000110
111000000111
100100011100
001001111100
011101001101
000111110000
001000110100
111001000110
110010001101
011011010101
011110011011
010110001100
111000001010
101101000001
101000011111
010110011011
000001101010
001100001001
000111111100
011000101001
011000101110
001001100011
111111111101
011010100010
010011010101
110010101100
100111101010
101110000111
100101010000
001001110010
100001100110
111001011000
100111010111
100111111110
110101010110
110000001110
001000110111
111101000110
110111101010
000100001101
011000011110
010110000000
111001111100
111111000001
111101001111
100001011011
000000110011
000010011111
100110001111
010001011011
111010100011
011001111100
110100001100
010000000101
101011001000
000011001111
111101111100
101111001011
011110011110
110101111001
010111000100
101100100100
010111100111
101111011010
110110110101
000110111010
010111010011
110000111010
011101001010
111011101111
010010000010
101111110001
110001101101
111101001010
010010110111
101110110011
101001100101
100000000001
000100000001
011001101110
010010111110
010000011111
101010101010
101001010111
010000001000
110001001011
100001110111
011111110010
100000100001
101101100101
100011110101
000100111110
001101010001
100010111101
010111100000
100001010001
000100111111
011100011000
010001100111
011000011011
011100000001
100101100110
110101010100
000000001101
001111100000
011111000010
101011010101
110011011000
000000111111
001100101001
010100110111
100000010010
101100010000
111111111010
100110000000
011111001100
011101001001
010011100101
010110010011
010011000000
111100011011
001001010010
010011001111
010100000101
111100110101
011011110011
011000110100
101111110000
011001000001
000111100000
110011111001
111010000001
001100011010
101010010110
100010111000
111111010000
010100111110
000001010100
001011101011
010000111010
110010100100
001101110100
001010001000
110110101010
110100101111
010010101100
011011111101
010011001100
011010011111
100110010100
010010011100
100010010101
010100111011
101101010100
001111111001
101101111110
000100101000
000100001110
101111001000
100101110011
111011111010
011010100101
100011000101
111100100110
011101111101
100111101001
010101110111
110100100111
001111100010
010111100011
101111011111
101111111101
101000001011
000011010111
000101001000
101111101111
100011101010
011111100110
000101010110
000000001010
000010110001
011101010101
011111010010
010001110000
101101000101
110100010110
100010100101
110010111101
010101111110
010111011010
111110011001
110010000110
100100111000
100011100101
001101011010
111000110000
111110010100
111000111000
101101000010
000111101110
110101011101
010100010001
011100001101
011101000000
100001011010
101001010010
110111011101
100000010110
010100110010
010000111011
101111111000
111000111101
001011110010
101001000001
011100110101
101101011111
111001101111
001110100010
001000011000
100000000011
011011100111
000101010001
100001110010
000111101000
111101101101
011101011001
110100010111
011101100010
101100110010
001101010011
010110010110
101001010100
011011000001
110001111001
111010011101
101001111000
110011011111
100110110110
001111011011
111100111110
010100000001
101111010101
011110100110
101100111101
010101100011
000011000011
011001001000
110000001100
101100000111
000000011110
100110000010
111001111010
000111001100
111011111100
100111001111
110010100001
100010001111
000010000110
111000101000
101011110001
101011011110
110111111110
010100101111
011100110000
011001101001
110101111100
001101110011
110110001101
011110111100
010011101000
011101101011
001010001111
000001001011
001101110001
000011001011
110100110110
110000111011
100001111110
010101010000
011000000101
110101001111
111001010000
000110110011
110001001110
110100111110
001010010101
001111011101
101000010001
101110100000
010110111111
111001001011
010011000101
010101010011
010010100110
000101000101
111011100001
100110110111
110111011000
111011110010
000100011110
110000111100
000000101100
101011010100
010100100100
011111101111
101001100100
001000011010
011000001100
111110100100
100101110111
011110110100
001011011000
111101011101
010111011101
100000100010
011100111111
111010100110
001011101110
000110111000
001011110000
101000110111
001101001111
000100001000
100000110110
000101100001
111010111101
010111001000
011110001101
001010011101
001010111100
010110111101
111110001111
011011010000
111011111001
111011010011
010111010010
000101110111
011000010000
010000100111
001111110000
011001101010
001110001111
101010000101
011011001100
110101000000
011000111011
010110001110
101101001001
111100001101
101011000000
110010000100
011000111110
100111100011
101010100001
100011101110
000100110010
100011111001
101100100110
101101011101
100111000110
111111100100
101001111111
010011111111
010111000000
101110001111
011000110000
100110110100
101010000110
101011000110
110001110100
110100111101
100110101101
001001101101
000001011001
010011001110
011010010010
011011011011
010100000010
100111001010
110101011111
001000101111
110100100001
101010111001
010111011100
010111011000
111000101110
111101000111
111000110001
000000111110
011101110001
011100100011
100110001100
001101000101
111000110101
011000101000
010110110100
101111101010
101001011111
101000111111
101001110110
100001010100
111111101101
110010111011
100111000111
000001111100
011010101000
100101101111
000110011111
101010011010
010000101101
001111001111
100100110111
001101000000
000110101010
011110001011
110001100111
000001101101
111001001111
000100010111
100001000110
000010110010
000100001010
001010100111
101000010110
011011011001
010011010001
100100011000
001111110110
110111100111
101110110100
101100001111
011001010001
001110110010
001000111011
110011000000
001101010111
110101100000
100011111010
110101000010
001100010001
001100110100
000100000111
001010111101
101001101000
010010000111
000100000010
001100000100
101000100010
010010100101
000110111111
001100100001
110001101010
001010110001
110111110000
100011100001
101000010000
101001000100
101101011110
010000110100
110100110010
110000010001
111110101010
110010101011
110101110110
111101101000
101010100111
101101101111
101010110101
001101010100
001101101100
010111001011
100000011011
111101001101
001110010111
010000110111
010000110110
111100110111
011100111010
010100011101
000011011101
111111110001
110000111000
110000110000
010011110011
011101000101
011011001011
111000011100
011111111100
100011001111
000101111110
001001110111
100111011011
011110110111
100100010011
010100110101
010001101000
011000001111
110011110001
110011000101
110011100100
011001001111
010100000110
011110010010
110101010101
000011011001
101011110011
101110011001
001111000100
110110111011
010101001011
011100100100
110010000010
000010000111
000101100100
001100100110
011011101010
111000010101
010000000100
111001110110
110000110111
111001001100
100011111011
010001001111
101100110000
010011011100
000001000101
011010011010
000010111001
110000101101
111010011000
110111011100
011100001110
011010001111
111110010011
111011010100
101101001011
010100001011
100011101100
010011101101
000101010000
110011011001
100100010111
111111010110
101011111011
010001110101
010001010010
100111100010
100000110000
011011000110
000110000100
100011110110
010111000011
100010100111
010010000001
111011001011
000100010110
101101011011
100101010001
111001111110
000111100010
010111011111
000110010100
110100000100
001000100101
001000100001
111100001010
001101010010
100101100011
101011001100
001110000010
011011010110
001001011111
111011100100
110100111000
000101100101
001001110100
000011000110
001110101101
110100111011
101011101110
110001001001
001000001100
101111111100
110011000010
001111001011
101100101110
110010111110
011101110000
101110010111
001011000111
011110010011
110111001100
111011110111
110111110011
010111100110
110011000111
101011011010
011100000101
101001111101
010001000001
011100100001
010110101010
001111101100
010000000110
010010010111
000110110101
101110110101
111010000000
101100011010
010010100000
001001000110
000010101110
100100110000
110101100001
100010011111
010110111110
000101100111
111010000010
110011010011
110011101001
101000100011
010101000101
111100111001
010011101010
001111101110
011000110010
001001000001
100011111111
101110100011
001011101001
010001011000
011111101100
110101010000
110110101100
111101110000
000001011010
100111001011
011101000110
010001000000
111001000100
000010100001
011000101010
010011010111
010100100011
001110011011
001101110000
101100000010
101111000000
100001111101
000000011101
111011010010
001110101111
010100001110
110001110010
001000011110
111100000011
111010100101
000101011010
100111110111
010100000100
011101001011
000010011100
001000010010
110100000001
011101100100
000100110001
001000000000
101111110011
000111010101
011110100011
110000001101
000001001100
111101110111
001100001111
101010001101
010011000111
100000000100
100100011001
100011100011
111110100011
111101100110
000000101001
101010100100
000100010000
010110001000
010110010000
100011000100
111011011001
100111111001
000011101111
101011001011
111110100010
000000010101
100111000000
000110010101
100101011111
010110011110
110110110011
100111011100
010000100101
011010101010
110111000111
110110000000
110111101101
001001101001
100101101000
001011100111
100010110100
011001111000
111110000000
010011101011
100010111010
101011101001
010110000110
001100010111
100010000110
100011001000
101111011110
110101101110
001110101001
010111111110
010011110111
100101001101
010111001101
001000110010
011110001110
111001110011
111001001101
000101110101
011011100010
001100011011
000011110001
111101111011
111101100010
111010001001
101001101101
100101011000
010011000010
110011000100
111100001001
010001110111
001011110110
110010011011
101000000111
100001110000
110111110010
000111011110
101010101101
110001000101
100100001101
111101100100
010000001001
011101001100
111010100001
101010010010
110111010111
000111011100
101101111010
110000010111
100100100000
101111011000
111011101100
110101101010
110111101011
001110100001
100110110011
011011011101
011001011000
101100011001
100000011100
111100010101
011100010111
010001111011
000000101110
000011011100
011100010000
011000001011
111110101110
111011010110
110110000011
011011010010
011111101101
001011001101
000101011100
111010001101
100001010111
010010100100
001011111000
000011010101
010100001001
101100101100
000000100010
001100110000
001010010111
101100110101
000001011000
001100110110
101000111100
111011111111
011010010000
100100111010
010000101001
110000110010
011010001011
001000001000
111010100000
101010101011
101000110100
100110000011
001100011110
001010100100
111111101001
101100001001
111111011110
000110001100
100101000100
000111101001
011000000110
101110001000
000110001000
001000100100
100100010110
010101110011
011101111000
111110010010
110110100010
010001001110
101011101100
101011011100
110001111011
110100010001
001100110001
001010111001
110011111000
110010101010
001010001100
101010001100
010100010100
111101100000
100100000101
100011011110
000111111011
010001101010
111001101011
001011001010
000101100000
010101011001
011110010101
010000110000
100101101001
110111110001
000100011111
010001101101
111010110101
011010011000
110011100000
101111100000
001011011101
010110000010
101000001110
101010000111
101000101110
101111001101
110110001111
100001011110
010111110100
110011000001
000111000100
010011100111
101011011101
111100001110
101000110010
100111111000
110101101001
001010010001
101110011110
100001001010
100111001100
110111101110
100011000001
111111010101
011111111101
100110111101
000111001110
000111011011
000001001010
000011010100
001100001011
100111010110
101011000111
011111100111
000001000100
100000101110
110110100111
111100000000
001100001101
011111100101
101110001100
000111000110
101010111011
101111001010
100110010011
000110101111
001010000010
100010000100
110001000110
101100100111

Day 04: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
bingoCard.ts
export class BingoCard {
    private numbers: number[];
    private columns: number;
    private rows: number;
    private columnsMatched: number[];
    private rowsMatched: number[];

    /**
     * Creates a new bingo card.
     * @param block Block of numbers describing the bingo card's content.
     */
    constructor(private block: string) {
        const lines = block.split('\r\n');

        // Parse the numbers. Careful with duplicate space separation.
        const flat = lines.flatMap(l => l.split(' '));
        this.numbers = flat.map(s => parseInt(s)).filter(n => n >= 0);

        this.rows = lines.length;
        this.columns = this.numbers.length / this.rows;

        // Initialize match counts; no matches yet.
        this.rowsMatched = Array<number>(this.rows).fill(0);
        this.columnsMatched = Array<number>(this.columns).fill(0);
    }

    /**
     * Marks the given number on the bingo card if it exists. Also contains a win-check.
     * @param n number that is to be marked.
     * @returns true if there is a bingo match, otherwise false.
     */
    public markNumber(n: number) : boolean {
        let result = false;

        const index = this.numbers.indexOf(n);
        if (index >= 0) {
            // There is a match! Calculate row and column.
            const col = index % this.columns;
            const row = Math.floor(index / this.columns);

            // Take the number off the list.
            this.numbers[index] = NaN;

            // Update match counts and check for win.
            result ||= ++this.columnsMatched[row] == this.columns;
            result ||= ++this.rowsMatched[col] == this.rows;
        }

        return result;
    }

    /**
     * Calculates the sum of the remaining numbers.
     * @returns Sum of remaining numbers.
     */
    public sumOfRemaining() : number {
        return this.numbers.filter(n => n).reduce((sum, current) => sum + current, 0);
    }
}
main.ts
// Day 04: Giant Squid by Christoph Jobmann

import { BingoGame } from "./bingoGame";

const game = new BingoGame();
let score = game.selectFirstWinningCardScore();
console.log(score);

score = game.selectLastWinningCardScore();
console.log(score);
bingoGame.ts
import * as r from './read';

import { BingoCard } from "./bingoCard";

export class BingoGame {
    private blocks: string[];
    private draws: number[] = [];
    private cards: BingoCard[] = [];

    constructor() {
        this.blocks = r.readBlocks('input.txt', 'day04/typescript/aspik79', '\r\n\r\n');
    }

    /**
     * Simulate a bingo game with all cards and find the first winner.
     * @returns First winner card's score.
     */
    public selectFirstWinningCardScore() : number {
        this.initializeGame();
        for (let n of this.draws) {
            for (let c of this.cards) {
                if (c.markNumber(n)) {
                    // We have the first winner.
                    const cardScore = c.sumOfRemaining();
                    return n * cardScore;
                }
            }
        }

        return -1;
    }

    /**
     * Simulate a bingo game with all cards and find the last winner.
     * @returns Last winner card's score.
     */
     public selectLastWinningCardScore() : number {
        this.initializeGame();

        let lastScore = 0;

        // Keep track of cards that already won.
        let winners: BingoCard[] = [];

        for (let n of this.draws) {
            for (let c of this.cards) {
                if (winners.findIndex(x => c == x) < 0 && c.markNumber(n)) {
                    // We have a new winner.
                    lastScore = c.sumOfRemaining() * n;
                    winners = winners.concat(c);
                }
            }
        }

        return lastScore;
    }

    private initializeGame() {
        this.draws = this.blocks[0].split(',').map(s => parseInt(s));

        const cardTexts = this.blocks.slice(1);
        this.cards = cardTexts.map(card => new BingoCard(card));
    }
}
input.txt
4,77,78,12,91,82,48,59,28,26,34,10,71,89,54,63,66,75,15,22,39,55,83,47,81,74,2,46,25,98,29,21,85,96,3,16,60,31,99,86,52,17,69,27,73,49,95,35,9,53,64,88,37,72,92,70,5,65,79,61,38,14,7,44,43,8,42,45,23,41,57,80,51,90,84,11,93,40,50,33,56,67,68,32,6,94,97,13,87,30,18,76,36,24,19,20,1,0,58,62

34 90 18 33 83
27  7 25 61 15
43  5 51 32 45
24 17 72 31 22
77 46 78 16  9

72 95 37 52 68
80  1 73 96 63
16 49  9 42 97
25 81 20 11 46
31 24  2 34 18

88 29 95 98 57
49 36  6 23 83
18  5 45 40 44
62 81 74 99 87
46 56 35 21 52

34 51 57 55 58
 3 30 35 92 69
56 53 86 40  4
46 71 43 29 18
 6 15  9 60 83

49 11 72 87 56
40 94 71 70  3
65  2 90 64 63
32 79 24 44 55
58 53 35 77 60

78 77 89 45 67
32 35 18  1 60
61 25 71 56  2
44 27 73 82 79
40 53 84 23 16

 9 70 11 95 14
77 54 55 10 97
88 89 41  8 43
87 37 20 67 86
74 24 30 75 25

30 36 41 93 66
27 23  7 40 92
73 29  1  2 45
68 95  0 14 59
78 70 54 64 25

35 75 54 52 86
32 60 72  6 79
45 26 77 83 41
74 29 58 19 18
49 63 31 61 88

 0 70 66  5 92
85 55 65 19 24
69 73  3 38 79
58 94 84 22 16
68 91 59 28 88

45 59 73  3 82
 7 79 55 62 49
89 32 99 69 19
10 26 63 36 27
28 83 43 64  4

53 28 61 95 63
39 78 38 50 26
46 91 70  6 98
97 87 27  8 25
 3 36 48 24  7

93 55 34 14 16
88 92 19 86 53
37 79 25 21 67
22 13 10 97  7
44  8 94 39 64

41  8 70 13 23
16 33 55 89 12
94 98 28 91 38
 3 32 82 71 90
92 15 76 86 80

34 99 57 29 48
89 18 67 90 96
12 95 93 41  9
25 78 97 59 65
87 38 91 61 17

31 96 70 24 11
64 54 52 47  7
86 27  1 85 44
77 99 81 97 90
21 82  6 83 41

98 59 95 45 34
51 66 49 35 47
83 13 28 94 32
10 31 96 22 70
62 48 42 44 16

61 44 52 12  7
 5 24 58 53 51
95 79 83 11 36
 1 25 94 55 27
89 59 88 39 70

30 81 65 77 82
50 53  6 89 85
12 33  1 72 11
48 29 23 60 20
67 27 95 61 28

44  6 72 94 32
61 81  1 23 78
67 22 15 24 12
98  9 71 17  8
25 50 93 92 56

89 63  3 53 90
65 66 52 62 92
55 59 42 71 49
67  6 22 25 46
10 94 84  1 77

16 34 96 63 56
77 32 84 90 49
52 44  9 95 94
 3  1 83 39 24
11 75 17 61 42

12  3  9 55 46
20 68 26 34  4
42 49 31 28 87
51 86  0 15 44
21 97 98 50 95

21 92 59 50 46
93 60 95 75 44
17  1 15 38 25
96 49 28 76 83
18 71 48 63 41

57 29 72 50 46
95 93 92 35 74
39 73 48 60 89
80 70 55 76 43
86 14 75  5 81

78 54 48 69 13
29 88 23 33 67
28 16 59 40 14
79 11 94 68  8
58 50 72 91 92

80 63  8 58 71
45 83 52 98 36
23  7 56 47  0
99  1 94 76 54
24 82 92 97 50

95 35 62  5 43
12 69 85 90 17
98 20 71  1 34
13 48 87 78 29
51 82 28 26 24

84 29 33 85 54
 8 49 10 24 35
67 15 37 34 32
 1 48 81 89 94
88 25 42 50 74

83 80 22 64 45
66 68 23 89 30
75 61 90 50 55
99 42 17 54 77
46 72 13 47  1

 7 22 27  6 71
29 41  9 32 47
84 67  2 92 53
36 12 56 68 11
74 48 38 96 51

85 53  8 73 41
48 70  7 88 89
87 63 11 32 12
33 61 96 65 18
52 97 20 45 67

70  0 51 30 37
23 46 55 98 77
 9 38 19 63 76
 4 91 33  8 60
92 67 39 47 85

19  9 17 28 26
24 99 87 46 93
16 97 41 96 13
44 95 56 77 98
15 61  7  5 58

65 11 68 97 95
36 19 31 40 76
12 79 27 34  9
 6 30 78 96 74
42 93 49 89 20

47 93 71 33 80
62 70  4 32 21
51 72 38 36 48
40  7 76 16 60
94 83 69 15 25

85 39 23 25  5
47 55 75 45 42
96 18 84 71 92
 0 19 56 29 14
58  6 79 21 43

26 28 59 55 49
48 91 50 33 94
78 97 43 71 17
 0 95 93 36 80
68 18 54 75 53

99 69 93 81 46
73 66  4 96 24
45 82  6  0 19
83 62 58 18 27
94 52 22 70 37

68 53 35 29 56
64  8 85 99 41
86 23 17 83  4
28 72 50 74 19
32 11 60 12 39

26  5 42 44 70
46 86  2 28  1
33 93 67 50  8
36  7 57 48 71
 3 80 45 49 15

66 47 14 37 52
71 32 95 28 50
58  1  0 51 30
44 11 79 74 75
46 64 26 29 13

25  0 44 52 11
18 68  9 81  1
42 41 55 63 91
10 87 53  7 17
90 24 49 21 99

12 73 26 13 98
60  5 17 11 52
 9 65 33 78 51
91 99  6  8 55
29 49 87 21 67

93 25  7 11 96
22 48 46 75 90
19 28 77 81 54
 2 31 16 14 32
27 36 52  5 64

12 26 90 61 10
35 75 53 13 51
50  9  5 71 15
32 95 55  4 78
98 48 94 19 27

64 75 20 77 82
46 63 83 69 41
44 15 73 35 61
99 71  4 43 72
76 81 93 23  0

46 49 42  7 71
39 82  2 61 11
87 81 67 57 85
52  6 92 19 98
72 76 99 45 96

 4 96 46 42 91
78  2 52 22 51
63 65 37 19 45
 7 77  5 87 36
 8 55  9 56 97

92 81 27 41 10
93 35 39 84 57
19 11 28 97 33
 4 64 95 40 30
 9 20 29 82 96

42 21 70 94 18
66 15 11 79 89
41 13  6 27 77
56 37  3 16  8
 4 28 24 96 10

36 54 66 95 53
10 92  1 38 44
 0 26 84 13 48
99  6 17 34  9
22 50 33 12  7

45 70 25 99 66
77 19 28 75 93
58 95 72 38 37
 7 98 24 68 15
61 29  1 55 97

 8  6 61 67 60
14 53 78  4 66
54 77 39 79 73
88 99 41 70 26
49 86 40 69 16

18 94 52 49 97
36 38 66  5 34
48 11 95 92 62
58 98 33 28 76
24 25 43 69 10

68 17 51 38 80
66 85 33  7 40
24 65 73 29 75
45 42  0 46  5
84 54 67 86 19

18 47 72 17 44
33 66 19 50  2
39 28 48  5  4
97 29 30 80 67
46 55 84 99 59

52 65 63 69 68
67 25 27 46  4
42 10 37 99 81
29  3 93 91 96
36 19 70 75 88

25 15 63 32 17
82 61 65 34 45
92  4 33 80 54
55 70 20 28  8
44 52 23 26 11

30 35 52 81 47
82 33 62 97 34
90  1 86 88 68
36 77 18 12 93
 9 91 43 87 24

93 26 16 30  7
 9 72 58 74 10
62 12 80 27 43
51 40 55  3 83
28 81 56 52 49

64 56 85  9 70
93 65 50 42 89
11 81 52 57 99
44  8 73 45 47
35 54 86 12 58

 4 63  6 17 59
86 81 65 55 36
16 30 34 79 20
80 98  2 88 40
94 23 69 28 27

 0 76 35 44 27
14 70 87 63  7
81 80  4  1 69
33 26 73 25 18
86 66  3 85 92

21 27 16 80 30
39 79 12 24 47
15 46 90 13 33
28 49 36  8 34
72  6 87 44 59

82 99 44 76 59
42 53 39 47 80
58 78 68 84  9
97 65 74 95 14
55 54 32 50 19

50 37  1 67 84
24 68 34 41 55
43 66 85 35 88
58 40 71 10 32
78 62 94 14 33

89 81 79 16  6
86 91  7 31  1
47 84 46 23  8
66 64 48 27 69
97 73 22 60 80

25 76 42 48 67
 0 99 96  5 82
86  8 24 28 90
21 92 56  4 53
74 61 15 12 50

67 16 88 98  0
10 15 99 96 56
43 51 13 58 97
94 57 28 29 23
40 32  4  9 17

86 30  2 35 46
88 60 57  9 45
70  3 92 80 18
11 32 48  1 23
12 19 74 39  6

62 78 16 48 74
88 49 43 44 35
87 51 99 17 86
92 28 70 19 18
25 80 50 52 24

64  9 77 44 31
11 23 33 62  7
14 53 84 41 12
87 48 34  0 63
71 91 78 27 29

49 42 54 43 98
 7 32 51 62 40
31 69 17 89  8
46  5 64 10  1
41 73 99 94  6

22 84 32 80 30
99 74 60 78 10
83  4 63 77 67
17 44 54  6 90
14 91 55 53 18

53 41 12 91 90
23 66 67 57 11
55  5 58 16 62
61 44 21 95  0
45 59 20 96 29

40 46 68 90 56
 9 17 13 20 59
76 91 51 39 99
72 42 16 69 27
30 52 71  3 66

 0 76 19 13 21
26 72 12 27 11
65 68 30 39 90
22 59 49 80 52
66 23 25  6 24

85 64 17 38 66
 2 99 33 50 52
58 42 15 86 47
19 81 16 43 92
28 30 59 80 36

53 46 30 91  5
17  8 62 31 12
45 52 56 41 97
87 65 26 63 36
58 42 86 68 92

72 94 25 75 15
48 61 68 38  9
 1 81 77 96 51
86 82 58 89 70
90 78  8 63  5

45 58 41 27 61
44 26 18 13 72
77 39 81 74  5
59 76 96 42 55
53 48 79 49 83

19 63  3 71 35
46 13  1 84 30
25 81 83 27 49
 2 74 93 48 98
78 34 68 29 26

87  3 46 88 19
14  8 23 34 60
90 15 75 51 74
53 35 94 11 84
49 12 18  1 64

 3 26 34 67 45
13 85 32 21 51
73 44 11 15  6
46 80 35 18 64
29 38 39 54 94

61 25 82  7 22
39 87 75 81 18
37 20 17 11 52
91 70 35 71 30
86 43 40 58  0

10 98 82 53 94
93 29 81 45 80
88 15  6 24 14
25 65 84 54 59
58  7 16 48 22

39 96 24 18 80
43 29 26 87 41
35 16  3 28 56
12 95 42 92 38
45  0 68  1 10

50 72 88 42 69
53 37 63 43 34
26  6  7 49 87
66 38 28 65 18
 5 35 80 15 59

30 65 33 48 97
43 29  0 73 52
26 35 36 28 39
58 51 82 16 75
12 62 55 83 19

 0 88 72  2 19
91 76 10 16 97
31 37 39 67 53
83 54 93  5 18
63 45 17 78 80

68  9 48 64 70
61 95 81 50 15
84 38 42 51 96
65 29 39 41  7
 5  2 12 23 56

82 97 57 86 52
93 45 89  9 23
41 32 61 16  2
 0 26 71 51 28
14 66 40 75 74

53 27  6 92 81
37 45 91 78 65
41  4 86 97 69
40 58 26 14 28
47 30 46 95 98

39 75 72 69 78
29 31 36 23 19
79 57 49 34 22
87 54 77 11 26
76  3 83 18 15

58 84 73 91 83
 6 52 81 92 76
23 18 62 66 77
79 89  4 41 72
59 36 13  8 31

81 32 67 75 44
96  3 90 11 46
61  1 14  2 86
89 24 53  8  7
26 20 18 59 42

71 77 24 72 43
41 38 62 21 36
70 10 37 60 83
79 94 39  0 51
73 46 98 34 50

96 26 95 48 17
97 40 42 53 35
74 67 47 22 23
14 70 54  8 66
52 31 63 34  1

96 55 84 44 10
57 80 30 52 72
42 40 36 41 73
85 38 64 63 13
47 16  8 76 94

Day 05: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

input1.txt
0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
3,4 -> 1,4
0,0 -> 8,8
5,5 -> 8,2
ventLine.ts
export class VentLine {
    private x1: number;
    private x2: number;
    private y1: number;
    private y2: number;

    constructor(line: string, private includeDiagonal: boolean) {
        const tokens = line.split(' ');
        const first = tokens[0].split(',');
        const second = tokens[2].split(',');
        this.x1 = parseInt(first[0]);
        this.y1 = parseInt(first[1]);
        this.x2 = parseInt(second[0]);
        this.y2 = parseInt(second[1]);
    }

    public isHorizontal(): boolean {
        return this.y1 == this.y2;
    }

    public isVertical(): boolean {
        return this.x1 == this.x2;
    }

    public listCovered(): number[][] {
        let result: number[][] = [];
        if (this.isHorizontal()) {
            for (let x = Math.min(this.x1, this.x2); x <= Math.max(this.x1, this.x2); ++x) {
                result.push([x, this.y1]);
            }
        }

        if (this.isVertical()) {
            for (let y = Math.min(this.y1, this.y2); y <= Math.max(this.y1,this.y2); ++y) {
                result.push([this.x1, y]);
            }
        }

        if (this.includeDiagonal && this.isDiagonal()) {
            if (this.x1 <= this.x2 && this.y1 <= this.y2) {
                for (let x = this.x1, y = this.y1; x <= this.x2, y <= this.y2; ++x, ++y) {
                    result.push([x, y]);
                }
            }

            if (this.x1 > this.x2 && this.y1 <= this.y2) {
                for (let x = this.x1, y = this.y1; x >= this.x2, y <= this.y2; --x, ++y) {
                    result.push([x, y]);
                }
            }

            if (this.x1 <= this.x2 && this.y1 > this.y2) {
                for (let x = this.x1, y = this.y1; x <= this.x2, y >= this.y2; ++x, --y) {
                    result.push([x, y]);
                }
            }

            if (this.x1 > this.x2 && this.y1 > this.y2) {
                for (let x = this.x1, y = this.y1; x >= this.x2, y >= this.y2; --x, --y) {
                    result.push([x, y]);
                }
            }
        }

        if (result.length == 0) {
            console.log('neither h, v nor d.')
        }

        return result;
    }

    public isDiagonal(): boolean {
        return Math.abs(this.x2 - this.x1) == Math.abs(this.y2 - this.y1);
    }
}
ventAnalysis.ts
import * as r from './read';
import { VentLine } from './ventLine';

export class VentAnalysis {
    private lines: string[];

    constructor() {
        this.lines = r.readLines('input.txt', 'day05/typescript/aspik79');
    }

    /**
     * Counts the number of cells with heat vent counts greater than one.
     * @param includeDiagonal if false only horizontal and vertical vents count.
     * @returns count of cells with vent count greater than one.
     */
    public countHighVentAreas(includeDiagonal: boolean): number {
        const vents = this.lines.map(l => new VentLine(l, includeDiagonal));
        let heatMap = this.buildHeatMap(vents);

        return heatMap.flat().filter(n => n > 1).length;
    }

    private buildHeatMap(vents: VentLine[]) : number[][] {
        let heatMap: number[][] = [];

        for (const v of vents) {
            for (const c of v.listCovered()) {
                let row = heatMap[c[0]];
                if (row == undefined) {
                    // Make sure the row exists.
                    heatMap[c[0]] = [];
                }

                let n1 = heatMap[c[0]][c[1]];
                if (n1 == undefined) {
                    // Make sure the cell is initialized.
                    n1 = 0;
                }

                // Increment the heat map's cell value.
                heatMap[c[0]][c[1]] = n1 + 1;
            }
        }

        return heatMap;
    }
}
read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
main.ts
import { VentAnalysis } from "./ventAnalysis";

// Day 5: Hydrothermal Venture by Christoph Jobmann
const ventAnalysis = new VentAnalysis();
console.log(ventAnalysis.countHighVentAreas(false));

console.log(ventAnalysis.countHighVentAreas(true));
input.txt
491,392 -> 34,392
337,52 -> 485,52
256,605 -> 256,959
889,142 -> 153,878
189,59 -> 512,382
399,193 -> 598,193
578,370 -> 795,153
79,450 -> 569,450
565,444 -> 270,149
39,28 -> 39,846
114,353 -> 114,383
356,61 -> 356,327
140,132 -> 515,132
361,848 -> 361,527
466,257 -> 466,784
818,397 -> 818,14
693,554 -> 693,984
171,290 -> 171,655
989,889 -> 170,70
527,855 -> 527,549
209,355 -> 486,355
800,430 -> 291,939
980,38 -> 31,987
964,559 -> 964,799
491,612 -> 930,173
57,977 -> 958,76
149,465 -> 349,465
512,624 -> 629,507
460,943 -> 460,441
988,29 -> 988,968
104,337 -> 441,337
939,48 -> 939,546
941,904 -> 498,461
850,972 -> 649,771
840,901 -> 23,84
231,790 -> 231,873
230,668 -> 840,58
410,922 -> 435,897
341,337 -> 341,406
264,752 -> 258,752
457,969 -> 457,757
465,42 -> 465,350
748,783 -> 502,783
461,930 -> 461,142
392,265 -> 215,265
417,805 -> 417,231
825,870 -> 60,105
524,167 -> 703,346
963,829 -> 308,174
730,361 -> 730,252
61,373 -> 61,593
873,893 -> 132,152
820,719 -> 417,719
142,238 -> 212,168
142,653 -> 676,119
392,955 -> 392,453
368,385 -> 414,385
464,762 -> 592,762
542,168 -> 542,789
622,693 -> 166,237
477,290 -> 792,290
731,56 -> 731,677
516,77 -> 326,77
595,973 -> 779,973
68,487 -> 128,487
389,738 -> 762,738
721,13 -> 827,119
797,625 -> 347,625
75,67 -> 75,458
931,142 -> 219,854
422,835 -> 980,835
278,565 -> 753,565
225,970 -> 806,389
791,725 -> 691,725
924,975 -> 18,69
326,763 -> 969,120
663,895 -> 663,559
940,965 -> 142,167
146,425 -> 791,425
832,968 -> 272,408
494,804 -> 694,804
23,25 -> 900,902
621,163 -> 894,163
587,605 -> 587,716
41,931 -> 383,589
888,530 -> 341,530
292,801 -> 292,567
537,213 -> 245,213
513,84 -> 527,84
623,516 -> 623,128
549,729 -> 509,729
576,232 -> 869,232
513,847 -> 433,847
536,612 -> 434,612
608,377 -> 33,952
137,762 -> 424,475
329,286 -> 584,541
493,296 -> 493,316
160,343 -> 189,343
477,929 -> 976,430
695,607 -> 557,607
745,322 -> 28,322
777,73 -> 76,774
163,723 -> 163,816
30,549 -> 63,516
163,914 -> 898,179
603,823 -> 603,78
498,616 -> 886,228
229,591 -> 341,591
742,841 -> 343,841
720,808 -> 934,808
985,48 -> 48,985
368,859 -> 178,859
506,30 -> 144,30
19,110 -> 19,750
293,689 -> 293,294
13,462 -> 980,462
536,963 -> 346,773
836,471 -> 462,471
506,952 -> 489,952
830,15 -> 461,15
392,378 -> 237,378
295,48 -> 295,825
264,679 -> 264,602
487,582 -> 487,116
832,677 -> 788,677
469,770 -> 211,512
400,773 -> 394,773
262,836 -> 262,454
51,17 -> 969,935
483,525 -> 838,880
71,124 -> 164,31
103,226 -> 912,226
785,169 -> 785,454
858,825 -> 176,143
248,960 -> 427,781
255,37 -> 767,37
832,149 -> 506,149
256,246 -> 86,246
447,448 -> 765,448
654,159 -> 654,158
120,500 -> 120,341
200,19 -> 839,658
451,251 -> 763,563
931,75 -> 931,312
69,404 -> 311,646
31,678 -> 31,231
410,307 -> 410,236
988,976 -> 387,375
654,402 -> 738,486
30,942 -> 942,30
115,652 -> 98,669
405,764 -> 375,734
88,759 -> 125,759
636,835 -> 722,835
300,60 -> 126,60
159,225 -> 159,319
934,188 -> 934,74
46,822 -> 708,160
605,612 -> 605,463
200,281 -> 536,617
392,11 -> 79,324
917,126 -> 258,785
803,143 -> 803,180
116,556 -> 651,556
922,222 -> 468,676
266,782 -> 896,782
733,448 -> 764,448
915,75 -> 305,685
150,243 -> 842,243
485,641 -> 963,641
965,206 -> 965,275
78,868 -> 748,198
37,947 -> 859,947
429,289 -> 429,48
378,261 -> 378,624
768,494 -> 768,782
702,566 -> 113,566
290,148 -> 913,771
806,931 -> 849,931
725,970 -> 299,970
38,565 -> 740,565
262,730 -> 973,730
826,376 -> 826,97
318,576 -> 318,227
159,868 -> 448,868
344,256 -> 344,615
824,188 -> 588,424
505,843 -> 897,843
293,348 -> 293,488
433,833 -> 165,565
56,471 -> 169,471
77,896 -> 914,59
405,904 -> 405,174
274,364 -> 274,88
785,704 -> 538,704
877,389 -> 681,389
790,936 -> 327,936
89,143 -> 755,809
721,450 -> 721,406
253,664 -> 811,664
881,143 -> 97,927
205,738 -> 645,738
869,951 -> 282,364
374,697 -> 374,592
251,989 -> 251,977
521,187 -> 885,187
536,401 -> 536,38
636,840 -> 636,873
695,333 -> 52,976
790,757 -> 790,358
314,765 -> 882,765
880,439 -> 127,439
266,848 -> 810,304
802,419 -> 802,936
554,67 -> 554,956
311,379 -> 685,753
183,544 -> 305,544
857,341 -> 407,791
306,559 -> 727,980
184,477 -> 509,152
934,174 -> 934,154
28,12 -> 28,968
418,984 -> 112,678
788,89 -> 837,89
229,425 -> 192,462
714,701 -> 424,411
198,313 -> 156,355
142,742 -> 215,742
15,639 -> 15,787
573,396 -> 462,396
954,977 -> 76,99
645,448 -> 652,448
958,822 -> 376,240
47,359 -> 212,194
524,366 -> 524,916
100,977 -> 501,576
932,148 -> 115,965
854,120 -> 421,553
318,630 -> 318,964
196,31 -> 874,709
812,826 -> 812,679
111,890 -> 897,104
46,35 -> 972,35
40,842 -> 40,835
390,510 -> 98,510
832,57 -> 124,765
422,331 -> 422,44
696,837 -> 696,555
849,571 -> 849,679
598,143 -> 598,261
670,745 -> 670,757
660,390 -> 660,912
960,578 -> 960,253
123,343 -> 123,28
643,199 -> 969,199
66,642 -> 669,39
776,30 -> 776,173
595,951 -> 84,951
908,183 -> 724,367
330,332 -> 330,455
954,955 -> 188,955
981,269 -> 90,269
235,579 -> 513,579
217,25 -> 217,990
811,810 -> 811,405
245,255 -> 367,255
860,225 -> 860,100
753,626 -> 697,626
755,404 -> 836,404
733,476 -> 336,476
562,172 -> 964,172
339,989 -> 749,989
167,581 -> 167,611
217,475 -> 217,747
103,598 -> 431,270
11,989 -> 989,11
925,90 -> 46,969
26,963 -> 935,54
40,925 -> 40,816
67,942 -> 984,25
933,652 -> 933,242
942,292 -> 942,138
889,909 -> 180,200
604,770 -> 237,770
30,627 -> 973,627
750,777 -> 750,645
254,797 -> 254,169
939,167 -> 347,759
889,682 -> 394,682
788,338 -> 388,338
757,252 -> 169,252
806,131 -> 699,131
562,270 -> 562,481
950,349 -> 459,840
219,915 -> 932,202
977,505 -> 977,708
915,559 -> 915,125
366,397 -> 366,717
54,723 -> 433,723
570,842 -> 236,508
513,365 -> 513,80
569,523 -> 569,266
278,764 -> 278,178
136,136 -> 84,84
787,108 -> 787,809
461,388 -> 855,782
64,898 -> 848,114
628,71 -> 178,521
842,66 -> 842,699
293,68 -> 742,68
960,102 -> 358,704
834,669 -> 27,669
11,43 -> 374,406
399,803 -> 340,803
564,211 -> 20,755
370,841 -> 370,321
518,590 -> 518,255
470,150 -> 470,850
769,182 -> 234,717
97,787 -> 97,382
36,31 -> 982,977
831,467 -> 471,827
253,836 -> 547,836
957,681 -> 957,919
768,831 -> 768,275
98,36 -> 955,893
283,413 -> 840,413
21,870 -> 20,870
979,507 -> 979,37
339,757 -> 210,757
388,594 -> 801,594
867,939 -> 91,163
755,864 -> 755,501
856,177 -> 736,57
74,365 -> 376,63
386,451 -> 815,22
389,883 -> 679,593
116,216 -> 157,175
693,960 -> 693,454
704,962 -> 306,962
613,442 -> 867,442
578,13 -> 578,855
417,683 -> 118,683
127,161 -> 742,161
646,979 -> 646,270
14,842 -> 14,802
496,902 -> 506,912
468,354 -> 468,875
714,431 -> 714,172
554,297 -> 554,790
717,664 -> 883,664
551,182 -> 980,611
794,932 -> 499,637
384,499 -> 507,499
32,368 -> 257,368
984,131 -> 904,131
973,16 -> 10,979
189,178 -> 189,752
492,404 -> 492,593
11,515 -> 117,515
230,182 -> 230,954
652,16 -> 663,16
698,693 -> 490,693
252,942 -> 587,942
551,901 -> 428,778
899,320 -> 903,316
14,577 -> 313,278
409,576 -> 409,475
466,883 -> 819,883
221,472 -> 609,472
686,828 -> 686,720
988,989 -> 13,14
514,171 -> 227,171
868,842 -> 632,842
279,824 -> 697,406
678,464 -> 678,687
736,358 -> 736,259
933,66 -> 24,975
679,470 -> 679,689
979,953 -> 45,19
98,826 -> 737,187
612,732 -> 612,681
985,23 -> 23,985
787,732 -> 332,277
660,211 -> 660,61
395,19 -> 246,19
129,876 -> 955,50
676,246 -> 821,246
980,26 -> 18,988
142,945 -> 142,218
165,240 -> 540,240
941,522 -> 941,129
876,274 -> 876,340
627,782 -> 905,782
928,235 -> 246,235
336,449 -> 92,205
748,62 -> 748,787
804,725 -> 356,277
910,89 -> 19,980
391,99 -> 155,335
608,127 -> 516,219
337,255 -> 337,649
818,831 -> 818,859
146,204 -> 301,359
629,646 -> 906,923
87,860 -> 824,123
613,867 -> 613,946
286,339 -> 286,626
942,120 -> 595,467
35,207 -> 187,207
684,559 -> 283,158
48,768 -> 48,349
656,965 -> 656,27
865,341 -> 865,576
218,786 -> 152,786
697,69 -> 583,69
790,79 -> 552,79
310,547 -> 846,11
428,809 -> 428,940
664,829 -> 664,455
265,775 -> 749,775
362,221 -> 309,168
437,253 -> 437,597
601,324 -> 245,680
24,69 -> 24,476
420,344 -> 420,525
215,866 -> 635,866
926,770 -> 315,770
413,650 -> 413,624
751,765 -> 475,489
673,709 -> 39,75
230,689 -> 805,689
31,209 -> 789,967
698,255 -> 909,255
641,752 -> 866,527
346,780 -> 391,825
328,905 -> 328,130
628,674 -> 628,354
666,110 -> 98,678
846,651 -> 846,371
28,946 -> 28,482
289,844 -> 458,675
605,602 -> 605,297
355,217 -> 239,217
453,96 -> 195,354
988,90 -> 145,933
801,194 -> 801,109
894,708 -> 894,212
177,447 -> 607,877
824,391 -> 788,391
386,940 -> 471,855
703,425 -> 583,425
848,110 -> 36,922
603,596 -> 685,678
584,458 -> 584,482
464,903 -> 343,903
888,413 -> 405,413
320,185 -> 103,185
475,458 -> 55,878
371,843 -> 371,466
785,507 -> 785,570
904,553 -> 904,983
872,600 -> 872,848
296,693 -> 751,238
490,488 -> 322,488
37,371 -> 185,223
238,618 -> 238,883
232,89 -> 123,89
20,14 -> 961,955
794,318 -> 914,318
407,499 -> 246,338
641,514 -> 227,514
284,210 -> 562,488
164,566 -> 498,900
20,825 -> 150,955
235,384 -> 537,686
151,116 -> 979,944
697,133 -> 59,771
212,226 -> 38,226
523,527 -> 523,497
119,493 -> 352,726
927,157 -> 154,930
336,149 -> 581,394
103,580 -> 354,580
891,494 -> 532,853
22,272 -> 538,788
544,296 -> 519,271
821,382 -> 821,155
501,807 -> 501,202
588,76 -> 708,76
773,681 -> 184,681
754,936 -> 86,268
582,972 -> 40,972
530,458 -> 530,329
109,433 -> 649,433
411,215 -> 411,311
433,568 -> 433,585
232,504 -> 799,504
72,442 -> 38,442

Day 06: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

input1.txt
3,4,3,1,2
read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
main.ts
// Day 06: Lanternfish  by Christoph Jobmann

import { FishPopulation } from "./fishPopulation";

const fp = new FishPopulation();
console.log(fp.getPopulationSmartAfter(80));
console.log(fp.getPopulationSmartAfter(256));
fishPopulation.ts
import * as r from './read';

export class FishPopulation {
    private line: string;
    private startPopulation: number[];
    private interval = 7;
    private offset = 2;

    constructor() {
        this.line = r.readLines('input.txt', '')[0];
        this.startPopulation = this.line.split(',').map(s => parseInt(s));
    }

    /**
     * Straightforward approach for simulating popolation. Sufficient for first star.
     * @param steps Number of steps that are to be simulated.
     * @returns population size after the given number of steps.
     */
    public getPopulationAfter(steps: number) : number {
        let pop = this.startPopulation.slice(0);
        for (let c = 0; c < steps; ++c){
            pop = this.advancePopulation(pop);
        }

        return pop.length;
    }

    /**
     * Smarter approach that is more efficient.
     * @param steps Number of steps that are to be simulated.
     * @returns population size after the given number of steps.
     */
    public getPopulationSmartAfter(steps: number) : number {
        let pop = new Array<number>(this.interval).fill(0);

        for (let timer of this.startPopulation) {
            ++pop[timer];
        }

        for (let c = 0; c < steps; ++c){
            pop = this.advancePopulationSmart(pop);
        }

        return pop.reduce((sum, p) => sum + p, 0);
    }

    private advancePopulation(current: number[]) : number[] {
        const next = current.slice(0);

        for (const index in current) {
            const timer = current[index] - 1;
            if (timer < 0) {
                // Timer goes below 0 - time for reproduction.
                // Add the offspring.
                next.push(this.interval - 1 + this.offset);

                // Reset timer.
                next[index] = this.interval - 1
            }
            else {
                // Apply reduced timer.
                next[index] = timer;
            }
        }

        return next;
    }


    private advancePopulationSmart(current: number[]) : number[] {
        const next: number[] = Array<number>(this.interval + this.offset).fill(0);

        for (const index in current) {

            let x: number = parseInt(index);
            const timer = parseInt(index) - 1;
            if (timer < 0) {
                // Timer goes below 0 - time for reproduction.
                // Add the offspring.
                next[this.interval - 1 + this.offset] = (current[index] ?? 0);

                // Reset timer.
                next[this.interval - 1] = current[index];
            }
            else {
                // Shift amount of fishes for timer value.
                next[timer] += (current[index] ?? 0);
            }
        }

        return next;
    }
}
input.txt
5,1,2,1,5,3,1,1,1,1,1,2,5,4,1,1,1,1,2,1,2,1,1,1,1,1,2,1,5,1,1,1,3,1,1,1,3,1,1,3,1,1,4,3,1,1,4,1,1,1,1,2,1,1,1,5,1,1,5,1,1,1,4,4,2,5,1,1,5,1,1,2,2,1,2,1,1,5,3,1,2,1,1,3,1,4,3,3,1,1,3,1,5,1,1,3,1,1,4,4,1,1,1,5,1,1,1,4,4,1,3,1,4,1,1,4,5,1,1,1,4,3,1,4,1,1,4,4,3,5,1,2,2,1,2,2,1,1,1,2,1,1,1,4,1,1,3,1,1,2,1,4,1,1,1,1,1,1,1,1,2,2,1,1,5,5,1,1,1,5,1,1,1,1,5,1,3,2,1,1,5,2,3,1,2,2,2,5,1,1,3,1,1,1,5,1,4,1,1,1,3,2,1,3,3,1,3,1,1,1,1,1,1,1,2,3,1,5,1,4,1,3,5,1,1,1,2,2,1,1,1,1,5,4,1,1,3,1,2,4,2,1,1,3,5,1,1,1,3,1,1,1,5,1,1,1,1,1,3,1,1,1,4,1,1,1,1,2,2,1,1,1,1,5,3,1,2,3,4,1,1,5,1,2,4,2,1,1,1,2,1,1,1,1,1,1,1,4,1,5

Day 07: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

input1.txt
16,1,2,0,4,2,7,1,2,14
read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
main.ts
// Day 07: The Treachery of Whales
// Solution by Christoph Jobmann

import { CrabAligner } from "./crabAligner";

console.log(new CrabAligner(true).countMinAlignmentFuel());
console.log(new CrabAligner(false).countMinAlignmentFuel());
crabAligner.ts
import * as r from './read';

/**
 * Class for evalualting fuel for minimum crab-in-a-sub alignment.
 */
export class CrabAligner {
    private positions: number[];

    /**
     * Initializes a new instance of the CrabAligner class.
     * @constantFuel If true fuel consumption is constant, otherwise linear.
     */
    constructor(private constantFuel: boolean) {
        const line = r.readLines('input.txt', '')[0];
        this.positions = line.split(',').map(s => parseInt(s));
    }

    /**
     * Count the minimum amount of fuel consumption for alignment.
     */
    public countMinAlignmentFuel() {
        const min = Math.min(...this.positions);
        const max = Math.max(...this.positions);

        let minFuel = this.countAlignment(min);

        for (let target = min + 1; target <= max; ++target) {
            const fuel = this.countAlignment(target);
            if (fuel < minFuel) {
                minFuel = fuel;
            }
        }

        return minFuel;
    }

    private countAlignment(target: number) : number {
        return this.positions.reduce((sum, current) => sum + this.calculateFuel(Math.abs(current - target)), 0);
    }

    private calculateFuel(distance: number) : number {
        // Thanks to Mr. Gauss for simplified calcualtion of aggregated fuel use.
        return this.constantFuel ? distance : distance * (distance + 1) / 2;
    }
}
input.txt
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,841,69,1401,423,17,18,427,405,56,624,1657,333,194,691,31,130,951,165,1952,483,109,126,67,163,457,542,808,75,418,21,483,22,648,447,153,41,1267,114,1531,6,456,841,42,908,256,136,18,326,69,1300,626,28,943,326,225,53,1254,707,20,792,141,470,178,337,280,181,977,153,213,300,919,1540,1667,245,732,257,137,762,1637,968,511,409,605,402,456,0,1269,166,82,359,416,315,95,66,477,1375,816,255,2,1084,1396,84,343,173,215,128,314,856,696,210,350,1111,709,517,39,6,8,503,166,94,387,1254,281,231,515,125,618,267,316,682,684,1118,12,927,548,151,907,222,915,618,14,859,131,750,293,1067,857,248,750,161,466,101,263,44,9,21,612,201,13,51,989,281,30,119,521,36,21,1705,21,451,12,264,813,218,1097,640,154,421,386,395,359,706,313,215,615,502,0,15,20,665,379,524,164,419,872,1113,131,76,211,422,27,611,308,162,1125,879,68,661,154,166,556,279,1160,389,315,213,791,396,608,269,844,470,856,450,268,408,1817,1040,1574,423,868,43,132,886,37,43,109,19,485,1185,1251,1070,258,345,42,334,221,730,563,152,5,1326,97,551,139,1701,296,371,577,694,1152,191,1056,26,511,566,446,431,858,967,303,962,325,121,1660,26,928,156,320,51,328,998,466,809,22,1685,489,260,258,1005,330,243,241,1130,1143,607,549,69,276,20,175,91,1081,227,1219,1597,66,110,11,73,238,78,1299,814,1051,261,54,61,678,44,439,249,115,251,232,14,294,195,336,334,113,420,70,186,34,31,590,412,330,1182,310,316,426,235,485,303,561,961,121,171,59,132,513,239,1277,519,324,102,245,172,283,292,663,10,852,1132,434,1046,1671,1208,32,1249,221,176,13,80,730,354,743,308,662,1016,148,333,179,100,1698,719,157,392,329,400,790,368,437,174,1577,14,388,844,132,82,294,140,3,363,215,56,1330,481,171,539,1670,78,1590,757,1357,15,863,295,448,340,420,569,542,750,49,23,803,122,1079,489,1281,75,1055,938,245,137,221,664,254,1179,15,225,529,829,346,128,380,295,388,51,1038,1001,223,256,611,965,189,664,1676,825,282,417,394,202,434,513,529,2,395,797,1683,771,176,207,32,129,385,99,204,513,132,365,644,2,37,618,228,282,363,991,475,1476,91,843,1347,130,1683,737,53,684,501,323,274,88,214,558,6,858,190,129,38,1294,343,266,73,1379,179,190,290,506,37,163,832,46,407,474,920,136,1220,1305,113,208,514,917,93,125,82,1222,116,426,921,296,276,717,867,792,643,48,1326,233,550,385,638,672,184,1189,23,267,302,222,149,904,660,452,53,32,744,749,235,124,588,762,130,17,885,1464,1813,208,732,597,881,154,155,844,446,653,820,60,420,476,591,101,898,1124,100,750,20,554,699,1109,997,1093,1109,279,1020,246,62,46,1830,2,514,3,54,310,90,140,584,852,649,58,166,517,563,317,437,910,365,26,170,124,147,145,46,500,124,475,689,1277,227,116,570,965,524,6,250,327,39,365,1058,5,840,681,199,1070,29,840,148,290,189,93,265,1775,1244,374,210,85,61,460,36,1157,1019,1338,644,624,1101,927,228,413,18,1312,612,374,520,1801,362,656,569,593,165,38,76,9,912,149,36,386,280,1279,512,568,963,347,75,327,268,629,10,260,67,1299,963,932,245,452,890,953,1140,544,523,288,316,317,761,283,907,552,9,259,1270,722,129,362,81,571,222,33,362,542,111,107,50,285,213,304,421,362,1751,219,57,766,1096,1333,48,597,730,910,129,559,962,170,59,246,4,1094,328,733,105,65,837,213,174,3,133,757,148,26,558,309,636,40,1615,757,478,1080,9,499,499,1224,0,871,457,34,738,489,322,55,36,24,369,1056,232,217,196,169,204,114,1097,239,471,681,45,853,782,832,322,441,269,1413,1100,95,51,70,763,456,194,310,614,266,31,754,13,561,904,303,266,1567,34,1707,370,629,13,378,144,527,48,520,1348,322,401,454,423,528,29,619,430,916,974,74,1321,940,504,365,240,1801,1045,267,622,424,1481,1020,121,546,208,138,487,622,1557,379,249,148,500,51,828,447,260,1241,585,219,108,601,772,979,1774,12,20,356,405,342,558,19,334,161,235,328,55,233,644,201,645,149,230,201,1305,26,943,207,253,1477,559,120,1015,31,494,87,393,1740,315,195,328,2,472,101,995

Day 08: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

digitSearcher.ts
import * as r from './read';

export class DigitSearcher {
    private lines: string[];

    private patterns: string[] = [
        'abcefg',
        'cf',
        'acdeg',
        'acdfg',
        'bcdf',
        'abdfg',
        'abdefg',
        'acf',
        'abcdefg',
        'abcdfg'
    ];

    private segmentCountForNumber = this.patterns.map(p => p.length);

    private simpleNumbers = [1, 4, 7, 8];

    /**
     * Initializes a new instance of the DigitSearcher class.
     */
    constructor() {
        this.lines = r.readLines('input.txt', '');
    }

    /**
     * Counts the occurrence of easy-to-decode digits.
     * @returns Amount of decoded digits (if they were easy to decode).
     */
    public countSimpleDigits() : number[] {
        let result: number[] = new Array<number>(10).fill(0);

        for (let line of this.lines) {
            let [signal, output] = line.split(' | ');

            const tokens = output.split(' ');
            for (let token of tokens) {
                for (let n of this.simpleNumbers) {
                    if (token.length == this.segmentCountForNumber[n]) {
                        ++result[n];
                    }
                }
            }
        }

        return result;
    }

    /**
     * Collect all translated outputs.
     * @returns Translated outputs.
     */
    public collectOutputs() : number[] {
        let result: number[] = [];

        for (let line of this.lines) {
            result.push(this.processLine(line));
        }

        return result;
    }

    private processLine(line: string) : number {
        const [signal, output] = line.split(' | ');

        const pattern: string[] =  this.determinePatterns(signal);

        let result = 0;

        let otokens = sortedTokens(output.split(' '));
        for (let otoken of otokens) {
            const idx = pattern.indexOf(otoken);
            if (idx >= 0) {
                result = result * 10 + idx;
            }
        }

        return result;
    }

    private determinePatterns(signal: string) : string[] {
        let tokens: string[] = sortedTokens(signal.split(' '));

        let pattern: string[] = Array<string>(10).fill('0');

        // Pattern extraction was solved by human - not sure how to do this via code without trying all permutations.
        pattern[1] = this.tokensCandidatesForNumber(tokens, 1)[0];
        pattern[4] = this.tokensCandidatesForNumber(tokens, 4)[0];
        pattern[7] = this.tokensCandidatesForNumber(tokens, 7)[0];
        pattern[8] = this.tokensCandidatesForNumber(tokens, 8)[0];

        pattern[6] = tokens.filter(t => t.length == this.segmentCountForNumber[6]
            && except(pattern[1], t).length == 1)[0];

        pattern[9] = tokens.filter(t => t.length == this.segmentCountForNumber[9]
            && intersect(pattern[4], t).length == 4)[0];

        pattern[0] = tokens.filter(t => t.length == this.segmentCountForNumber[0]
            && t != pattern[6] && t != pattern[9])[0];

        pattern[3] = this.tokensCandidatesForNumber(tokens, 3)
            .filter(t => intersect(t, pattern[1]).length == 2)[0];

        pattern[5] = this.tokensCandidatesForNumber(tokens, 5)
            .filter(t => intersect(t, pattern[6]).length == 5)[0];

        pattern[2] = this.tokensCandidatesForNumber(tokens, 2)
            .filter(t => !pattern.some(p => p == t))[0];

        return pattern;
    }

    private tokensCandidatesForNumber(tokens: string[], n: number) : string[] {
        return tokens.filter(t => t.length == this.segmentCountForNumber[n]);
    }
}

/**
 * Creates an array of sorted single characters from the string.
 */
function toSortedCharArray(s: string) : string[] {
    let result: string[] = [];
    for (let i = 0; i < s.length; ++i) {
        result.push(s.charAt(i));
    }

    result.sort((s1, s2) => s1.localeCompare(s2));

    return result;
}

/**
 * Processes the given tokens, creating a sorted representation of each token.
 * The order of tokens is preserved.
 */
function sortedTokens(tokens: string[]) : string[] {
    return tokens.map(t => toSortedCharArray(t).join(''));
}

/**
 * Determines the characters that are part of both strings.
 * @param s1 First string.
 * @param s2 Second string.
 * @returns Array of single characters that are part of both string.
 */
function intersect(s1: string, s2: string) : string[] {
    const expanded = toSortedCharArray(s2);
    let result: string[] = [];

    for (let x1 of toSortedCharArray(s1)) {
        if (expanded.includes(x1)) {
            result.push(x1);
        }
    }

    return result;
}

/**
 * Determines the characters that are part of the first but not the second string.
 * @param s1 First string.
 * @param s2 Second string.
 * @returns Array of single characters that are part of the first but not the second string.
 */
 function except(s1: string, s2: string) : string[] {
    const expanded = toSortedCharArray(s2);
    let result: string[] = [];
    for (let x1 of toSortedCharArray(s1)) {
        if (!s2.includes(x1)) {
            result.push(x1);
        }
    }

    return result;
}
read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
main.ts
// Day 8: Seven Segment Search
// Solution by Christoph Jobmann

import { DigitSearcher } from "./digitSearcher";

const ds = new DigitSearcher();
const simpleNumbers = ds.countSimpleDigits();
console.log(simpleNumbers.reduce((s, v) => s + v, 0));

const outputs = ds.collectOutputs();
console.log(outputs.reduce((s, v) => s + v, 0));
input.txt
fdeba beagfd gbafe dagb dbf ecfad bd dgcaefb fbecgd abfecg | dgba dfb ecadf bdf
dgfc egdbaf afgcbe eafdbcg bcgad bdg fdbacg gd ecabd bafgc | gd gbd dg febgac
dfebc bceadf ebacf gdceb fd dfea cdgfba afbgec dfb fdaecbg | cgafbde efbagc faed gecdb
dbaef fabgd fcaedb cgadf aefbgd cabefg gfb bceagdf bg ebdg | gdbfae geafdbc bafgdce dbgfa
aebgd adg dg dgcabef facedg cfaebd dfbega begca bfgd dbafe | abdecf eafbd fdgb ebdfgca
bae febac abcgf eabfgd cbagfd gefcba abedfcg efcda eb becg | fcgab gafbed aedcfbg eb
edbcg ba afcdeg gbaedf gcabdf eabf bagde bga deabgcf edfga | aebf ab bdfecag abfe
dbae dgfec egfbd fbgaed feb fcabdg be bfgda facebgd baefcg | bagecf efb eb fbcgad
cdagbef cd bdgcf efcbg adbgf cdga egdabf acbdfg cdf caebfd | fbdga fcd fcd adcg
abceg dbgca acfd ebagfdc dbecfg gdfbea dc dcg abfdcg gfbad | cdg dbcagf acdf gbcdef
bcdag acdgbef ebcdag facd dfgbe cfg bfagdc fc fbcgd bgfaec | fc dafbcg fc cbdgae
ca feacgb cedfgb bgaed gbaec acefdgb bfcge eafgcd acg fbac | ca cag gac becga
gbdcfa afdcb cebd fadce cbgfdea aec cdebfa ce caegfb daegf | aedfbgc eca eca cebd
cb dcb fdbegc bgaed fcba dacgfe efcadb dceaf eacgfbd dbaec | cbd cb bagde dcb
debgf gaecdfb gcbef cbgaf fbecag bce bgfcda ce aefc ebdgca | ebcfgad ec gefcba bec
cdbfega ae cedaf bedgcf ebac efadbg afcedb afe fgadc cdfbe | fabedcg cafbed efa badgcef
aceg bcafgde deacgb fdcgab dacgb eafbcd dgcbe bdfge bce ce | dbfge bdcafg fbdcga ebdfg
efcbda fcgbe efdgc efgdcab cagbe cbf bagf ecagdb bacefg fb | fgab aecgb acfgbe agecfbd
bcgd egafb adgbcf cafged cegadfb gd dgf dbfag dfeacb dcabf | adbcf dg gd dgf
bgeca fgcbe fcgd egfbd bcgdfe fc agbdef ecf dafgecb bdafec | fc febdag cgfd dfcbgae
agb dbfa gbafcde afgcbe edfgb bagde cfdegb gbdefa ba caged | bdfa bafd cfdgeba agb
bdf baefcdg df cafbgd bdcgef bcdeag bcgad cadf gfbad fbeag | ebacfgd facd cdgfbe df
edagc egbcfad bcfdge agbdcf fbdage dcabg bga bgfdc fbca ba | cebgfda gdcfabe gfcdba bag
bgaf af bcdfge ecfagd fgcdb beacd gdecbfa bcafd fac bfdgac | bagcedf fbedgc ebfgdc gbfa
fagbdc fagdeb cebgf cbd ecagdb cade dagcebf dc becdg geabd | gfbadec cdae dbc bcefg
dgfbeac abfge dcefag cga cgbd baced gc adfebc ecbag aedgbc | bfcaged gac gebaf egdafc
cfdbe afge fa gdfbeca agfcbd abedgc fac cafbe ecfgab acgeb | adcfgeb bcadfg ebfac cfa
gebdcf cdbga eag ae dagecbf bgdfe ebgfad gabed dagfec feab | fadgecb fgbced dgcab ega
gf gcbaf gfdc agf eafcb cadebfg cgfabd dbagc agdcbe egfbda | gf beafc fga fcgd
cbed ebgad gadbfe bc bcfgea gebacd gceadfb cgfad cbg abcgd | bacdg afbegdc bgc bcagdfe
fdg dg acgfdbe gafdec cfbdg ebfgc gdeb bdcgef fbegca fbdca | fdg edbg edbg cgfbe
gfcbaed gfceda cadbg gafdb ca adc fbca dfcabg cedbg aegfdb | ca becadfg dcefga ca
agfcbd edcabg cdf cdgfabe debgcf fdgca bfac gdcab cf gedaf | fc cdf cf bcagdef
cdagb bae ea cdfebg febacd egdfb gdacfbe feag aedfbg gdabe | ea gefa agbde afge
dab cgaedb cafbg faced bdfe bd gfdeca dafgbec fcbda cadbef | db edfb bd dcafe
bde cbaed dcbf ecbag fcbdae acgfde dgafebc db fbdgea dacfe | cadbe bcdf afebdg dcgfea
ag fgaecd egcbdaf ebacd gad dagbfe cfga fcegd dcbgfe gaced | dag ag gda gacf
fdaegb dcgefa bfdec geca ge fge cdbafg decbgaf ecdfg cagdf | gdefc cgea dfacgb gedbaf
ecgfab cgbdea dgabf dcfb bd dgcabf fgdeacb dba efagd cfabg | dab adb bfdc fcdbag
dfcae cfegbd ade cdeabg egacdf gcfde da becfadg agfd efcba | ade aed dfga ade
fdgeab adcbgfe edfca cebad gdbace dgcb beafgc bac cb gdeba | bdcea bgdc dagcfeb abc
cabdge fdgae fbgc fedgcb gfebacd dfbeg bf bdf ecgbd adecfb | fb aegfbcd bdf fbacged
dfbgec feacgdb ca adgec cda ecba gdaef degbc abfdgc gdceab | ca dabfegc ca acdeg
abd fbagec gfdbea dagc ad fcdbega bafcdg facbg ecbdf fbcad | edfagb bcedf dba fbdcag
abf ebfdcg fgcdbae faegc bdgacf bfdec bade ceafdb ba eacbf | fab fbdaecg dcabfg ba
ebcgf aedcb gbaecfd gd cgdeb cadfeb edga bdfgca cbgead cdg | adge fgbec cgd dgbcfa
gdcaef dcgbe fbcdage bacge aec ea bfea bcafg aegbcf cfdgab | bfea gfecadb gbafc gedafcb
facg aebfg ecfba bfaecd fbdge badcfeg cfgeba ega cadebg ag | fgca bdgef gafc acgf
dacefg eb bdecf acbfge ecb bfcda decgf cgdebaf cbfgde gbde | bdge ecbfgd feacbgd efdabcg
bd fbd bfcgde egbaf dafgceb cefgda fcbdae dfgeb gcdb cgfde | dfbceag bd fgbdec gdbfec
gbdacf dacebf adgfbe aedfb acgbedf eacf ca dac aedcb bedgc | ca cad fcbdaeg bdagcf
cbd egdba ebfdga efadc gcdfabe bc decbga dbaec gfbecd bcag | cdb egdba acbg acgb
eacb fdeab fgcade cbdaf dea cfebgda ae bdegf cebdaf fgdcab | ae facbdg bdfecga baec
cfd adbce cf bcdafg fcedb cbedfag fdgbe faegdb fceg gdcbef | fegc cf gfdabe adbcgf
gfbdeac efdgac gcfb edbagf cebda cafeb abf cgfeab bf gacfe | abfce cadefgb abf abfce
dcfge fabgec beg abdg gbaedcf gcdbe bg ebcad cfdaeb ebagcd | bgdaec gbe gb gb
aecb daefbg ebdfc aedfcg efbad cdgabfe cfgdb fdbeca ce cfe | fce ce aceb ec
gadebf fg fga acbgfe agbcd deabf bdagf cedbfa dbafceg dfeg | fg afg gaf fg
afed cdbge dag gabfe fagbde gadbcf adebg ad agfecb gedfabc | da geabf fgcbad gad
de gcdeaf agbcedf efacg gdcea efgacb edc fegd adcgb daecbf | edc ecd de dgceaf
becadgf edagfc fcg edbagf cg adfgcb dfega acgfe gecd bfeca | cgf cg gcde cg
cfaed agcedf db dfcbe bcd dbefca dcbgfa gbecf dcaegfb bdea | dagbcef bcd fegcb eabd
fcdagb ca aedfcgb fca gafbd abegfd afbcg fbgce aefcbd acdg | acf adcg efbgc ca
da dcefgba cdgef egcabf baed fagbcd fadbge dag faebg agedf | fcegab abde gad dbgfae
fbdec cdaeb dac dbage egca ecbdgaf debcga ca abdgfe dagcbf | efbcd adgefbc gbefacd ca
bfdecg dbaecg fcd bedaf fc dcbafg cegf fcdeb cbdfage bcdeg | egcf fbade cfd dbafgec
cg cadegb badfce gfdc agfbc cadbf egafb dbecfag cbg dagcbf | bagdcf fgcbda cbg dgcf
acgbf afbged fcadgb dcefg gebcaf ad adcb acdefbg cdgfa daf | dgcefab egbfacd gabefc cdab
dgb ecfbd fbgcd aegdbcf adcfg gfba gbaced acfgde fcabgd bg | dbg gb efdcb dbgcae
febg bcfaed efagdc fba ebafgc aecbgdf fegca bcgad bf acfbg | febgacd bfeg afb fb
adc ebdfacg ad badec efbdcg fade bcgdaf faedbc baecg cbfde | da edgbcf da edfa
afbgd agdcef dc cda bedcag cgaefb fdec cgfae fgadc deabgfc | cd cfage cedf fecd
facbe edcbf ebdgac fa dfgeac gaebc acf cfaegb dcfegba bfag | ebfac gcebad fac fa
cfebdag daecfb bg gecbdf ebagc ecagd gbe abfgec gabf ebfac | gbe afcbe gecdabf gb
bgefdca fecbgd ec bce cedab ecaf bdeafg cgbda dbaef bcfdae | bfecgd cefa fdeabc ce
gedbac cbade edfgbac gabfe cfaeb caf fc dcbf cdfbea cdefga | acf dafcbe cdfb dfabceg
cfgaed cbda abgfde cea abcdfeg adcgbe ac fcbge egdab eagbc | bcda ac ac ac
cbfaged afdgec ed fdea edcfg dce fdgac bfdagc fecbg ebcdga | fcabgd bfegc fcedag gfdabc
gafec afegb bgafed bafd fb egbda edbgac cedgfb ebf bedgfca | cgefbd bef edcgfb fb
cf gfc fecgd cebf dgecbaf faedgb afbgcd dcaeg efbdg dbcefg | fecb edfgcb ebgafd bfadgc
ea gafecd fbgac fcedb defcab fbeca bfdcge baed dabfceg fae | gbefcd ebda beda fae
afdgb acg aefdgc cebgd ac begdfac dacbfg gbcad abgfde cfab | abgdc abcf bacf ca
cdbga acedbg gefcd abdf fac af bfgaec ecfagdb gfdac bcdfag | caf bfad fa caf
edcagf feadg dab adgeb gceab dgfabc fdbe befcadg fagbed bd | dab dgabef dgebcaf bd
bga baedg abdc ab gefdb gadceb gcdae aedgcbf gcebaf cfdega | gab cdab dagcfeb dafebgc
afb eabdgf eafgcb gcdabe ecfa edbgfac fbdgc fa bacfg ceagb | cefa fab baf aebcgfd
da gdbcef facdeg dafbc efdcb adc edba gbcfa acdbef deafcbg | da ad defbgc ad
acbg ecbdg ecbgfda gdabec bg daefbc cefgd dceba dgb afebdg | bg edfcg gb efcgdab
dgbeca befcd gcfaed edgac agefcbd ceadb ba abe gcba daebgf | aeb acbg efgadc becgda
cgbafde ed bdce gde bdaegc eagbfd cgbad eadgc facbgd cgfae | gfdacbe fdegacb de deg
deacfbg afc dfcea cgaed gdbcea cf dcfg fbeacg gdfcae baedf | dbcaefg fdcg acgdebf gdfc
gca fagdbe cedbgaf dgbc gdaec badeg edafc gc abedcg afbgec | gac dgbae gdcb bgdc
cdfeab dbcfa bdg bg fgbc adcgb gdfeab ecgbdfa gdeca cfadgb | bedgacf acbdfg gdb bg
gbfec bgfde gacedb fcgea cb cgeafd bcg aebgcf gdaebcf afbc | cafbge abfc adbgfec bcg
edgf bcgef edcgfb gfcabd fbdcae ef efc acebg gcbdfea fgcdb | fdge fe dabcfg aefdcb
cdbafge agdebc bcg dfbgac cged ebagd degafb bfcea gc caegb | bcg edbga fcgdab debga
ea dagfbe fae fcdgbe gfaecbd decfb dacbfe abec gdafc caedf | defcba ebgdafc ceab gbcafde
dg cefga bfaed fdecgb bdag bdaecfg fgedab edg adfecb efdag | dgab gfcae bedgfc cgfdeab
degcfb bdcfg edgb cdfab bcadgef fgcdea gdf becfg dg egfbca | gd ceabgfd efcbagd bedg
dfbg bcgeda faecdg dab bfaec dbegacf geafd eabfd agbfde db | dab adfegbc db bd
ecfagdb db gadecb dagfb caefgb gbd fbeag facgd bdfe efadgb | bfedagc db dgb cagfd
edbcga fcdgbe ebcdg bcfage fb bfcgd bgf gcdaf bgfcdea fbde | dgcbf fbg gbf fdgcb
efagd eb dafcgb ebfad eabdgcf cbed aecfbd egbcfa feb adcbf | be eb eb bfe
bdge fdabce begfcd gcbdf bd ebfgc fadcg dagecbf dfb bcafge | gfacd dbf bgcaedf dgfca
geacf cfb gbfcde dfbga bc fbadgce fgdcba cabgf fdaegb dacb | dfagcb cafdebg acfbdg fcdgeba
fecdbg gbcaf ebgacfd acgfed gbad gb fbaec afcgd bafdcg fgb | gcbefd egfdbc fgb fgb
fdce ebagf fdcegb fgacbd dcbeg geadbc cf gebcf gabefdc cbf | edfc cfdgab decbg fc
adcfeg cfgad efgcdba fecda fec gabcdf ef bacde bfdceg gefa | ef edafc ef fgcdab
afeb fbegd daefg agdbcfe agdcf ega adbegc dbgafe efcdbg ae | abedcg efbgcd fgcad cdegba
fdegbca gefbda egbf dbagc gfd bgdaf adgfec fg bfead dfceab | fdg abcdegf gadebf decfgba
dbcaef debfgc gfebdca bcaed ad baceg dca deaf edfbc dagcfb | acd dafe fbdecg adef
beadc fc faedc dbafeg gdfea gafc fegcad cgebadf dfgbec fcd | cdf deacgf gefda cf
fdaceg edgacb dbcg cda cd ebfad acbeg gdfbace dbaec bcfeag | deabf bcgd cdgb defgca
fgcebd dgbcae bfcgad ga bga bfcgd gbfda acfg dbafe fbcgead | bedcgf dbfgc gfac acfbgd
cfaebdg dcg gedbfc gefdba egafcd dc cbde bedfg bcgdf cabgf | dbacfeg feadgb dcbgf fbgdae
fagcbd fedbg fcabge ebgad cbfdg cfedgab feb fdce dfcgeb ef | cfde fgedb bdgecf ef
becgdf efcbda cgbd gdcfe gc gaedf efbcd cfg fbegcad gbfcae | fcg cdefbg gafed efadg
da adbcgef dacf eadfcb bfcage eafbc ceabd begfda bdceg bda | da da acbedf bagcfe
agebf adfb fabedg cgafde dga beadfcg cdbeg egbad cfabeg da | dfegba dafgbce egdbc fecbdga
eac fcdabeg gdabc ebadc bcge gfecad deafb bdgfac dgaecb ce | cea ec cegabdf gadcb
gfedbc gcdfb ecdfga df cfegba defb dbcga gdf cgfbead ecgbf | facbged dfg bfed cfbedag
agbde bgdfca deacgb agbef aebcgdf afg fbecg aedbfg afed af | daef fga fga gdefab
gfbac gaecdb baefc fdebgca fgbadc ec adbef efgc fabegc cea | cae eac gfdcbea fceg
ec dagbc cagfbd adbecg bfdge gebcdaf ced gdebc fagced bcea | gdbeca dec agcdb aebc
geab ebgdfa eafbd dafbc efdgb aed ae bgcaefd dcegfb aegdcf | ebga ade ebfdg dgafceb
bdaeg aebcd cgebad dbc cb fecbgd dafce bcgfdea gcab gfdbae | cbga cbag cdb bagc
dfb egfbdc ceabdfg cfbae fgbade fdbec bd gedfc deafgc cbdg | ebfgdca fdgbec caebdgf db
dfcaeg bagcefd fceab ad dae faedb fcabed ebfgd fcabeg adcb | dea ad ebgfd da
afgcd acgebf da agbdfc cad gcdfe dagb dafbec dagbefc abcgf | fgcde beagcfd cebafg da
cabd bce cb cfbdea adbef agcfbe aebcdfg fabdeg dgcfe fbdec | ebc gfcabe egcfd fedab
efcbga cgfbaed bcfga ecgbf egdbc deabfc fdgcba fage fce ef | ecgbdaf gdecabf bdceg febcga
gbcda ad gacfb dba gfacbd fbgdeca aecbfg fdac gfabde bdgce | dab bdgafce bcegd abegdfc
fcaegb baegdf gfaced gedfa dcebg dbgea agedcbf abdf bga ba | bag fabd bgfcea bga
ebafg gdebafc gedacb gcdefb agbdfc cf gebcd gcf cfde cgbfe | fdgaecb dfbcega cfg fc
fce cbaedf cgbaedf ec bfega dcea agbdfc bfdegc dacbf cefab | ce efabg faebcd gdecbaf
dcfbg fd egcdba efcgb bfad cefagd abegdfc gcafdb cabgd fdg | bafd egfbc cdgabf gfebc
abfegc gecdabf cedb bdg dgcbf gaebdf db fgacd ecfgb egcfdb | bdegaf gfaebd gcefb cdbe
bafeg febdac ged bfcedg gd cbafedg edcaf gafdce cagd fadge | fgcdae daebgcf dagc fadeg
cfdegb efdc gcadbe gdbaf ebadgfc fc gdebc dfcgb fgc egcbaf | fc cf cfed cf
aecfgd efgab bdagfc cedf cge agfce afcdg cdeabg dgbaefc ec | gce gce ec cegfadb
eagdbc ga fecbda ecdaf fdgbc abgdcef afdcg fega cag eafgdc | cga ag ag ag
fabedg cedg cbefga dga gacedf gd fdcga afecg bfdac gabfedc | fgeca gdec fdacg gda
begadc gcfeab dgcba defbac gc fbdag agdebcf degc cag abecd | gcde gca cdge cg
fd dcgba gdbfca afedcgb gbadef cagfe fad dfcb acgfd dacgeb | cbgdea fd cfdb afegbdc
fb fceab fdeb bgfaced acdfbe gbcafd cdabe abf agcef baecdg | bf fb gdebac bf
df fdb egcbd gfed bcaegd abcfg ceadbf egcdbf aegfdcb dbgfc | begdac fdb acefbd dgbec
bgedfa dg bdcgeaf cbfad decg efcdga aecgfb aegcf cgdfa gad | egfac dg gedc dga
gadfe cfgead cdgbae cfage de dbceagf ecgafb cfed dea fgbad | ade fecag aefgc fcagbed
dfab gaecbd degfc bcegfa dgebfa edb ebdfg dbceagf gafeb bd | gbaef bafd agcfbe bfcadeg
edcbg dgbfc bdfecag cfegbd eg gebfda dcaeb afcdgb cgef ebg | fceabdg gdfbec beg fdbgc
ba gfbdec gacfd bfcdae caeb egbfacd cbedf edabgf bad cadbf | becfdg aecb bad efgcdb
gba dabgfec ga fbadc dafgcb fdabg dbecaf agfceb cdag bfegd | dfeabc gab gfabd abg
abgdf gcabfd cgabde agedfcb ab cegfda dbfeg afcgd acfb gba | bcfa dgefca dfcagb ba
bdecf dgebfc bgcd fdgae gec cg gbacef bacefd cgedf afbecgd | abegfc egfcd cg gbedafc
gdecbfa cd bfcagd fagec dfcae dcf adgcfe eabfd cdge gcbeaf | cd dfc dcf gcfbae
fdecb adfce bc ecagbd bdc facgedb bfac fbged egdacf fcadbe | daefc efcgda bcd dagcfeb
fgdba fbae bcafedg dfgebc fag cbgad gedacf gdfeb fbdage fa | dbfag fdbeacg bgedaf bfae
dafbg abfed fe eaf degbca fegabc bafdec dcef aedbc afdcegb | fe fe ebfcag dacgefb
adcegb cf dceab caef ebgadfc dcabfe cbdfe fbc degbf gbdfca | cf afce aecgdb cf
cebdfag acfgbd gcbef bcf dfegc bf egacfd bfde gbfdec abceg | dbef cbf cfgde cbf
bgfaedc gcdfb cadbge fdac bgfdac cf eabfgc bfc acdbg fgbed | cafd fbdagc bdgac cf
fgdc fgceab edf feadg beadfc bdgae egdcfba efagc fd cdagef | fed gfdcaeb cgaef fedgca
bfg ecabg cabdgfe fdgc fgbac dafbge gf fcdbag fadcbe fdcab | bdagecf fgbdaec fdcgeab fg
aefdgb agcfe dfeca dgecfa feg deabgfc ge gacfb defabc dceg | efg edfca egf aefcdg
afbeg fagd adgfbe abefcdg bdefca ga gab ecdgab abefd bgfce | fgad fdag dgcbeaf ga
fbgea ebfgdca badegc bac cb gceba eadcgf daegc gcdafb bedc | cgbdefa bc bc dabecgf
cfbega dgba gb fbegd gdeabf bfcadeg egdcf fgb badef fdbaec | gadb facbdge cfgdbae eadbf
gdecaf fabed bdgcae dcgfba ce bdfegca dcaeb gbcda cae ebgc | afdgce dcbegfa egdcfba bgfcad
bcgdfa cda agecfdb cedba cafdeb caefbg abfec edcf debag cd | cda cda dc ecabd
fdbagce abfc cageb cagfe eba gadefc dgcbe adebgf geafbc ab | ab edbagf afbc facb
gcdfa cadeg dcaeb adcegf gfcdba fcabgde ge gfed gea gfeacb | cadgf gae dagfbc gfed
bfegdac gcabf fdg adgfb gefdcb gd abfed gdae dfgbae befacd | dega bfgdec dfg daefbg
acebgd ceg gcabd afcbgde ebcd afbdcg cbgea ec gbfae gdfeac | gce afbeg adcgb abedcgf
degfab fbade ac acdf feacb dgcbea cfbge abc dgfaecb bdecfa | adfc cdaebg ca acb
adegcfb gf acfdbe ecfdb dgceaf dgfbe dgbae feg fcbg dfcbge | gf fg fg gf
fbacde gfacbe eg dcge fdbga beg bedgcf dcbef fcbaedg bgfde | cged edcg bgedf ge
dgafc dfbegc fagbed cfba adfbcg cfg cf dabfg gafcdbe dgaec | dgbface fcgad cfg fadgc
defcga gdfc afc cadebf bceag degaf fc gaedfb dabcgfe eagfc | adfge dgfc edcfab fgcd
dcefb feb gcdeb efdg fcagbe becgad bfcda gabfdec fe ebfdgc | ecbagf ef dfge decbf
fgebac faegb gcebfad fb fecga bgf ecbf abged gcefad fbgacd | fb fbeag fbega bfg
cbdgfae fbe gdfbce egbda abedf cdfea badcge agfb edbafg fb | ebfad afbg edafbg efb
gbdc gb cfdegba bdgae gab gcafbe fadeb ecfgda gbdace cgaed | abg dbgc dcbg gb
db dgefb eafdbgc ecfbg bcegdf bdg fbcd gefad ecfbag adbgce | db cabedgf dbg fgead
ab bcfa bacfed dba befad fadeg bcdaeg abcgdfe bdecfg bcfde | ba debacfg fdcbe abd
baecfg edgba cdgae fced cd egfdca cgd acedfgb dbfgca feagc | adceg dcaeg efdc dc
cdb bgfeda acdeb becfda fedba dfca gbeca dbgecf dc aedcfbg | bdc egabfd cd eadbc
efgcadb dgebf baedf gcedfa bfg gb eacgbf dgefc bdcg cgbfde | dfgbe gb gbdefca dbcg
afebdgc gbfdc gbca defgb cdb bc bcfagd bcdfae edfgca fdacg | cbd cgab dfbgc cb
bgfade cdgabef cfebd ce febad dgafce dce abce cgbdf edcafb | bfeadg gdfbea cabe ce
gefbcd de dgfce gfdaecb gafec bfdcg bdge abdfgc edf dfbcea | ed fcdgab dfe edgb
cgafeb egadbc bagce gedcafb afcbd fgae bfeac fdegbc feb fe | egcba bfe bef bcdaf
bcdea dgbfc gdae dabcg ecdfab gca ag dcebgaf gadecb beafcg | eagd eadg bfgcd gac
gafcb eba acbfeg cagbfd ecaf fcbedag bdcge ea cagbe fdeabg | bea aeb ae eab
cdegfb cdagef bgf dfgcaeb eadgb fegac febga bf bfcaeg cfba | caefdgb gfb fb ebafgcd
bgedfa dfbca ebdgcf fbgcd dfcega cgf gfbcead degfb ecbg gc | gecb cfg cg aegdfb
agebd bcegda aeg fedabc bdgafce acgd fbgde ag caegbf cbdae | agcd egabfc dacg dgca
cbdfe feacd geacfd dbaefg cbgfd aedfbc ceba eb bde egacfdb | bed ceba adbefgc ebd
egd ge afcbedg bfgeda bdgefc gbce bcgdf fdacbg aecfd dcgfe | cefgbd afcbgd ge cebg
bg gacbe cefgad cbgf cbead gba fcedagb ebdafg gcfbae gacfe | gabec cedfgab acgefb dgecabf
afedg edabg fcdg bfcega ebfdca decaf gf gfa acegfbd afedcg | dgcf efacgdb dcgf ebdfcag

Day 09: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

input1.txt
2199943210
3987894921
9856789892
8767896789
9899965678
package.json
{
  "name": "aoc2021",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "main": "ts-node main.ts"
  },
  "author": "Christoph Jobmann <christoph.jobmann@deutschebahn.com>",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^16.11.12",
    "typescript": "^4.5.2"
  },
  "dependencies": {
    "ts-node": "^10.4.0",
    "tslint": "^5.20.1",
    "typescript": "^3.9.10"
  }
}
read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
main.ts
// Day 9: Smoke Basin
// Solution by Christoph Jobmann

import { RiskEvaluator } from "./riskEvaluator";

const re = new RiskEvaluator();

const highRisk = re.getHighRiskValues();
console.log(highRisk.reduce((s, v) => s + v, 0));

const basins = re.getBasins();
basins.sort((a, b) => b - a);
console.log(basins.slice(0, 3).reduce((p, v) => p * v, 1));
riskEvaluator.ts
import * as r from './read';

export class RiskEvaluator {
    private heightMap: number[][] = [];

    constructor() {
        const lines = r.readLines('input.txt', '');
        this.heightMap = lines.map(l => l.split('').map(s => parseInt(s)));
    }

    /**
     * Recovers the values of high risk.
     * @returns High risk values.
     */
    public getHighRiskValues() : number[] {
        const locs = this.getHighRiskLocations();

        return locs.map(l => 1 + this.heightMap[l[0]][l[1]]);
    }

    /**
     * Gets the sizes of the individual basins, extending from a low point.
     * @returns Sizes of basins.
     */
    public getBasins() : number[] {
        let result: number[] = [];
        const lowPoints = this.getHighRiskLocations();

        for (let origin of lowPoints) {

            let seen: number[][] = [];
            let basin = [origin];
            let unexplored = basin.slice(0);

            do {
                unexplored = this.tryExtendBasin(basin, unexplored, seen);
            }
            while (unexplored.length > 0);

            result.push(basin.length);
        }

        return result;
    }

    private getHighRiskLocations(): number[][] {
        let result: number[][] = [];
        for (let row = 0; row < this.heightMap.length; ++row) {
            const rowData = this.heightMap[row];
            for (let col = 0; col < rowData.length; ++col) {
                const v = rowData[col];
                if (this.calcRisk(v, row - 1, col)
                    && this.calcRisk(v, row, col - 1)
                    && this.calcRisk(v, row + 1, col)
                    && this.calcRisk(v, row, col + 1)) {
                    result.push([row, col]);
                }
            }
        }

        return result;

    }

    private tryExtendBasin(basin: number[][], unexplored: number[][], seen: number[][]) : number[][] {
        let nextUnexplored: number[][] = [];

        for (let point of unexplored) {
            if (!seen.some(b => b[0] == point[0] && b[1] == point[1])) {
                const v = this.heightMap[point[0]][point[1]];
                this.tryExtendBasinStep(basin, nextUnexplored, v, point[0] - 1, point[1]);
                this.tryExtendBasinStep(basin, nextUnexplored, v, point[0] + 1, point[1]);
                this.tryExtendBasinStep(basin, nextUnexplored, v, point[0], point[1] - 1);
                this.tryExtendBasinStep(basin, nextUnexplored, v, point[0], point[1] + 1);
                seen.push(point);
            }
        }

        return nextUnexplored;
    }

    private tryExtendBasinStep(basin: number[][], nextUnexplored: number[][], v: number, r: number, c: number) {

        if (r >= 0 && r <= this.heightMap.length - 1 && c >= 0 && c <= this.heightMap[r].length - 1) {
            if (this.heightMap[r][c] < 9 && v <= this.heightMap[r][c] && !basin.includes([r,c])) {

                if (basin.some(b => b[0] == r && b[1] == c)) {
                }
                else {
                    basin.push([r, c]);
                }

                nextUnexplored.push([r, c]);
            }
        }
    }

    private calcRisk(v: number, r: number, c: number): boolean {
        if (r >= 0 && r <= this.heightMap.length - 1 && c >= 0 && c <= this.heightMap[r].length - 1) {
            return v < this.heightMap[r][c];
        }

        return true;
    }
}
tsconfig.json
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "baseUrl": "./",
    "paths": {
      "*": ["./dist"]
    },
    "typeRoots": ["node_modules/@types", "src/types"],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": []
}
input.txt
5456789349886456890123985435578996543213456789656899996467789234989765442345789778999989652349879899
4349891298765348789339875323456789665434568996545698874356679959879898321457893569998879931998765668
1298910989873234595498764312345678976746899989656987563234567899767987442578954678987968899897654457
2987939875432123489999953201234599698657979979997965432023479998959876553689965789876856789789543345
9896899984321012668899865313546789569798965469879876553135568987643988767997896898765945697698722256
8765789965442143456789996579658895434999876398767987864589679876542099898966789999833123598589810123
9954629876553234667899987988767932129899989219755398878678989987943989959355678998921057987678924345
6543212989654345788999898999998941098789998998543229989789797999899876543134989997632345698789545456
8654543498765476899398759126679953997678987987632101297997656798678965432015699876546559989898756567
8767654579879989943297642014567899889567896597543223456789348976578976543126921998758698979999768979
9988765678998999765965432123789998765456997498654345789893219865458897654434890139769987867896979989
9899876989987899899876843234891249654369889329765567899994325976346789887565789349898765756975395699
8767987899876999997987755346910198773235679939876688989875634987497893999679899959999654248954234799
9653299999875789986599896467899987652134567899999789879876786798998932398789999898998643135932129978
8632102398764578965434987578978698743028979989998998866987899899989510129999987797987659239891098769
6543223987643589874323498678965469764167899878987897654398999989876431236789876576898798998789989756
7654564597532599993214998789975379894356899865476789762129789879876543345699765455789987684569877546
8799796798543489874109899899876123989456989874345678995345698765987876596998954314597998593498766434
9989987987654678965929799999993239979569876543234589986797987653298989989897895423456987432987655325
9876898998779899899898589998754998768998765432107678999989298942139599879766889435668986543498943212
9785799659989956798767467899769878657889877543234789998979109893013498765455679546899598665569954323
9654588949893245697654356999898767345678987698645679876767998782129987654343568958912459988798766534
7543567998732196899793234789999543236789699798759798765656897643298799973212389979101967999899887646
6432457898653989932989345699987684545893568999868979874545989654349698764324567899999899767999998787
7421348999769878949878996789999876657932378999979657953435679876598539875634689979876798657789429898
3210128799898767956965989899987988867891234989989345942124789998987621986875678967965987545679945929
4323235678923456899854567978976799978910349878991249873675678989798710197987989459893296534567896912
5454348789636567989765878967965456989321398767890956954578789977679821298998994299794987321457999899
7689656896547678979896989549876567895432999656799897967789897855569932459019865987689876432346899768
9798798998658999867998996432987678999549899245698689879892996743498643567999989876530998546456796547
9899899139769643456999876545698789598998778967789542989954985432129754979789997987421987698578899656
3956921019898752147898987676789993497987668989899901299875976593939878998668946799532398799989998997
2345892345999864234987698787896432986543445899999892989989987989899999976557899987643469896799997989
1016795469899975695995429898999999995432036789987799767898999879789998764345998987654567965678986879
2525679579789986989876210989878878986544125679986678956967999765678999855235687899768789654379875668
3434567989678999879998329876756569876543234589765459548456898764567899932123456969899997543268994345
7566798998989239868965498995435457987764547678955347932345679876689999899015897954966989875346789656
9789899867992198957896597954321349999975656889543136793656789997799975768976788963245976996657898769
9899997656893987645789986896440497898896787897665945679778997598899854356898899995139895987767899878
8989876545679998435699875789559976786797898998779897899899995439998765456999999989298784598998996999
7879987934567954324987654668998765345689959689898799910999989323689878767892198778997653239569985321
6567899895678965439876523456987643286789244567999667899989878934569989978999987667998732123489876432
5434998799789877598965412355698321098992153456796543498868767957878999999398799456789541025678997643
3129899678995998997894301234899532136789012568986432987659756899989999893298654345897632125989898856
4598797587894359876894213568998754245989193467965421098643237923499989789139885457998784534898759878
5999675466789299875689428689549895345678989979876533498754346935999767679099976868959987656789943989
9876543245699987654578938795430976467989667899998754579865467899898654568989899979249898767899899993
9985432125789998743567899894321987598992556998879867678987568998789843499876788989198779898989798921
7898743014569879852456789965939798679321349876765978789998979987679921989795667891098655999876567893
6987653123698765920378898979896549789210199765654989899979989875568999876654456789297643498765456989
9998754534899994321234567898789329895321987654323499998765698784459679765443234678989931019874359878
8979986785678987435345679987679434976433499876212578987644597643274598754320123799767892398765699967
7768997896789876587486889898569555986545689974323459954323998932123459866541234598756789469886987856
6456798987893987697578998766478976797969789865464567893219876543235579877532346689347898579998986543
4347899999932398798678998754367898899898993976789679987623998995468678998546456789456987678979897421
5456987891291999899989659765456789989697894987898799876534569989579789979798767897567898989469653210
7567896790989899956796539878677899978576989998999893989545698878998996869899878998678999993298964523
8879935789876788932986424989789999867485678899987932395987987659497895456989989659799899989987895634
9989323498765567891093212399899998754334799789876421034599997545376994345679896543986789876766989745
6695214998854458989989923569979876543212345698765432123498898434265679266989689959875698765454878957
4594349876543234568979894698667987656101356789876743649987654320124589356789567898764329954343459998
2987656987435156679965789987546499797219459899998654997698965434245678967892459929873219543212368999
1099878994321067789874689876432345989498968978998789876569876554356789988921378910989398654563567897
2178989965442128999943599984321259878987899567889898765459989866457891299543467899898989765687679956
4569399879674236789732398743210198767466789335678999654378999878968954397664578998787779876998789632
6891239998787645897653987654323987654345679126799198796459998989879765989876789999676567987899996543
7920198769898657998764598765459876543234678938894349986567897692999979975987998987543456798998987655
8941987654998789729978689876599987532145678956976499987778976543978898943299987976532102679987698786
9659998543239897539989798987989976541013799767898989898989987999865767892109876598799993568976539987
9998987654357999998599897899879997663123478988999875679297599789754456793298997329987889979765423498
7767899765468998897432986798768989893234567899698764799198988678963345989987789419876776898976434579
6756789976979767796521095679946679964545678924569953898999876567892259869876678923995665987897545678
5345999898989745689432194599834569875657899535679831987894324456891098754324567899874354556789696989
3234998789497659996543986987612346989798999947799762986543212367952169765913478998765212345678987891
0199879695398798789674987965401656999899587899987653987655423478943459899894589998754303456789698910
1987654569219899678995699876213457899945456989999768998766545678986567998789678999865412567896599932
2398543458901987567989789984345569989631345678999899469898758789997679989698999989986543456789387893
3987654567899895456778999995668979876520234567896952399969969898898798778456789976597654568895456794
4598897678998754234567899876779989987431345778995431989459878976789989656345467894398767678998768989
7679998789329895345978953987889296796532459889889549879321989345899876543234349943209879789899979978
9796999899902976567889992198999345986545669994679698767990993276799989854101247895499989896789898765
9895789999893597678999989239998456797676778933468987657789894387989998768212356976989998965899765754
3934598998789698789999878956987568998987889012457896545698765498978999978326979899678987654987654323
2123567997688999899898767999998678979998993233468993234569976999869899989545998787567899543499843212
3234979783467899998789956678999989568989654354569689156789989897456789987659898645456789532398765301
4569898672456789987695434599789995479679765457689589235679998756345679998798786534345789643999876412
5698765421345698768459996789589954234569879878797678946899987643234568979897654323245689659876986433
8789876510124569654347789993467893199979989989998789757998998743123458954999843210156799998765498764
9998765421267898542125678975678999987898793296789899867987689854234567893598764321277899899654359875
9329878632358987651014567896989998976799532135678999978976534965446789932349875432348998798765667986
8912998793479199432123678998999876565987673234567998989986549876767899953456986546556795659976889997
7894989895589298753234899769235965434598765345688997899987656998898998764567898657867954345989998998
6789976986678999954745678952139876512349998656899876569898967989989689877698949768978985466996567899
5689895499899888895677789543025987829467899767998775466789989879976578999789429899989876877895456789
4578789357998767797799998765434598998998999878989654345678999967896469989993210967999987998954345678
3435689467997655689899899879545679997889997999678921234589997656789359879879921256789798999543257789
2324579569889834578965789998976899876679876544567892346899986545992198765767893345997569987654568999
1012459698779323569954678967997987764589997432378965467999987956893987654556789457896456999765678967
2123468987656313467893212356789996543678986543567899578998898768954998643544579968998345899976899456
3654567896543202348932104567899987654569999864568998679997649879869876542123567899765456789987893237

Day 10: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

package.json
{
  "name": "aoc2021",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "main": "ts-node main.ts"
  },
  "author": "Christoph Jobmann <christoph.jobmann@deutschebahn.com>",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^16.11.12",
    "typescript": "^4.5.2"
  },
  "dependencies": {
    "ts-node": "^10.4.0",
    "tslint": "^5.20.1",
    "typescript": "^3.9.10"
  }
}
syntaxChecker.ts
import * as r from './read';

export class SyntaxChecker {
    private tokens: string[][] = [
        ['(',')'],
        ['[',']'],
        ['{','}'],
        ['<','>']
    ];

    private score: Map<string, number>;

    private completionScoreOrder = this.tokens.map(t => t[1]);

    private lines: string[];

    constructor() {
        this.score = new Map<string, number>();
        this.score.set(')', 3);
        this.score.set(']', 57);
        this.score.set('}', 1197);
        this.score.set('>', 25137);

        this.lines = r.readLines('input.txt', '');
    }

    /**
     * Gets the error scores for the given lines.
     * @returns Error scores.
     */
    public getErrorScores() : number[] {
        let result: number[] = [];

        result = this.lines.map(l => this.getErrorScore(l));

        return result;
    }

    /**
     * Gets the median completion score.
     * @returns median completion score.
     */
    public getMiddleCompletionScore() : number {
        let cscores = this.getCompletionScores();
        cscores.sort((a, b) => a - b);

        const middleIndex = (cscores.length - 1) / 2;
        return cscores[middleIndex];
    }

    private getCompletionScores() : number[] {
        return this.filterToIncomplete().map(l => this.getCompletionScore(l));
    }

    private getCompletionScore(line: string) : number {
        let remain: string[] = [];

        this.process(line.split(''), remain);

        remain.reverse();
        let completingTokens = remain.map(i => this.findCompleting(i));
        return completingTokens.reduce((p, v) => p * 5 + (this.completionScoreOrder.indexOf(v) + 1), 0);
    }

    private findCompleting(s: string) : string {
        return this.tokens.filter(t => t[0] == s).map(t => t[1])[0];
    }

    private filterToIncomplete() : string[] {
        return this.lines.filter(l => this.getErrorScore(l) == 0);
    }

    private process(remain: string[], started: string[]) : string {

        while (remain.length > 0) {
            let char = remain.shift() as string;
            if (this.tokens.some(t => t[0] == char)) {
                started.push(char);
            }
            else {
                let last = started.pop() as string;
                const expectedCompleting = this.findCompleting(last);
                if (expectedCompleting != char) {
                    return char;
                }
            }
        }

        return '';
    }

    private getErrorScore(line: string) : number {
        let errorChar = this.process(line.split(''), []);
        let result = this.score.get(errorChar);
        return result || 0;
    }
}
read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
main.ts
// Day 10: Syntax Scoring
// Solution by Christoph Jobmann

import { SyntaxChecker } from "./syntaxChecker";

let checker = new SyntaxChecker();
const scores = checker.getErrorScores();
console.log(scores.reduce((sum, v) => sum + v, 0));

console.log(checker.getMiddleCompletionScore());
tsconfig.json
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "baseUrl": "./",
    "paths": {
      "*": ["./dist"]
    },
    "typeRoots": ["node_modules/@types", "src/types"],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": []
}
input.txt
[{<(<[<<(<{[[<[]{}><()[]>]]<(([]<>)<(){}>)({[]{}}([]()))>}>{{{<(()<>)[[]()]><(<>())[[]<>]>}{({()
<<[{([[{{[[[({()()}[<>[]]){<<>[]>([]<>)}]{[{{}{}}<{}{}>]{{[]<>}{[]{}}}}][{{{(){}}<<>[]>}}]]}{
([<{([<[([({[{[]{}}{{}{}}]}{[{<>{}}{(){}}]})[{[[(){}][(){}]]{<<>[]}{{}[]}}}]])]><({{{[[{{}{}}]<{<>
{{((<([<[<[((<{}>{()()})<[{}[]]{<>{}}>)<({[]{}}([][])){{[]<>}{{}<>}}>]>]><[[[[[<<>()>(()[])](<[][]>{<>{}}
{[[<[[((<[{{<[[]{}](()[])>}{<({}[])[[]<>]>}}{[(<()()><()>)({[]()}[<>()>)]}]((<{[<>[]]{{}()}}>[{<()<>>{[]
({{((<[{{{([{[(){}][<>]}([<>()][[]()])]{<{{}<>}<{}<>>>{{()[]}{()()}}})<<[(<><>)<[]()>][((){}){[]{}}]>>}}
{<(<{[[([[(<[(<>[])]<{()}<()[]>>><{<{}[]><[]>}(<<>{}><()()>)>)]]{((({{<><>}{{}{}}}{<[]()><{}<>>})<[{(
<[{(<{<((<(<{(<>{})}<<[]>(<>{})>>){{(<()[]>[[]<>])}[{[[][]]<<>()>}{[{}()]<(){}>}]}>{(((<<>
(<[{[<((((<[[[{}{}]{{}<>}]({[][]}[(){}])][{(<>[])<[]<>>}<[(){}]>]>)))<({{[<([]<>)<()<>>>[{
{{<<[<({[{([(<[][]>{[][]})<<<>[]>([]())>])[(<<[]<>>[{}()]>{([]{})})]}](<[<(<<>[]>)>{(<[]{}>[<>[]])<<[]()>((
[[[{<{[[[([[<<<>>[{}()]}[({}[])<()<>>]]]{<<<[]{}>[<>[]]><{[]<>}{[]{}}>>{(<{}{}>{<><>})({[]()}{{}<>})}})]<<<[(
(({([<{{{{<<<({}())[()<>]>{[[]()][()[]}}>>}<({({{}<>}[[]{}])(({}{}){()()})}{[(<>{}){<>{}}]{[<>[]]({}<>)}})>}(
{(([{(([<[{(<{[]<>}<()<>>>[([]{}}(<>{})])}({[<<>[]><<>{}>]}<[<()[]>[<>{}]]{<()<>>{(){}}}>)]>([<((<{}()>
({{<{{{{{{({<{<>{}}>(<<>[]>[[][]])})]{[{{{(){}}[()<>]}<[<>][[]{}]>}{[<{}<>>{<>}]{{[]{}}(<>{})
{{(([{([{([<([[]{}]{<>[]})>{(((){})[()()]){{{}<>]<()()>}}])(({{{<>{}}{[]{}}}[((){})[<>]]}<{(()[])[
{<[((<<(([{{<{[][]}>{[()<>]{()[]}}}}]))<<((<[<[][]>[[]()]][({}){[]<>}]>))>>>>))<(<<([<<[{<<><>>[(
[([[(<([(({<([{}][<>[]]){<{}{}><{}[]>}>(<({}[])>(<()()>))}{[[{{}()}{<><>}][{()[]}<()()>]>[{<<><>>{
[{[<{(<[([[[{[{}<>]({}())}(<<>>[[]<>])]{({<>()}{()()}){{[]()>{[]()}}}]]{[[{({}()){[][]}}((<><>))][[
<{(<[<<<{{[{{<{}<>>[[]<>]}[{()<>}[()<>]]}{[{{}[]}{()}]{<[]<>>([][])}}]({[[{}]{()<>}](({}{}))}>}{<[<({}()){()
<(<[<([({[<([<[]{}>{[]<>}]{{[]{}}{{}{}}})<<{()<>}({}{})><<[]()>{()<>]>>>(([{[]()}({}())]([[]()]<{}()>))
{[<<([[<([<<(<[]<>>){<<>()>(<><>)}><<{<><>}[{}[]]>([{}()])>>])>][{({[<<[<>]{<>()}>><<[<>()]{{
<<<[<<{[<<(({<{}<>>{{}<>}}[<[]<>>({}[])]))><{{<[[]()][(){}]><{{}()}(<>)>}[((<>{})(()<>))<[(){}][[][]]>]>>>]}
(([{{[{{<<{{[({}<>)(<>{})](<(){}><{}{}))}}([{({}())<<><>>}{<(){}>}]{{[{}{}]{(){}}}<([]<>){()()}>})
({{([{{({[{<<({}[])(()[])>[{{}()}[{}{}]]><<{()<>}{{}}>>}<[((()<>)([]{}))[{()()}(()<>)]]{[{(){}}{()
<[<{<[{({(([((<>{}){()[]}){{{}{}}{[]<>}}]{{({}<>)<{}[]>}<(()<>}(()[])>}))(<{({<><>}[[]()])<[{}()](
[[{[({{<{{{{[<<>[]]({}{})]<([]{})(<>{})>}{{({}{})[{}{}]}{<<>[]><{}>}}}{<(<<>[]>{{}{}})[(()<
[([(<{{[<[{[<(<>())<[]()>>{{{}}<[][]>}][[{[][]}<{}[]>]({{}()}[[][]])]}{{{<{}{}><{}<>>}{[()[]]<()[]>}}<<{[]{}}
[[(((({<<[<<({{}()}){<()()><<>[]>}>{((<><>)({}())){<[]{}><()[]>}}><[{<{}>}({{}{}}[<>()])]{{({}{})}[<
((<<[{{[[([[<[{}()]((){})>[{()[]}<<>{}>]]([<{}()>][{{}[]}[()]])]{({[()()][[]()]}(((){}){{}{}}))[{(<>())}
{[[<{<{[{{[(<<<>[]>([]())>{(()[])[<>{}]}){<(<>())(<>{})>{<[]<>>[{}[]]}}]({<<<>[]><{}()>>([[][]])}<[<{
[(<[<{<[([[{{{<>[]}[[]{}]>({[][]}[[][]])}{[(<>[])[[]]]({()()}({}[]))}]])<[<<<{<>{}}{[][]}>((()){()<>})>>
({<[<<[{[<({<{{}{}}{<>[]}>{{()}{[]<>}}}[<[{}<>][()[]]>])((<([]())((){})><[(){}]{{}()}>)[{<[]{}>[{}{}]}[
<[[([([(<(<[[(()[])]{[[]<>]({}{})}]>)>[<[{<<<>()>({}{})><([][])<{}{}>>}<([()[]]<(){}>)[([]{})[{}<>]]>]><[{({
[<{([([(<{<<{[()[]][()}}<<{}{}>>><<{[]<>}((){})>[{[]()}]>>}[(({{<>[]}[<>()]}<({}{})[{}[]]>)<[{<>{}}([][])
[<{([((<{({{[<<>()>{[]{}}](<[]()>[{}{}])}})(<{([<>()]{[][]})[{{}()}]}<((()[])(())){([]<>)([]<>)}>>{((({}()){
((<{{{<<[[<[[{[]<>}<{}[]>]<<(){}><<>>>]<<[[][]>[[][]]>{{<><>}{[]{}}}>>{{{{<>[]}{<>{}}}[[[]<>]<{
[<<[{[<({[[{{{{}[]}[<><>]}{<<>[]>[{}[]]}}<<(()[])[<>()]>[[<>{}]]>]]}{<({<([]())(<>())>[[{}[]][<>{}]]}){([
([<{({({{<[({(<><>){(){}}}<{[]{}}{[]())>)({<(){}>[<>[]]})]<[([{}{}]<{}[]>)[[()[]]]]{[{{}<>}]<(()<>)
[([{<{<{(<<(({[]{}}({}()))){{(<>())(<><>)}(([]{})<{}[]>)}><[<[{}{}]({}{})>]{[<[]()>(<>{})]<({}()
((<{[(<<[([<{([]{}){<><>)}[[[][]]({}())]>[[{<>()}[()<>]](({}<>)([]))]][<((()[])<()[]>)[[<>()]]>])<<{[
{[[<{<<[{{(((<{}[]>(()))[<<>()>{[][]}])){<([[]{}]{{}[]})<{{}()}{()()}>}}}[{[[<(){}>{{}()}]
{[{[<<[{[{([(<[]()>(()<>))]<{[{}<>]<{}()>}<{{}{}}[()[]]>>)[{{<{}>(())}<(<>)[<>[]]>}(<{[]<>}[()()]]<{<>{}}
[{{[{{[<{[(<{[()()][<>[]]}<([][])(()<>)>>({{{}()}[()<>]}[<[]{}><[]}]))([<<<><>>({}[])>({()[]}[<>])][([(
[({<[[<{<[(<(<[][]><[]()>){[()()]{()()}}>)[<[<()>(()[])][(<><>)]>((({}())<<>[]>))]]<[{[<<>{}>[{}<>]](<{}{}>((
<{<(<((<<[[<([<><>][()[]])(<<>{}>[<>[]])>]({<<[]>(()<>)>(((){}){<>[]})}{[[[]](<>())]<<(){}><<>[]>>
[<{(<{{<(({(<<[]()>><<()<>>>)<{<{}()><()()}}(<[][]>{{}{}})>}[{[{[][]}[()<>]]{([][])(<>[])}}[{[{}()][
{{(([[[{[{({([()()]([]<>))<[{}{}](<>())>}{{{()<>}{()()}}({()[]}[{}{}])})<([([]{})<()[]>]{<<>()>})>}[[
(((<[{<[{([[{[[]<>]{<>{}}}[[{}<>](<>{})]]<<[(){}][[]{}}>{[[][]]}>][{{[[]{}]([]{})}[([])<<>>]}
<[<[[([[[[{{{([]()){(){}}}<[[]{}](<><>)>}}]]]{([[<[(()())(()[]]][[<>{}]<<>[]>]>(<[<>]<<><>>>({{}{}}([]{
({(([<<[{{[(<({}<>)<[]<>>>(<{}<>>{(){}}))]{(({{}[]})({{}<>}((){}]))[({{}()}[()<>])<({}()){<>()}>]}}}[<
<[<({[[<<([[((<>())[<><>]){[<>[]]<<>>}]]{([<{}[]>{<><>}])})<<[<([]<>)(()<>)>(<{}()>([]<>))]>[
({({{[[<<([[({()[]}[<><>]){(()<>){<><>}}][{{<>[]}(<><>)}{[[]<>]<[]>}]])>([[<(({}[])<()>)(<()>[<>{
<([{(({<[{([<[[]<>]<()<>>><(<>())({})>][[(<>[]){[]{}}]{(<>[])<()[]>}])({[{{}()}{[]()}]}{{[[]{}]({}<>)
[([{({(({{<<<<(){}>[<>[]]>([<>()][<>[]])>[{(()())[()<>]}<{[][]}[<>{}]>]>}<[<([[]()][<>()])((<><>){[]})>
<({[{{[{{[([{({}()){{}{}}}<(()())[[][]]>][<[<>()][{}[]]><<<><>>>])([[({}{})(()<>)]{<<><>>([]<>)}]{{<()[]
<{{<{(([(<<<{{[]()}[[]()]}>{{[{}<>]<()<>>}[{{}{}}[{}[]]]}>>([([<()()>[{}<>]])([<()[]>[<>()]]{([]{})}
{<({<{[{{({[<{{}()}[()()]>{({}<>)}][<<()()>{[][]}>{<<>()><{}{}>}]})}{(<{<[()()]>}<{({}){()()}}(<[]<>><
(({{({{{<[[({((){})[<>[]]}[{<>{}}[[]()]])]{<<(<>){{}()}>[<<>>{{}{}}]>([(()[])][([]())<<>()>])}][<[[
[{[[[{<<<[<{({[]()}({}{}))[{<>}{<>[]}]}>[((<<><>>[[]<>])[[[]<>]<[][]>]){[[{}()][{}<>]]({[]
<<[{({[[[<[[[<[][]>]{{[]()}(()<>)}]{[[(){}}<{}()>][{<>{}}({}{})]}](({([]{})<()()>}[({}())]))>(<{(<(){}>)}
({<([[(<(({{<{{}[]}[[]<>]>}[<(<>[])<{}{}>><[[]<>][[]{}]>]}<[({<>{}}{{}()})(<[]()>(()<>))]([<{}()
((<[{[{[{{<[{[<>{}]}[<[][]><()>]]{{<()[]>}<[(){}]{{}<>}>}>}<(([[[]{}]<[]<>>]{[{}{}]<()[]>})[[{[]{}}{{}
[([(<([<(<<{(<{}{}>{()<>})[([]())[[]]]}[{{[]<>}((){})}<{{}[]}([]())>]><{[[<>()]]<({}())[{}<>]>}{[({}<>)
[{[<([<{<{{[[{{}{}}{<><>}]<[[]()]{[]{}}>][{({}{}){[][]}}<<{}{}>([]()]>]}[<<({}<>){()<>}>({(){}}<{}{}>)><([{}
<{((<{{<{({(([<>{}]{()<>}))(<({}[])(<>())><{{}()}[<>[]]>)}]}(<{{(({}<>)[{}{}])<<<>[]>>}}((<<<
<[<({<({{([{<<<>[]><[]{}>>(<()()>({}[]))}(((()())<{}[]>))][[[<(){}>[()()]][[{}[]]]]])}([(([{[][]}(()())][{()
[({{[<((<{{{<[[][]]({}{})>{(<>[]){[]}}}([{()[]}{[]{}}])]}{[<<[(){}]<[]<>>>{({}<>)([]())}>]
{[{(<({<[[(<<({}<>){[]{}}>(({}{})(<>[]))>({[()[]]<<>{}>}<[[][]]({}())>))(([[<>[]]([]{})][<{}>>){{[[]
{<([[(<<[(<{<<<>{}><<>>>(({}[])<()<>>)}<{<[]{}><()()>}[{(){}}]>>){<<<{{}{}}{()<>}>{{()[]}{()}>><<<<>[
<{[{(<{[<<(<<([]{})(())>[({}[]){{}()}]>)(<{[[]()]}>[{(()<>)(()<>)}{[{}<>]{()()}}])>[(({<<>[]>({}[]}}{([]
{{{([{[([[[{[{(){}}{[]()}][<<>()>]}([[[][]](<><>)])]]]{(<[(<<>[]>[{}<>])(({}[])({}{}))]{<([]{})<[][]>>((
({{[(<<<[({<[{[]<>}<{}<>>]<<()>[(){}]>>[<<<>{}>{{}[]}><({}{})>]})][(<{[(<>())]}(([<><>){[][]})
([[([{[<<{(<{<[]()>[(){}]}[(<><>){()<>}]>){{[<()()><<>[]>](<[][]>{[]<>})}<[{<>()}{()[]}]{{<><>}[<><>]}>}}{<<
<[<([<[(({<{{<(){}><<>[]>}{{<>{}}((){})}}<<[{}]({}[])}{<()()><()<>>}>>[[[{<><>}([][])](({}<>)((){}
<<[<[[<(<{(<{[[][]]{(){}}}<{{}()}<()[]>>><{<{}>}{{<>{}}[()<>]}>)}><{[<{(()[]]<()()>}<{(){}}
([([(<({{(<<{[[]<>]({}())}{{[][]}<()[]>}>>)}})(<{{<({<()[]>([]{})}[{{}<>}[<>()]])><[({<>()}{<>[
<(({{(<(<[{<[{{}[]}[<>{}])(<()<>>({}{}))>[<[<>[]]{{}}>[({}<>)[[]{}]]]}<[[{[]<>}{[]<>}]<(()()){<
{(<(([{([<({[[<>[]]{<>[]}]{{[]<>}{()}}})<[<[[]()][<>{}]>{[<>{}]<()<>>}]<(<[]>[[]()])([<>()](()<>))]>>])
{{[([[<<([(<{{{}[]}<()[]>}({[]{}}[[]{}])>(<{(){}}<(){}>><[[]{}]>))])>{{<<{<[()[]]<[]<>>>}{{(()
{{<[{[<([({<[{[][]}<<>()>]{{[]{}}({}())}]({{[]<>}}(<()<>>(<>[])))}([<[()()][[][]]>((<>{}){()<>})]
{[[{<{<<{((<<<<><>><[][]>>([()<>]<{}[]>)>{((<><>)({}()))([{}{}][<>])})<({({}[])({}())}<[()[]][{}<>]
<({{{(<{({<<(<[]<>>{{}})>[[({}<>)(()())]{[[]{}]({}{})>]>({<<()<>>[<>[]]>((()<>)([]{}))}[[([]<>)<[]<>>]{{{}<>}
{<[{([([{<[{<[<><>]([]())>((<>[])([][]))}]>(({[<[]>[[]<>]]{{{}[]}{[]{}}}}){(<{{}{}}([]<>)>)})}
(<[{{<([<[({<{{}{}}><{{}<>}([]{})>}<<[()()]{{}()}>[[[]()]({}{})]>)[[{<()[]><[]()>}<[<>()][(){}]>]]]<{(<<[]{}>
<{([[<{<([({{[<>{}]({}[])](<[][]>{{}[]})}{{{<>[]}<{}()>}<[{}[]]{{}()}>})([<[[][]]{<>()}>[<<>()>({
<{[{(<<{[<(<{{()<>}{[]()}}[([][])<{}[]>]>[[[{}<>}[()[]]][({}[]){()<>}]]){[<[{}[]][[][]]>(<{}>([][]))][[
{[{<([<<({<<(<<><>><{}[]>)[(<>()){[]{}}]>(<{{}<>}[[]<>]>([{}{}]))>}([{<(()[])[()<>]>{{()()}}}[[<[][
<{(<[{<<[[[({([]{})([]<>)}{([][])([][])})[[<[]{}><<><>>]<[{}<>]({}[])>]]<{[[{}{}]({}[])]<{[]<>}(()<>)>}[({<
(<[{([[[{[<([<{}[]>][(<>[])(()<>)])<[{[][]}([]())]>>][{([(<>())[()[]]])}({({()[]}[{}{}])}{[<[]<>>([]()
<({{[([[<<[(({{}}{{}()})<<()()><<><>>>)<[<{}[]><()<>>][<<>{}]([]{})]>]>>{<((<<[]>(())>{{()<>}}
[[[[<{[[({[{{[()[]]([]())}}<<{{}<>}(<>)>({{}{}}<[][]>)>]<{(<<>()>{(){}})[{()()}<<>>]}([{{}]<{}<>>][[()()](
(([[<(([{<({<<()()>>{<()<>><{}{}>}}{((<>()){()[]})<([]{}){()[]}>})>(<[[<[]()>{[][]>][[[]]<<>
{[<[({<(<<[[((<>())(<>[])){(<>[])(<>[])}][({[]{}}{{}<>})[<(){}>((){})]]]>>[<<{<<()[]>[[][]>>(
{<<(<([<<<((({[][]}{<><>})[{[][]}([]{})])<[<{}{}>({}())][((){})[[]()]]>)<[{(()<>)(()[])}](<[

Day 11: typescript

this documentation is autogenerated. Add a README.adoc to your solution to take over the control of this :-)

typescript

input1.txt
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526
package.json
{
  "name": "aoc2021",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "main": "ts-node main.ts"
  },
  "author": "Christoph Jobmann <christoph.jobmann@deutschebahn.com>",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^16.11.12",
    "typescript": "^4.5.2"
  },
  "dependencies": {
    "ts-node": "^10.4.0",
    "tslint": "^5.20.1",
    "typescript": "^3.9.10"
  }
}
flashAnalyzer.ts
import * as r from './read';

export class FlashAnalyzer {
    private energyLevels: number[][] = [];
    private columns: number;
    private rows: number;

    constructor() {
        const lines = r.readLines('input.txt', '');
        this.rows = lines.length;
        this.columns = lines[0].length;

        for (let r = 0; r < this.rows; ++r) {
            const row = lines[r];
            this.energyLevels[r] = [];
            for (let c = 0; c < this.columns; ++c) {
                this.energyLevels[r][c] = parseInt(row.charAt(c));
            }
        }
    }

    /**
     * Counts home many flashes occurred within the given number of steps.
     * @param steps number of desired steps.
     * @returns number of flashes.
     */
    public countFlashesAfter(steps: number) : number {
        let result = 0;

        for (let c = 0; c < steps; ++c) {
            result += this.step();
        }

        return result;
    }

    /**
     * Counts how many steps it takes until all octopuses flash at the same time.
     * @returns Number of steps.
     */
    public countStepsToFullFlash() : number {
        for (let result = 0; true; ++result) {
            if (this.step() == this.rows * this.columns) {
                return result;
            }
        }
    }

    private step() : number {
        let result = 0;
        let flashed: boolean[] = new Array<boolean>(this.energyLevels.length * this.energyLevels[0].length).fill(false);

        for (let r = 0; r < this.rows; ++r) {
            for (let c = 0; c < this.columns; ++c) {
                result += this.incrementAndFlash(r, c, flashed);
            }
        }

        // Reset energy for flashers.
        for (let r = 0; r < this.rows; ++r) {
            for (let c = 0; c < this.columns; ++c) {
                if (this.energyLevels[r][c] > 9) {
                    this.energyLevels[r][c] = 0;
                }
            }
        }

        return result;
    }

    private incrementAndFlash(r: number, c: number, flashed: boolean[]) : number {
        let result = 0;
        if (r >= 0 && r < this.rows && c >= 0 && c < this.columns) {
            if (++this.energyLevels[r][c] > 9 && !flashed[r * this.rows + c]) {
                const neighbours = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
                flashed[r * this.rows + c] = true;
                result = 1 + neighbours
                    .map(p => this.incrementAndFlash(r + p[0], c + p[1], flashed))
                    .reduce((s, v) => s + v, 0);
            }
        }

        return result;
    }
}
read.ts
import * as fs from 'fs';

/**
 * Reads all lines from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @returns lines of the file.
 */
export function readLines(file: string, path: string) : string[] {
    return readBlocks(file, path, '\r\n');
}

/**
 * Reads all blocks from the given file.
 * @param file name of the file.
 * @param path alternative location if file is not found.
 * @param separator separator that is to be used for separating blocks.
 * @returns blocks of the file.
 */
 export function readBlocks(file: string, path: string, separator: string) : string[] {
    let input: string;

    const path1 = path + '/' + file;

    if (fs.existsSync(path1)) {
        input = fs.readFileSync(path1,'utf8');
    }
    else {
        input = fs.readFileSync(file,'utf8');
    }

    return input.split(separator);
}
main.ts
// Day 11: Dumbo Octopus
// Solution by Christoph Jobmann

import { FlashAnalyzer } from "./flashAnalyzer";

const flashes = new FlashAnalyzer().countFlashesAfter(100);
console.log(flashes);

const untilFullFlash = new FlashAnalyzer().countStepsToFullFlash();
console.log(untilFullFlash);
tsconfig.json
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "baseUrl": "./",
    "paths": {
      "*": ["./dist"]
    },
    "typeRoots": ["node_modules/@types", "src/types"],
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "exclude": []
}
input.txt
4341347643
5477728451
2322733878
5453762556
2718123421
4237886115
5631617114
2217667227
4236581255
4482627641