~zanneth/aoc2022

f5bd725599c8cfa247692bc832abe78e228c6be5 — Charles Magahern 1 year, 9 months ago master
Initial commit
A  => day1/day1.cpp +69 -0
@@ 1,69 @@
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <sysexits.h>

using namespace std;

int my_atoi(const char *str)
{
    int r = 0;
    int sign = 1;
    const size_t len = strlen(str);
    
    for (unsigned i = 0; i < len; ++i) {
        const char c = str[i];
        if (c == '-') {
            sign = -1;
        } else if (c >= '0' && c <= '9') {
            int digit = c - '0';
            r += int(pow(10.0, double(len - i - 1))) * digit;
        } else {
            return 0;
        }
    }
    
    return sign * r;
}

int main(int argc, const char **argv)
{
    if (argc != 2) {
        fprintf(stderr, "usage: %s <input-file>\n", argv[0]);
        exit(EX_USAGE);
    }
    
    ifstream f(argv[1]);
    
    const size_t max_cals_buckets = 3;
    size_t max_cals[max_cals_buckets] = {0};
    size_t cur_elf_calories = 0;
    
    for (string line; getline(f, line);) {
        if (line.empty()) {
            for (size_t i = 0; i < max_cals_buckets; ++i) {
                if (cur_elf_calories > max_cals[i]) {
                    max_cals[i] = cur_elf_calories;
                    break;
                }
            }
            cur_elf_calories = 0;
        } else {
            cur_elf_calories += my_atoi(line.c_str());
        }
    }
    
    size_t sum = 0;
    for (unsigned i = 0; i < max_cals_buckets; ++i) {
        printf("bucket[%u] = %zu\n", i, max_cals[i]);
        sum += max_cals[i];
    }
    printf("sum = %zu\n", sum);
    
    return 0;
}


A  => day1/input.txt +2251 -0
@@ 1,2251 @@
2494
8013
1055
5425
9104
10665

10642
10677
10300
7374
9085
8508
7569
6214

5300
5960
8252
5852
4308
9991
6367

1361
5356
6114
3379
5996
3822
3785
1622
1143
6009
2211
4951
3093
6395

4892
6648
3022
6063
5436
2174
4264
2004
6444
2926
2651
2749

17121
17879
11056
15642

3926
6751
2643
7882
4006
1351
4912
2735
2985
4015

3043
6923
10352
9998
2470
7346
1077
3024

21632
34735

8525
1982
9285
4188
7017
6666
6538

7019
2696
2707
3639
3674
3642
4837
3804

3570
8191
6054
8727
7323
3522

1442
5794
3774
2398
5615
5786
1832
2234
7906
4799

12978
17621
9788
9237

3006
2799
5627
2478
3159
6430
3843
1469
2006
4131
2269
6201
3593
1423

30560

5281
3850
2894
4056
4341
4117
8216
2700
1327
2379

1597
7217
1003
2555
4820
2881
4051
4550
2457
6518
5480
3044

9465
4325
5593
5606
9317
1026
3707
9456
7801

6217
7814
3159
3866
1035
4302
1498
1160
1510
4650

13306
15884
9699
11206

24775
21119
12643

12737
10893
3450
10732
8670
7597

35714

3380
3513
6559
6891
7767
5311
7086
5345
3498
3091
2516

11565
12877
13416
10568
16033

1380
4192
5815
6230
2434
2443
3682
5568
6134
3316
5878
4493
3857
2110

4341
2469
5606
4268
3525
5555
5771
2284
1921
3279
1901
5991
2868
4866
2310

5969
18172
1931

3598
2837
1105
7300
11781
10686

3698
4698
3891
4481
4089
3511
4949
2148
4017
2529
3572
1912
1837
1937
2688

6485
7072
7964
13114
5864
5280

12413
7196
12856
18069

1367
2238
3089
3189
5022
3877
5238
3566
1081
1525
1958
5796
2498
1517
1481

25527
17474
4705

6722
2844
3856
1780
4518
5679
4775
6067
2695
5979
2488
1515
5071

7155
4147
4406
4169
2156
7110
6837
4673
3599
2672
2768
3195

8040
5248
6440
1830
2281
4938
6116
6842
5743
5788
5703

2527
3362
5630
4976
1989
5157
4951
3382
4525
4057
4077
3717
4035
4907
1795

1069
7242
2438
7224
8058
6215
7770
5958
2445
1702
3558

6075
4164
5797
1051
3104
2966
3653
3933
1546
5111
4811
4145
3532
2289
1468

9540

1830
6422
7523
2131
3072
2873
1423
7560
4640
4476

10022
15927
14403
2312

3056
5371
4501
6465
4761
2050
4187
1179
3746
6089
1365
6495
4844
4984

1812
2671
1805
4200
1986
5327
5548
1872
4364
3147
5447
5882
2602
5501
2446

9725
8080
9941
10636
6852
5378
4137

25228
22215
10199

15394
28799

3620
1758
4663
2715
5642
6209
5361
4582
2165
7485
7611

6910
6782
2177
2763
6877
3922
1355
2400
6139
5362
5737
3766
3535

6587
6770
3729
3316
4161
2828
3886
7483
2746
5923

1647
6201
1200
5810
4493
5373
1856
5507
1833
4277
2897
4473
4433
4352

3807
18028
7426
18476

6493
1157
3125
7736
1208
3243
7737
1953
1970
3245
1600

12034
12959
9334

8432
3424
4506
5758
10840
11056

7284
4013
4217
7307
6367
1977
3617
2165
2969
6595
6651
2446

1083
5636
1785
2553
4634
3790
7465
2970
2725
4267
2861

3145
7872
5049
3368
4009
2348
6877
6956
2359
8064
4386

4764
6236
4923
4395
2974
3985
2725
1831
2755
4068
2383
2138
2998
4346

6673
2519
2754
5734
4796
3389
6931
5771
5936
2328
5684
3171
4608

15166
11415
9051
3437
10405

1590
7370
7003
5030
3852
6353
7054
3765
2925
6968

9678
2846
8939
10270
7196
11860
4221

4447
5407
1459
1693
3774
3978
5240
2331
1903
4421
1152
5084
1969
2365
4526

5249
5631
3701
6419
6003
6884
2315
5745
1341
6370
5430
6442
3156

2112
3970
1000
1981
3528
3490
1510
1629
5413
4277
6347
6134
1855

8848
3187
9361
16338
5644

8477
6983
8052
4156
8204
3216
4797
3024
3499
6006

7326
14394
7169
17160

3282
5582
6657
5435
2096
3038
5747
2545
1927
6331
6785
1199
1794

1471
4089
8406
3811
7060
1164
1042
5968
8721

6191
17967
6680
15071

1811
2960
4046
4196
5271
1982
2324
8928
4517

12525
5174
5986
14713
15516

4412
5282
6035
5882
5488
5797
1101
2763
6159
3886
5358
5802
4033
3113

9534
4195
9134
4093
2988
7170
10552
1724

1768
8793
5606
8771
5365
9465
6618
3528

2206
4623
4108
3138
5818
4907
2036
1646
5703
3097
3475
1167
2515
5095
4964

3633
6926
5402
4602
8429
9575
7807
3691
1060

1142
10612
6215
9965
6377
2889

3544
3870
1373
1166
2068
5111
1958
4383
1868
5305
3620
5304
3126
2972

36719

6297
1347
1423
7325
1798
7102
2585
7973
7084
6963
2423

23242
10969
22162

13407

3392
4473
1448
4470
2740
2249
1154
2212
3078
3817
6471
3506
3395
1906

4808
1923
8332
8636
2919
5259
7210
10191

7183
4475
5652
6992
7492
7906
7275
6680
5776

2752
9069
11736
9659
11337
1120
9412

3199
3488
13447
10265
6076
13516

1651
3970
7077
6774
6915
4838
10860

5737
6268
1718
10759
3572
5494

24537
10330

10316
2956
5555
6248
5263
1249
5783
5774

3525
2066
2616
7191
3926
1532
5964
5512
1695
2512
6491

2975
1916
10644
5182
5339
8680
3275
10289

4593
4274
4044
4904
1989
4851
1555
3703
5231
2427
3096
4461
5178
5241
1141

2331
1706
5359
5149
3273
4602
3067
6598
6665
3244
2654

2959
3036
1202
4882
1152
1667
4291
2393
3774
5366
1414
3985
4260
2775
3831

2474
1259
2835
6583
6997
6502
5069
6551
3077
5282
2469
7110

8600
5500
15337
13901
1000

18310
10484

6280
8351
4405
5826
1032
6646
1367
3758
7046
2308

4888
8942
6060
2012
9154
6142
1923
7135
3387

9170
5125
1487
6729
8642
10296
7469

1373
9559
6106
2405
7721
5877
5946
6080

4164
2747
4312
5824
2960
2506
6274
5887
4796
3492
4477
2933
1811
4957

8728
9090
7028
8869
3362
3784
7482
8101
3665

5341
8591
3108
9080
6248
6100

7454
28472

7151
4060
9436
9008
1333
6366
8098
7046
1869

34017
11550

4232
6470
3007
4974
6384
5389
2818
3389
2533
6309
2500
2012
2348
3439

2004
2786
6125
2455
3910
2408
1037
2979
3755
3838
2639
5705
4765
3057

2257
2999
6940
2994
5671
1779
2765
5705
2980
4426
6194
4142
5594

31017
14466

5123
4500
5594
2181
3229
4797
3006
5755
3988
3184
2501
5516
5401

23717
19963
23101

22339
24909
1460

4560
2544
3862
4631
2156
7098
3945
1190
1009
1850
2418
2600

3012
1803
1248
1391
3975
4870
6010
4507
5351
2986
6310
4678
4341
4420

18246
20268
12620

2308
9249
3234
11647
5717
10514
10348

6993
14784
22089

2456
7956
4644
11788
10286
10176
6059

7692
10510
11255

6235
2861
1136

11444

11241
2893
3679
12208

8913
9505
3537
15868

4555
9248
18262

12005
1419
5608
3454

14026
3426
9822
6157
1034

3063
1146
10723
1798
10569
3361
8119
5926

11894
8410
3507
8343
15469

16610
3588
11982
2953

3112
4710
4522
2766
4143
3462
1736
2128
2889
4421
2772
1153
4622
3897
4013

3483
1728
3257
4736
11723
2254
7438

4465
5761
1625
5566
1391
5720
2158
5331
1482
1734
4974
1276
2704
1386
5426

18780
10740

5245
1769
7853

2539
6400
4704
3929
6819
4483
1535
1689
6851
2644
1799
6513
4817

6631
13675
2737
15282
10426

4102
2574
4427
2824
1083
4480
3898
2459
4123
4502
2174
4804
3109
3121
3408

9018
2604
9256
6568
4487
4133
3395
9266
2025

3920
1556
6177
5349
6296
13639

4313
1156
8342
7415
4000
11858
4709

8780
5173
6162
6344
1941

1301
4685
1841
2222
3305
3965
6551
7114
5399
3747
1839
6706

7853
11264

14768
14746
5840
1731

4166
1442
2971
8507
1859
5344

2874
1080
4159
2491
3860
6050
6523
1136
1478
6370
6541
3607
1908

4652
5783
4407
5261
1017
3165
3589
1771
1700
1308
2280
5742

4598
4281
2933
5351
2897
3983
6840
4827
3726
7356
5221
4955

5184
9444
4616
2549
4979
4577

4998
1639
1189
2612
1072
2130
1044
3009
4132
2712
1223
5394
4698
3702
2456

5523
6843
6182
4741
6514
5068
4521
2424
6076
7273
3125
6378

5675
5075
4462
2155
2621
6955
6893
5037
1935
6837
2225
5190

23738
30667

3332
4507
4454
3274
6417
5739
1855
5078
2040
2472
6068
5696
1449

12606
17528

1761
8980
8137
12561
1838

23685
5576
2070

2014
2573
1478
3902
6247
5167
3393
3723
6336
4675
6430
5310
1484
4109

9842
3374
4250
6939
3975
5106
4823

27517
29161

3861
2633
15717

4392
3840
3178
4148
1419
4242
5498
3890
6033
4700
6624
4499

7872
1829
9261
3780
3815
11309
5207

10646
3597
8139
4802
6588
8367
9006

3268
4153
4070
3310
1132
6237
3285
4461
1418
3315
5840
3931
4168
4059

12562
15842
4084
5075
4652

13950
9685
24437

13322
17454
3563
6272

3171
4566
2828
2367
3947
3408
4149
3323
2995
5217
2740
5365
1857
3393
5257

25535
4255
4792

2725
7987
4898
4443
6620
7232
5562
8511
8551
6817

4986
1999
9609
4028
7978
7833

7122
3544
1386
6190
2119
3479
3638
2645
4651
6909
3419
6260

4884
24630
16892

1404
3127
3142
5332
1979
1038
4098
3841
3620
3092
5325
3685
5385
3439

25512
4994
1339

65852

5886
2370
2424
7331
4765
8599
3997
4213
1185
4739

3268
6752
3238
8925
4044
9369
4423
6024

7615
7582
1946
6493
6969
2369
2498
4231
6898
2301

13338
15159
1007
1579
4532

3111
4477
2628
2009
1361
3171
5895
5000
3213
5536

3384
6723
5558
3445
7104
4590
2005
1142
4239
2804
2136
5493

8745
8221
2669
3171
5469
2077
7506
1388
6350

1347
1620
2690
4070
4859
6068
4170
4634
2749
3346
3541
3841
3558
5879
1725

1630
8268
4370
1609
6617
5419
4991
3865
5722
4530

5677
17141
16522
13806

18659
25364
19945

27851
31094

4535
5908
4391
1243
1037
4963
1570
5836
3720
3066
2995
4234
3073
5882

37830

8609
8530
6527
2145
8647
7720
5906
2524
8666

1143
1080
4034
2107
2539
4458
5898
2709
4941
1011
1232
3069
1527
2769
5071

2092
6346
6041
8472
10954
2509
3632

23978
1578
23954

3027
2598
1818
5892
2519
5083
3793
5849
1488
3357
1350
6813
4486

2282
6271
2548
6333
7978
4451
5808
5716
7485
6615
2823

63025

5701
2013
5327
3534
4144
1980
5576
5075
5456
3808
2466
5444
4918
6048
4177

3240
1730
5306
7215
2278
4619
3812
4873
4453

1467
2152
6616
3839
3422
3110
4447
6771
2967
4994
6764
5722
3680

58287

6434
1137
15936
15651
14632

1074
5120
1340
4497
4947
2195
1243
5123
2076
4464
2615
3780
5693
1208
2180

14965
10684
2049
10628
9532

24592

4560
4156
3363
1751
4886
5216
2888
1327
1285
6123
2701
4501
6007

6445
1701
3886
3597
3854
2593
3249
3424
1703
3036
1670
5705
5781
1953

11411
7632
1419
5620
7953
7273
10715

12735
1860
6909
9353

6189
10627
9335
5646
5375
6886
3897
5716

8653
12542
6082
15244

4819
1613
1332
3125
1897
3675
3688
3393
3794
1146

2603
6838
6037
5540
2335
6837
4425
3437
5965
3449
4752
5173
1971

25800
14272
12870

4840
6051
2429
2372
2533
4184
4051
5449
1321
2738
4450
4473
4618
2936
5818

9966
9565
4598
6548
6832
1749

6333
7723
7084
7305
2609
8143
10400
7867

2652
6421
6630
4124
8490
8618
6380
2636
8045

1382
6541
2533
3419
3661
4779
5466
6163
5536
4844
2600
1126
4297

4541
10317
5900
4278
2540
4385
3048
3079

7542
4938
1913
7746
7472
7621
1307
2142

12358
6813
15347
14448
4584

8653
14358
1689
3466
13581

18460
15717
11921

5002
1450
1233
5553
2723
3811
4765
1001
4513
5847
4403

20065
10696

8007
1090
2875
4585
7707
7823
2009
8498

9586
8143
8021
4245
7291
3936
11899

26024

14163
9586
12371
2127
4436

2613
6450
3236
7142
6570
6405
2444
3243
6166
7090
3461
6534

3176
4477
4562
3589
5280
5548
3708
4632
3836
4171
5284
3667
3313
4312

12262
7518
13586
14339
2951

30207

3979
2163
7147
3726
4358
7572
3345
1296
2755
4608

5723
3754
2684

19384
3722

2024
8540
6504
12081
4812
3647
2731

18117
13193
13899
19853

3533
4991
2034
3914
5920
2455
2660
3175
1410
1127
2272
3689
5804
1311
1121
\ No newline at end of file

A  => day2/day2 +0 -0
A  => day2/day2.cpp +162 -0
@@ 1,162 @@
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>
#include <sysexits.h>

using namespace std;

enum Shape {
    ROCK,
    PAPER,
    SCISSORS,
};

enum Outcome {
    WIN,
    LOSE,
    DRAW,
};

static Shape from_opponent_strategy(char c)
{
    switch (c) {
    case 'A': return Shape::ROCK;
    case 'B': return Shape::PAPER;
    case 'C': return Shape::SCISSORS;
    default:  throw runtime_error("invalid opp shape");
    }
}

static Shape from_player_strategy(char c)
{
    switch (c) {
    case 'X': return Shape::ROCK;
    case 'Y': return Shape::PAPER;
    case 'Z': return Shape::SCISSORS;
    default:  throw runtime_error("invalid player shape");
    }
}

static Outcome from_raw(char c)
{
    switch (c) {
    case 'X': return Outcome::LOSE;
    case 'Y': return Outcome::DRAW;
    case 'Z': return Outcome::WIN;
    default:  throw runtime_error("invalid outcome");
    }
}

static size_t score_for_shape(Shape s)
{
    switch (s) {
    case Shape::ROCK:       return 1;
    case Shape::PAPER:      return 2;
    case Shape::SCISSORS:   return 3;
    }
}

static Shape shape_for_outcome(Shape opp, Outcome outcome)
{
    switch (outcome) {
    case Outcome::WIN:
        switch (opp) {
        case Shape::ROCK:        return Shape::PAPER;
        case Shape::PAPER:       return Shape::SCISSORS;
        case Shape::SCISSORS:    return Shape::ROCK;
        }
        break;
        
    case Outcome::LOSE:
        switch (opp) {
        case Shape::ROCK:        return Shape::SCISSORS;
        case Shape::PAPER:       return Shape::ROCK;
        case Shape::SCISSORS:    return Shape::PAPER;
        }
        break;
        
    case Outcome::DRAW:
        return opp;
    }
}

static bool is_win(Shape player, Shape opp)
{
    return player == shape_for_outcome(opp, Outcome::WIN);
    
    /*
    if (player == opp) {
        return false;
    }
    
    return (
        (player == Shape::ROCK && opp == Shape::SCISSORS) ||
        (player == Shape::PAPER && opp == Shape::ROCK) ||
        (player == Shape::SCISSORS && opp == Shape::PAPER)
    );
    */
}

static size_t score_for_p1(Shape player, Shape opp)
{
    size_t base_score = 0;
    if (player == opp) {
        // draw
        base_score = 3;
    } else if (is_win(player, opp)) {
        // win
        base_score = 6;
    } else {
        // loss
        base_score = 0;
    }

    return base_score + score_for_shape(player);
}

static size_t score_for_p2(Shape opp, Outcome outcome)
{
    size_t base_score = 0;
    switch (outcome) {
    break; case Outcome::WIN:   base_score = 6;
    break; case Outcome::LOSE:  base_score = 0;
    break; case Outcome::DRAW:  base_score = 3;
    }
    
    return base_score + score_for_shape(shape_for_outcome(opp, outcome));
}

int main(int argc, const char **argv)
{
    if (argc != 2) {
        fprintf(stderr, "usage: %s <input-file>\n", argv[0]);
        exit(EX_USAGE);
    }
    
    ifstream f(argv[1]);
    
    size_t p1_score = 0;
    size_t p2_score = 0;
    
    for (string line; getline(f, line);) {
        char col1, col2;
        sscanf(line.c_str(), "%c %c", &col1, &col2);
        
        Shape player = from_player_strategy(col2);
        Shape opp = from_opponent_strategy(col1);
        p1_score += score_for_p1(player, opp);
        
        Outcome outcome = from_raw(col2);
        p2_score += score_for_p2(opp, outcome);
    }
    
    printf("part1 score = %zu\n", p1_score);
    printf("part2 score = %zu\n", p2_score);
    
    return 0;
}


A  => day2/input.txt +2500 -0
@@ 1,2500 @@
B X
A Z
A Y
B X
C Z
B Y
B X
C X
A Y
B Y
B Y
C Y
B Y
C Y
B X
A Z
C Y
B Z
C X
A Y
B Y
B Y
B Y
B Y
B X
B Y
C Y
B Y
B Y
B Y
A Y
B X
A Y
A Y
B X
B Z
B Y
C Y
A Y
A Z
C Y
A Z
C Z
C Y
B Z
C X
A Z
C Y
B X
B X
C Z
C Y
B Y
A X
C Z
B Y
B X
A Z
B Z
C Y
C Z
B X
B Y
B Y
C Y
B Y
B Y
C Y
B Z
A Y
B Y
C Y
B Y
B Y
B Y
C Y
B X
C X
C Y
B X
B X
C X
B Y
C Z
B Y
B Y
B Y
C Y
B X
A Z
C Y
A Z
B X
B X
A Y
C X
B Z
B Y
B X
C X
C X
B X
A Z
A Y
A Z
B X
B X
B Y
C Y
C Z
B Y
A Y
C Y
A Z
A X
A Y
B X
B Y
C Y
B Y
B Z
C X
B Y
B Z
C Y
C Y
C Z
B Y
C Y
B Y
C Y
A Z
A Z
A Z
B Y
B Y
C Z
B Y
C Y
B X
B X
A Y
B X
B X
C Y
C Z
B Y
A Z
A Y
C Y
B X
C Z
C Y
B Y
B Y
A Z
B Y
B Y
B X
B Z
A Z
C Y
A Z
C Z
B Y
B Y
A X
B X
A Z
B Y
C Z
A Y
B Y
A Z
C X
C Y
B Y
B Y
B Y
C Z
B X
C Z
B Y
C Y
C Y
B Y
C Y
C Z
B Y
C Z
B Y
B Y
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
B X
B Y
C X
B Y
C Y
A Z
A Z
B X
B Z
A X
A Z
C X
A Z
B Z
B Y
C Y
B X
B Y
B Z
B Y
B X
B Y
C X
B Y
B X
B Y
C Y
C X
B Z
B Y
C X
C X
B X
B Y
B X
B Y
B Y
B Y
B Y
B X
B Y
A Z
B Y
A Y
B Y
A Y
B Y
A Y
C Y
B Y
C Y
C Y
C Y
C Y
C Y
C Y
A Z
A Z
B X
C X
C Z
B Y
C X
A Z
C Z
C Y
B Z
B Y
B Z
B Y
A Z
B X
B Y
B X
C Y
B Y
B X
A Y
B Y
B Y
B Z
B X
C X
B Y
B Y
C Y
C Y
B Y
C Y
C X
A X
C X
C Y
B Y
B Y
B Y
B Z
B Y
B Z
B Y
B X
A Z
C Z
C Y
C Y
A Y
B X
B Y
C Z
A Y
A Y
B Y
B X
A Z
B Y
B Y
A Y
C Y
A Z
C Y
B Z
B Y
B Y
C Y
C Z
B Y
B Y
C Y
C Y
B Z
B Z
A Y
C Y
A Z
B Z
B Y
B Y
B X
B Y
A Z
A Y
A Z
B Y
B X
C X
C Y
C Z
B Y
B Y
B Y
A Y
C Y
B Y
C Y
C Y
B Y
\ No newline at end of file

A  => day22/.gitignore +1 -0
@@ 1,1 @@
/target

A  => day22/Cargo.lock +7 -0
@@ 1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "day22"
version = "0.1.0"

A  => day22/Cargo.toml +8 -0
@@ 1,8 @@
[package]
name = "day22"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

A  => day22/example.txt +14 -0
@@ 1,14 @@
        ...#
        .#..
        #...
        ....
...#.......#
........#...
..#....#....
..........#.
        ...#....
        .....#..
        .#......
        ......#.

10R5L5R10L4R5L5
\ No newline at end of file

A  => day22/input.txt +202 -0
@@ 1,202 @@
                                                  .......#..............................................#.#..#.#..#.....#.........#.....#.............
                                                  ......................#..........................#.#.....................##.........................
                                                  ......#...#.#...........#...#..........#...........#.........................#..........#..#........
                                                  ..........#.....#.....##..#..#..............#....#..........................##.#..#......#.....##...
                                                  .......#....#...#.......#..#......#...#..........#...........................####...................
                                                  ...#.....#....#............#..#.#.....#.#................#..#........#.........#....................
                                                  ..............#...#....#....................#.#....#.##....#...#.#.#...#..........#....#............
                                                  ...........#........#.#......#.#..............................#.............#.............#....#....
                                                  ............#.........##..........##.#....##........#.......#.#.......................#...#...#.....
                                                  ...................#......#........#......#.......#....#...............................#...#......#.
                                                  ....#........................................#..#................##...........#.........#...##......
                                                  ..........................#...................#.......#.......##...#.......#...#........#...........
                                                  ........#....#...##...#.......#.....##...#..............#.................#..#.........#........#...
                                                  ..................#..........#...#...#..#...........................##...##.....#...................
                                                  ...#......#....#......#.............#.....#...........#...........................................#.
                                                  ...................#..........#..#.......#........#........#.#.....#...#............................
                                                  ..#.....................#..#....#.......#......#.................................#..............#...
                                                  ............#...........#..#..........#...........##...................#..#.............#.....#.#...
                                                  ..............##.........#.#........#.............#...#..........#.........................#.#....#.
                                                  .#............##................................#.......#......#...##...#.............#.............
                                                  ...............#............#...........#.#.............#..........................##...#...........
                                                  ...#.#...........#.......#..#............#.....#.......#....#.....#...#.........#.#.....#..........#
                                                  .#.....................#..#...........#............#........#........#....#.#.......................
                                                  ..#.......................................#...........#....#......................#..............#..
                                                  ..#..........#..#...........#..........................#..........#.........#....#......#..........#
                                                  .....#........................#......................#.#..#........#................................
                                                  #...#..................#....#..............................#......#.....................#.#.........
                                                  ...........#.............#...##..........#.......................#..#....#...#.....#..#.........#..#
                                                  .#..#..#.............##..#..............##.....#.............#......##..#.##...............#........
                                                  ........#...#...............#....#.#..........#..#........#..#..#......#.....#......................
                                                  ......................#...............#...............#............#....#....#.#....................
                                                  .#.....#.............#................................#.............................#.....#...#....#
                                                  .........#.##........#.#..#.....##.........................##..........................#............
                                                  ....#.........................#........#...........#..#....................#......#..#..........#...
                                                  ..........#...#.##...........................................................##......#..............
                                                  ...#..........#....#....#..#.....#....#...#..#....#..............#..........................#.#.....
                                                  .#.......#.#.....................#...........#..................................#.....#.......#....#
                                                  .........##.........................#...#......#....#............................#....#.............
                                                  ..................#........#.....#...............#........#.....#...................#...#........#..
                                                  ...............#........#...........#....#................#..........##......#.#....................
                                                  ....#.............#............#.........#...........................................#......#...#..#
                                                  ...............##...#.##.#.............#...#.......#..#..#...#..#...........#.....##.##...#........#
                                                  #........#...##................................##..#....................#.#.......................#.
                                                  ....#.#.......#..........#.............#.#............#........#.....##.#........#..................
                                                  ......#................##.....#.............#..#.....#.#..........#...##....#....................#..
                                                  ...###...............................#..................#.#..........#...........................#..
                                                  ...#.........#......#.#....#...........#.....#.......................#.#...#......#................#
                                                  .....#..#.#..#............#.....#........................#....#.................#..........#.....#..
                                                  ...#...........#.....#...........#.#..#....#.#...##.#......#.#.....#....#........#..................
                                                  ..#......#.#...##............#............................#.....#...........#.....................#.
                                                  ..#..............#........................##.#....
                                                  ....#............#...#....#..#....#.........#.....
                                                  ...#........#.#.#................#...............#
                                                  .#..#.........................#....#.#.....#......
                                                  ....#..........#....................#.#.##........
                                                  ....#.......#..#........................#.........
                                                  ..............#......#.........#...........#......
                                                  #......#.#............#....................#...#..
                                                  #..........#.....#................................
                                                  ..#.......##...#............................#.....
                                                  ..##........#..........#...##.........#..........#
                                                  ................#....#........#.....#.............
                                                  ....#..#.............#.............#..............
                                                  ..#.........#.......#...##.....#.......#...#......
                                                  ..........#.................#......#...#..........
                                                  ..........................#.......................
                                                  ...#...#.........#.....#.......#............#.....
                                                  ............................#..........##........#
                                                  ....#...................#.......................#.
                                                  ...#.....#.....#........................#.........
                                                  ...................................#......#.#.....
                                                  .......##.#...........###........................#
                                                  ...#.............#.#..........#............#......
                                                  ................#..#.....#.............#..........
                                                  .#......##.#......#.#..#.......................#..
                                                  .#...........#............#....#..................
                                                  ......#...#.#............#...#...#...#............
                                                  ...........##.......##.......#....................
                                                  #..........#......#..................#............
                                                  ......#..................#..........#............#
                                                  ......................#........#..........#.......
                                                  .......#......#.................#.................
                                                  ...................#.#.........#..........#.......
                                                  .......#.#..........................#..#..........
                                                  .......#..........#...............................
                                                  ..................#.........#................##..#
                                                  ##..........#.......#.........#...#......#........
                                                  ..................#.........#.....................
                                                  .....#......#................#....................
                                                  ...............................#..#......#........
                                                  ..........................#....#..................
                                                  .....#..#..#..........#......#....................
                                                  ........##...#..#......#..#...............#.......
                                                  ##.......#..........#...#..........##......#......
                                                  #.............#...............................#...
                                                  .#.............#..................................
                                                  ..................................................
                                                  .#...#...#..#.............#.....#......#..........
                                                  .#..#.....#..............#.##....#................
                                                  ...................#.#.........#..................
..#..##......##.#........#.#....#.......#................#..........................................
.....#.......#.......#........#.#.....#.............#..............#..............#.................
..........#....#...#...........................##...............................##.#...............#
..........#.............#.................##..............#.................................#.......
.#..#.............................................#...##..#.....#.......#.#..##...#.................
##.##...................................#...................................#.............#.........
....#.........#.........#............#..#.........#...........#..............#..........#......#....
.....................#...#........................#...........#.....#...............................
...#......#.....#....#.....#..........#.........................##.#........#.......................
.#.......#.......................##...................#.#..#...#.......................##...........
.#...........#.............#...#......................#..#...........#.....#........#......#........
....................#....##...#...............##.#....#.....................#.#...............#.....
.......#..#..#.....#...........#......#...........................#..............#...#......#.......
.....#.......#...................##..............................#...............#................#.
...#...........#...........##.#.......#....##..............#.##...............#.......#...#.#......#
...............#.........#....##........#....##.......#...................##.................#...#..
...........#.............#.........#..#.#..........#...#.....#............#.........................
...................#......#.................#....................#...#...#...............#..#.......
....#.........................................##...#..#.....................#....#..................
.................#...#.....#........................#........#.......#........#.....................
.............#........................#.#.....................#..........#..............#....#.#....
..#........#.#...............#..#.....#...#...............#..#........................#.#....#......
#......#........#....#.....#.#..........##.....#.....#..........................##..#.#.#........#.#
.......#.....#..#...........#..#.#....#.......#...........#...........#..................#..........
..............#............................................................#...#.....##......#......
..#....................................#..........#.#....##.....#...#...........#.....#.............
..................#...#.....................#.#.#..#..............#..#.....#...........#.....#...#..
.#.#..#.....##...........#.................#.........#.......................#.#...#.#.....#........
.....#...........................#.............#.....#.............#.....................#.......#..
....#..#...#............#.............#..#..#......#...#.................#....#....###..............
.........#.....#....#........#........#....##...#.......#...#.....#........#............#...........
##.....#...#.##................##........#......#........................#..#.....#.........#.......
........................#...........#.............................#.....#..#.................#......
.............#..#.....#..................#............#.........................#...................
............#..............#.#..#.....................#........................#..#.......#......#..
.............##........#.#......#....#.....................##.................#..#..##...........#..
......................#..................#.......................#....#.................#...........
#.....#.......#............#......#..#...#....#.#.............#.................#.....#.............
...#.......#.........................#...........##..........#..................#..#.......#.....#..
..#.#.#..............#....#..#..........................................#.#..........#.....#........
.....#..................#.#............#........................................#....#..............
.#.....#........#................................#..#...................##.#......#.................
##............#......#.#...##.............................#.......#........#........................
...............#..#......#.......#....#....................................#......#...........#....#
...........#..........#......#...#....#.....#....#..............#............#.............#........
...............#...........#....#.......................#...#...............................#.......
........#........#......#...#.................#..#..................#..................#............
...#.........#................#.....................#..##...................#....##............#.#..
...........#....#.#.....##......................#..#......#.........#...#...........................
.....###.........#................#............#...#.............................#.....#..#.......#.
.......#.......#.........#....#....##.............
.............#..##.#.......#.....#...#.........#.#
.#................#..#........#...............#..#
.....#.......#...........#.....#.....#......#.....
.#.#......#..#..........#.....#...#.#.............
.......##....#............#..#..............#.....
.#.........#..........#.......#........#..........
...#.....#.#.#..........##...................#....
.#..#..#..#...#.#....#.......#.................#..
........#......#......#..#..#.....#.....#..#......
..................................................
..................................................
.#..#.............#.........#....#..###...........
#.#....#......................#.#....#...........#
..................#..................#....#.......
...........#.........#....#..#...#................
#...........#..........#............#....#.#......
.#....##.....#......#.............................
....#.....#........#......#..#................#.#.
...#............#....#.#........................#.
..#..................#............................
....#.....#.................#......##.............
......................#...........................
#......#.#........#...........#.....#.............
...#................#............#..#..#......#..#
..............##................#.#......##.......
.................#....#.#.#..#.......#........#...
.......#........#......##...........#......#......
.#...............#....#...........#.#.............
....#..............##.#.....#....#.#...........#..
.......................##.....#...#..............#
..#..............................#.....#.......#..
...#......##..#...#........#..#...................
#.................................................
........#.................#...#.........##........
#..............................#..#...............
........#..#...#.....##.#........#....#..........#
#...#......#...............#..................#...
....................#.....#...................#...
.......#.......####...............................
.##...........#......#.........##.................
.#..#.............#.#...................#..##.....
........#...#...#........#.....##.................
.....#....................#.......................
......................#...........................
..........#.....#........##....#....#.............
........#............#................#...........
..#....................................#........#.
..............##.#......#...............##.#.#....
....#...#.#.#.................##.............#....

42L16R50R47L35L8L9L30L12R41L5R42L31R30L36R37L8R16R12L43L27R15R18L18L38R39R2L22R17L34R12L32L50R37L9R22L36R4L35R29L26R15L34L4L32R1R12L30R38R30L40L20L47L46R29L21R48L23L34R41L18R36R47R16L31R8L20L24L29R26L2R23L46L48L33R46R47L15R39L38L15L3R36L39L40L5L30R27R42L12L3R42L1R28R42L50R8R15R39L29L38R10L37R49L25L45R3L44R29L16R30L48L29L22L42R44L36R12R38R44R29L18L37R39L47L4L49L18R32R34L45L15R11R28L21R35L20L40L8L2R16L21L30R9R21L44L33R40L50R15L38R49L40L13L3L5L16L23L26L27L12R41L40R33L15L28L43R16R4R9R7L16R48R4R46L5R29R7R35R17L30L32R37L19L49R45R4L43R28R1L23L33L11R31R30R30R47R25R9R16L43L40L8L9L12R47R32R33R36L8L2L26R29R5R32R11R45R14L31R30L10L16R27R26R10R2R50R37L9L12L13R38R27R21L30L21R37R5L44L1L33R43R5R31R30R11L38L9L35L21R37R7R50L26R18L32R21R45R22R29L40R36L27R15R27R38R27R12R14R23L6L33L4R4L38R17L38R44L33L38L43R14L11L47L18R2R40R26L30R10L5L28L14L23L46L29L1L35L24R33L14R33R29L37R6L49L33R6L37R4L7L33L29R12L28R24L1R20R36L8L34L17L20R41R1R34R3L38R20R35R21L7R34L44L9R39L30R22L36L45L4R49R39R21L22L29R5L5L40L17L40R40R5L45R37R42R42R15L38L17L4R30R5R16R42R12L22R24R12L45R49R49L37R10R16L27L9R19R13R42R46L9L37R47L11L23R19R25L29R28L36L13R24R25L20R12L44L11L42R47L8L20L35R10L49R22L33L25R46L29L19R40R15L24L33R29R48L39R30L25L8L26L26L10L12R50L10L32R6R19R15L48L40L40L33R19L20L9R44R15R22R18L19R26R7L43L38L39L37R11L13R34R36R6R42R8R32R36R17R28R48L20L50R38R43L18L31L49R15L41R31L6R38L33L4L38R49R6L11L16L31L19R18R1R4R16R46L13R23L46L45L11L40L18L21L38L33R22R16L47L10L48R32R16R5L2R21R22R33R32L18L41L40R46R2L29R24L24R14R42L44L24R32R5R16R5L29R40R32L30L19L47R39L48R35R26L47R40L9R47R43R50L1R47R10L43R39L37L24L7R33L38R37R10R39L13L3R4R29R25R10R43R35L40L41R36R31L11L18R14R41R23R32L40R14L45L22L42L38R43R11L43L16R48L1L6R2R2L5L18R21L42R38L10R48L4R32R38L33R16R33L23L29L43R19R41R15L11L1L43R33R49L43R22R20L18L30R18L43R41R6L40L50R6R48R16L27L4L32R27R4R10R13R41L47R30R44L19L28R38R35R5L26R46R10R19L38R40R9R50R43R7R36L29L20R5L16L37L24L46L6L49L2L40L39L18L9R46L42R48L8L47R10R9R48L26R40L23L42L25R30R17R33R4R40R46R23L15R2L47R40L3R18L14L29R9R19L2R12R19R20R2R27L17R5R22R30R10R1L42R48L26R15R18R43R44R23L6L24R35L45L3L8R43L48R50L8R8L19L12R45R29L5L13R20L15R3L33L39L38L30R2R37R31R48R18L13L36R47L37L16L29R38R27R27L27L21R16R50R12R9R36L6L4R48R39L41R5L11L47R22L20L12L26L43R19L34R1R19R44L48R8R32L36R47R8L22L18L48L32R9L42R14R32L35L36R48R42R36L4R42R44L19R1R35L17R48R23R49L27L13L5R5L14L24R35R6L20R2L50L31R16L28R39L36R44R6L1R28L38L22R13R12R46L34L39L44R49R48R8R26L9R17R6L38L26L50L31R18L42L46R15L26R43L8L41L30R33R33R46L37R44L35R1L1R1L15L43L16L33L22L15L32L43R43R30R49R2L26R46R18L2R39R1R28L2L42R42L2L21L41R41L1L3R37R6R21L29R8L26R46L36R22L14L23L12L12L9L42R17R41R26L3L27L25L11L6L32L1R41L11R40R47R35L45R15R38L1L1R28R12R17L43L14R17L17R4L42L46R43L46R41R32L12R22R4L25L23R14L5L43R22L40R4R50R36R24L26R27R15L34R44R1R43R43R7R7L10L4R27L12R29R5L48L26L20R26L9L13L32L48R34L29R33R22L35R42R41R19R37L16R24L33R5L10R14R28L5L46R42L11L16L44R5R27L21L38R36R33R45R10L40R35L37R3L37L37L6R27R41L45L21R1L2L5R15L33R26L14L10L29R32L24L7L9L3R49L32R37R23L10R42L33L16L18L13L34R23R17R46L45L29L18L6R34R29L34L10L27L27L47R27L37R28L10R14R48L19L11R24R24L38L6R23R13R19L11L34L19L23R12L5R26L22R36L16R47L23R24R29R40L43R15R9L2L45L35R32R27L41L45R17L17R17L9L29L22R26L19R47R4L2L23L37R40L3L28R29R9L24L14R50R43L18L19R15L27L46L47L31L50L44L29R14R8R17R12R8R16R35R11R41R11L2L43L35L15L14R10R44R25R45L42L29L27L14R10R30R26L5L23R46R31L43L44R29R22L24L34L14R36R15L16R20R31R4L14R45L24L22R50R10L10L36L35R11R12L29R33R4R18R16R34L44R33R10L5L23R48R19R18L25L23L36R27L1R28R49R43L24L22L40R5L26R22L8R49L48R18R21L43L43L43R26R21R46L21R8L48L5R24R16R27L16R50L41R13R9L7R24R35R23L7R14L16R39L7R22R34R36R3R48L22R22R29L22L27L8L18L30L30L42R42R47R12R49R8L5R5L47L45R7R36L31L39R23L9R18L5L38L49R4R6R22R17R4L34R40R48R23L37L6L43L37R10L30R39L22L11L30L30L24L31L30L34L26L17R39R23L31L24L30R1L23L9R21R40R27R42L24L48R34L15L17R39R11R30R27L28L38L14R26L20L41R20L48L33R41R26L1L34L43L20L12L38L32R8L17L23R46L24R13R29R1R13L33R21R8R36R35R7R24L38L39L27L49L4R28R31L49L45L3R6R17L43R21L8L10L46R17R43R45L12R25R18L41L28L46L38L4R46R22R25L26L11R48L1L10R39R41R13R48L10R40R45R35L45R24R30L29L14L12R9R12L33R13L21R23L22L32L6R34L27L42L31R8L24L23L34L27L37R27R4L20R2L22R17R29L1L25L30R11R6L44R8L14R11L32L28L34L4R17L29R24L20R46R12R14R43R46R11L35R23L12R43L46L35R48L36L25R41R46L33R43R41L32L16L1L25R17R42R44L34R6R37L49R29L21L47L45R39L46L26R2L49L49R7R36R18R39L49L45R45L10R27R13R3L10L17L14R34R22R17L49L34L24R39R37R26L28L24R2R30R40R17R46L27R11L9L20L18L41L5L31R3R45R28R6L32L34L46L4L13L29R50R15R14R26L36R48R12L13R10R29R31R47L49R9L18R50L1L2L46R33L14R21R33L44L18R9L34L39L29L17L49R6R1R41R7R12R45R13R41L24L50L35R21R5R25R2L42L24R42L31R48L4L34R48L15R43L40R30L7R24R47L42L7R44L12L30L24R5R39R26L17L46L14R15L23R4L48L8R37L27L29L24R11L37L18R38L35R8R7R36R22L35R8R18L49R41R46R24R11L47L50L15L38L38L11R39R44L36L2L40L47R39R42R11R35L9R13R36L46R36R22R42R19L20L31R7L21R11L37L6R28R3L26R12L14L47R22L8L24R47R42L29L9R36L46R41L12L2R40L32R34L15R13R21R22L44R48L26L2L47R49R6R33R28R12L39R43L25R33R10R9L14L50R5L10R9L10R46R18L25L17R9R5R4L27R25L2R14L7L48L17L50R3L28R36R47L38L13R49L9R43R5L22L22L50L7R4R5R39R21L24R6L8L42L28L18L41L13R21R20R3L6L7L20R10R33R10R49L18R2L35L16R24R4L9R17R39L44R41L16L17R18R10R35R31R25L43L29R32R4R21L38R5L16L15R11L26R38L14R41R14R4R47R1R5R31R38L7L23L25L8L48R10R46L50L27L24L43R32L28L13R26R40L41L10L14R38R45L10L26L35L17L12R31R48L25R5R26L20R38R28R46L39R36R37L44R4R48L30R24R3L4R23R41R29R29L1L47L36L41R47R20L31R35L10L12R13L37L38R29L31L23L12L47L26L31L49L3R23R48R41L38L31L27L44R26R38R17L18R38R4R9R39L18R3L12R20L1L23L16R30R16L6R44L45R26R2R50L21R15R21R14R4R18R21L1R14L18L13L40R47R3L11R50L50L42L10R32L30L8R35R33L44R50R43R2L1R14L31L32R11R22L5L27L41L43L27L29R17R21R7R12R14R38L45R21L21R48L16R6R30R28R6R16L19L45L17R45R12L20L18L13L23L35R17L39L33L29R32R35L25L28R50L7R46L14L28L20R43R47R32R9R50R47L33R31R25
\ No newline at end of file

A  => day22/problem.txt +66 -0
@@ 1,66 @@
--- Part Two ---
As you reach the force field, you think you hear some Elves in the distance. Perhaps they've already arrived?

You approach the strange input device, but it isn't quite what the monkeys drew in their notes. Instead, you are met with a large cube; each of its six faces is a square of 50x50 tiles.

To be fair, the monkeys' map does have six 50x50 regions on it. If you were to carefully fold the map, you should be able to shape it into a cube!

In the example above, the six (smaller, 4x4) faces of the cube are:

        1111
        1111
        1111
        1111
222233334444
222233334444
222233334444
222233334444
        55556666
        55556666
        55556666
        55556666
You still start in the same position and with the same facing as before, but the wrapping rules are different. Now, if you would walk off the board, you instead proceed around the cube. From the perspective of the map, this can look a little strange. In the above example, if you are at A and move to the right, you would arrive at B facing down; if you are at C and move down, you would arrive at D facing up:

        ...#
        .#..
        #...
        ....
...#.......#
........#..A
..#....#....
.D........#.
        ...#..B.
        .....#..
        .#......
        ..C...#.
Walls still block your path, even if they are on a different face of the cube. If you are at E facing up, your movement is blocked by the wall marked by the arrow:

        ...#
        .#..
     -->#...
        ....
...#..E....#
........#...
..#....#....
..........#.
        ...#....
        .....#..
        .#......
        ......#.
Using the same method of drawing the last facing you had with an arrow on each tile you visit, the full path taken by the above example now looks like this:

        >>v#    
        .#v.    
        #.v.    
        ..v.    
...#..^...v#    
.>>>>>^.#.>>    
.^#....#....    
.^........#.    
        ...#..v.
        .....#v.
        .#v<<<<.
        ..v...#.
The final password is still calculated from your final position and facing from the perspective of the map. In this example, the final row is 5, the final column is 7, and the final facing is 3, so the final password is 1000 * 5 + 4 * 7 + 3 = 5031.

Fold the map into a cube, then follow the path given in the monkeys' notes. What is the final password?

A  => day22/src/main.rs +662 -0
@@ 1,662 @@
#![allow(unused_parens)]

use std::convert::TryInto;
use std::env::args;
use std::fmt::{Display, Formatter, Write};
use std::fs::File;
use std::io::{BufRead, BufReader, Seek};
use std::ops::Range;
use std::process::exit;
use std::str::FromStr;

// -------------------------------------------------------------------------------------------------

const FACE_DIM:       usize = 50;
const NUM_FACES:      usize = 6;
const FACES_PER_LINE: usize = 3;
const DEBUG:          bool  = false;

// -------------------------------------------------------------------------------------------------

enum Mode {
    Part1,
    Part2,
}

// -------------------------------------------------------------------------------------------------

#[derive(Copy, Clone, PartialEq)]
enum Dir {
    N,
    S,
    E,
    W,
}

impl Dir {
    fn apply_rot(&self, rot: &Rot) -> Dir {
        use Dir::*;
        match rot {
            Rot(N) => *self,
            Rot(S) => match self {
                N => S,
                S => N,
                E => W,
                W => E,
            },
            Rot(E) => match self {
                N => E,
                S => W,
                E => S,
                W => W
            },
            Rot(W) => match self {
                N => W,
                S => E,
                E => N,
                W => S
            }
        }
    }

    fn value(&self) -> i32 {
        use Dir::*;
        match self {
            N => 3,
            S => 1,
            E => 0,
            W => 2
        }
    }
}

impl Display for Dir {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        use Dir::*;
        let c = match self {
            N => '∧',
            S => '∨',
            E => '>',
            W => '<'
        };
        f.write_char(c)
    }
}

#[derive(Copy, Clone, PartialEq)]
struct Rot(Dir);

// -------------------------------------------------------------------------------------------------

#[derive(Copy, Clone, PartialEq)]
struct Pos {
    x: i32,
    y: i32,
}

impl Pos {
    fn apply_dir(&self, d: &Dir) -> Pos {
        use Dir::*;
        match d {
            N => Pos { x: self.x, y: self.y - 1 },
            S => Pos { x: self.x, y: self.y + 1 },
            E => Pos { x: self.x + 1, y: self.y },
            W => Pos { x: self.x - 1, y: self.y },
        }
    }

    fn apply_rot(&self, rot: &Rot, face_dim: i32) -> Pos {
        use Dir::*;
        match rot {
            Rot(N) => *self,
            Rot(S) => Pos { x: face_dim - 1 - self.x, y: face_dim - 1 - self.y },
            Rot(E) => Pos { x: face_dim - 1 - self.y, y: self.x },
            Rot(W) => Pos { x: self.y, y: face_dim - 1 - self.x },
        }
    }
}

#[derive(Copy, Clone, PartialEq)]
struct GlobalPos {
    face_id:    FaceID,
    local:      Pos,
    dir:        Dir,
}

// -------------------------------------------------------------------------------------------------

#[derive(Copy, Clone, Debug)]
enum Tile {
    Open,
    Wall,
}

impl Tile {
    fn from_char(c: char) -> Option<Self> {
        use Tile::*;
        match c {
            '.' => Some(Open),
            '#' => Some(Wall),
            _   => None
        }
    }
}

impl Display for Tile {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        use Tile::*;
        let c = match self {
            Open => '.',
            Wall => '#'
        };

        f.write_char(c)
    }
}

// -------------------------------------------------------------------------------------------------

#[derive(Clone, Debug)]
struct InputRange {
    h: Range<usize>,
    v: Range<usize>,
}

impl InputRange {
    fn new(h: Range<usize>, v: Range<usize>) -> Self {
        Self { h, v }
    }
}

// -------------------------------------------------------------------------------------------------

#[derive(Copy, Clone)]
enum Turn {
    R,
    L,
}

impl Turn {
    fn from_char(c: char) -> Option<Self> {
        use Turn::*;
        match c {
            'R' => Some(R),
            'L' => Some(L),
            _   => None
        }
    }
}

// -------------------------------------------------------------------------------------------------

#[derive(Copy, Clone)]
enum Instr {
    Move    (u64),
    Turn    (Turn),
}

// -------------------------------------------------------------------------------------------------

#[derive(Copy, Clone, Debug, PartialEq)]
struct FaceID(u8);

#[derive(Clone, Debug)]
struct Face {
    id:          FaceID,
    input_range: InputRange,
    tiles:       [[Tile; FACE_DIM]; FACE_DIM],
}

impl Face {
    fn parse(s: &String, id: FaceID) -> Self {
        let input_range = Self::input_range(id);
        let mut tiles = [[Tile::Open; FACE_DIM]; FACE_DIM];

        for y in 0..FACE_DIM {
            for x in 0..FACE_DIM {
                let input_x = input_range.h.start + x;
                let input_y = input_range.v.start + y;
                let char_idx = (input_y * FACE_DIM * FACES_PER_LINE) + input_x;

                let c = s.as_bytes()[char_idx] as char;
                let tile = Tile::from_char(c).expect("invalid input");

                tiles[y][x] = tile;
            }
        }

        Self {
            id,
            input_range,
            tiles
        }
    }

    fn input_range(id: FaceID) -> InputRange {
        let (horiz, vert) = match id {
            FaceID(1) => (50..100,   0..50),
            FaceID(2) => (100..150,  0..50),
            FaceID(3) => (50..100,   50..100),
            FaceID(4) => (50..100,   100..150),
            FaceID(5) => (0..50,     100..150),
            FaceID(6) => (0..50,     150..200),
            _ => unreachable!()
        };

        InputRange::new(horiz, vert)
    }

    fn tile(&self, p: &Pos) -> Tile {
        let (col, row) = (p.x as usize, p.y as usize);