solve 2020 d11 and d12
This commit is contained in:
parent
58d1719ee9
commit
1c618df84c
99
data/2020/11.txt
Normal file
99
data/2020/11.txt
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLLLLLLLL.LL.LLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLL.LLLL.L.LLLLLLLLLL.LLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLLL..LLLLL.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLL.LL.LL.LLLLL.L.LLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLL.LLL.LL.LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLL.L.LLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLL.LL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLLL.LLLLL.LLLLLLL.LLLL.L.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
.L.LL...LLLL.......L....L.LLLLLL.......LL....LL...L..L.LLL...LLL..L.L.L.L..L...............L
|
||||||
|
LLLLLLLLLL.LL.LLL.LLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLLL.LLLLLLLLLLLL.LLLLL.LLLL.LLLLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLL..LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLL.LL.LLL.LLLLLLLLLLLLL.L.LLLLLLL.LLLLL.LLLLLLL.LLLLLL..LLLLLL.LLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
.......L.LLL........LL.L....L.LL...L.....L..LL......L.....L....L.LLLL...L....L..L.L........L
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLL.L.LLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLLLLLLLL.LL.LLLL.LLLLL.LLLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||||
|
..L...L.........LL.LLLL...L...LL.L.L..L...L.L...LL..LL...L....L....LL.L...LLL........LLL....
|
||||||
|
LLLLLLLL.L.LLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLL.LLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLL.LL.LLLLLLLLLLL.LLLLLL.LLLLLL.LL.LLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LL.LLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||||
|
L..L...........L....L.LLLL........L..LL....L.L.......L.L.L.....LL......L.....LLL.LL.L.L.LL.L
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLL.LLLLL..LLLLLL.LLLLLLLLLLL.LLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLLLLL.LLL.LLLLL.LLLLLL..LLLLL.LLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL
|
||||||
|
..L.....LLL.L..L...L......LL......L.......LL..L.L.L.L....LLLL....L....L...LL...LLL.L....LLL.
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLLL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
|
LLLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.L.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLL.LL.LLLLLLLLLLLLL.LLLLLLLLLL.
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLL.L.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.L.LLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLL.L
|
||||||
|
.L....LL....L....L.L....L......LL.....L..L.L....LL.......L......L.L..L.......L....L.LLL....L
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLLLLLLLL..LLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
.L......L....L.L..L....LL.......L.LL..LL.L.....L..L.L...............LL....L...L....L....L.LL
|
||||||
|
LLLLLLLLL..LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL..LLLLLLLLL.LLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLL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LLLLLL..LLLLL.LLLLLLLLLL.LLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLL.L.L.LLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLL.LLLLLLLLLLLLL
|
||||||
|
LLLLL....L.LL..LLL.L...LL.....L............L...............L..L.LLLLL.L.L.......L..LL.L...L.
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLL..LLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLLLL.LLL.LL.LLLLLL..LLLLL.LLLLLL.L.LLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL.L.LLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLL
|
||||||
|
.....L...L......L...LL.L.......LL.L...LL..LL.....L.......LL.LL......LL.L...L..L..L...L.LLL..
|
||||||
|
LLLLLLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLL.LLLLLL.LLLLLL..LLLLLLLLLL
|
||||||
|
LLLLLL.LLL.LLLLLL.LLLLLL.LL.LL.LLLLLLL.LLLLL.LLLLLLL.LLLLLL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LLL.LLLL.LLLLLL.LLLLLLLLLL.LLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLL..LLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLL.LLLLLLLLLLL
|
||||||
|
LLLLLLLLLL.LLL.LLLLLLLLL.LLLLL.LLLLLLLLLLLL..LLLLLLL.LLLLL..LLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
|
||||||
|
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLL.LL.LLLLLLLLLL.LLLLLLLLLLL
|
774
data/2020/12.txt
Normal file
774
data/2020/12.txt
Normal file
|
@ -0,0 +1,774 @@
|
||||||
|
F41
|
||||||
|
N2
|
||||||
|
L270
|
||||||
|
S3
|
||||||
|
F85
|
||||||
|
R90
|
||||||
|
E4
|
||||||
|
R180
|
||||||
|
E4
|
||||||
|
L90
|
||||||
|
F78
|
||||||
|
R270
|
||||||
|
F63
|
||||||
|
W2
|
||||||
|
R90
|
||||||
|
F40
|
||||||
|
R90
|
||||||
|
E3
|
||||||
|
S4
|
||||||
|
F44
|
||||||
|
W3
|
||||||
|
F6
|
||||||
|
S3
|
||||||
|
F21
|
||||||
|
N1
|
||||||
|
F47
|
||||||
|
L180
|
||||||
|
F96
|
||||||
|
S5
|
||||||
|
F7
|
||||||
|
S4
|
||||||
|
E4
|
||||||
|
S2
|
||||||
|
F46
|
||||||
|
L90
|
||||||
|
R180
|
||||||
|
W4
|
||||||
|
N4
|
||||||
|
F11
|
||||||
|
N3
|
||||||
|
W1
|
||||||
|
F51
|
||||||
|
S4
|
||||||
|
L90
|
||||||
|
W4
|
||||||
|
F93
|
||||||
|
R90
|
||||||
|
N3
|
||||||
|
R180
|
||||||
|
F66
|
||||||
|
W3
|
||||||
|
F93
|
||||||
|
W4
|
||||||
|
F20
|
||||||
|
W5
|
||||||
|
S4
|
||||||
|
E4
|
||||||
|
S4
|
||||||
|
E2
|
||||||
|
S3
|
||||||
|
L90
|
||||||
|
N5
|
||||||
|
F93
|
||||||
|
E5
|
||||||
|
N2
|
||||||
|
F50
|
||||||
|
L270
|
||||||
|
F10
|
||||||
|
W4
|
||||||
|
L180
|
||||||
|
N4
|
||||||
|
E2
|
||||||
|
S5
|
||||||
|
F17
|
||||||
|
E1
|
||||||
|
N5
|
||||||
|
F99
|
||||||
|
R90
|
||||||
|
F47
|
||||||
|
R180
|
||||||
|
F43
|
||||||
|
W3
|
||||||
|
L90
|
||||||
|
E3
|
||||||
|
N3
|
||||||
|
E5
|
||||||
|
S1
|
||||||
|
F89
|
||||||
|
W5
|
||||||
|
F73
|
||||||
|
R180
|
||||||
|
S3
|
||||||
|
L90
|
||||||
|
F81
|
||||||
|
N4
|
||||||
|
F17
|
||||||
|
L180
|
||||||
|
W2
|
||||||
|
F56
|
||||||
|
W5
|
||||||
|
N1
|
||||||
|
F81
|
||||||
|
S1
|
||||||
|
F7
|
||||||
|
S3
|
||||||
|
E4
|
||||||
|
F26
|
||||||
|
S2
|
||||||
|
W2
|
||||||
|
F71
|
||||||
|
W5
|
||||||
|
F10
|
||||||
|
L180
|
||||||
|
F3
|
||||||
|
E1
|
||||||
|
L90
|
||||||
|
F54
|
||||||
|
E5
|
||||||
|
N4
|
||||||
|
R90
|
||||||
|
F81
|
||||||
|
W3
|
||||||
|
F73
|
||||||
|
N5
|
||||||
|
F38
|
||||||
|
S1
|
||||||
|
L90
|
||||||
|
N1
|
||||||
|
L270
|
||||||
|
F51
|
||||||
|
R90
|
||||||
|
N2
|
||||||
|
E1
|
||||||
|
L90
|
||||||
|
F12
|
||||||
|
L90
|
||||||
|
E2
|
||||||
|
F69
|
||||||
|
S5
|
||||||
|
L90
|
||||||
|
F17
|
||||||
|
L90
|
||||||
|
W4
|
||||||
|
S4
|
||||||
|
L90
|
||||||
|
R90
|
||||||
|
F80
|
||||||
|
W5
|
||||||
|
N1
|
||||||
|
W2
|
||||||
|
F16
|
||||||
|
S5
|
||||||
|
F66
|
||||||
|
E3
|
||||||
|
F39
|
||||||
|
W4
|
||||||
|
F89
|
||||||
|
N5
|
||||||
|
W1
|
||||||
|
F37
|
||||||
|
N4
|
||||||
|
E4
|
||||||
|
R270
|
||||||
|
E2
|
||||||
|
L90
|
||||||
|
W2
|
||||||
|
F99
|
||||||
|
N3
|
||||||
|
E5
|
||||||
|
N2
|
||||||
|
F38
|
||||||
|
W4
|
||||||
|
S5
|
||||||
|
L180
|
||||||
|
F9
|
||||||
|
S4
|
||||||
|
W1
|
||||||
|
F8
|
||||||
|
W5
|
||||||
|
L90
|
||||||
|
W3
|
||||||
|
F60
|
||||||
|
W2
|
||||||
|
N5
|
||||||
|
F41
|
||||||
|
W2
|
||||||
|
L90
|
||||||
|
F75
|
||||||
|
N4
|
||||||
|
L90
|
||||||
|
N4
|
||||||
|
F5
|
||||||
|
W3
|
||||||
|
S2
|
||||||
|
F22
|
||||||
|
R90
|
||||||
|
S2
|
||||||
|
W4
|
||||||
|
F61
|
||||||
|
S1
|
||||||
|
L90
|
||||||
|
N1
|
||||||
|
L90
|
||||||
|
W4
|
||||||
|
S1
|
||||||
|
W3
|
||||||
|
S2
|
||||||
|
F94
|
||||||
|
E3
|
||||||
|
N4
|
||||||
|
F41
|
||||||
|
N1
|
||||||
|
W3
|
||||||
|
N4
|
||||||
|
R180
|
||||||
|
E4
|
||||||
|
F90
|
||||||
|
W1
|
||||||
|
S1
|
||||||
|
E5
|
||||||
|
N5
|
||||||
|
R90
|
||||||
|
W3
|
||||||
|
S1
|
||||||
|
F42
|
||||||
|
R90
|
||||||
|
F18
|
||||||
|
S4
|
||||||
|
E2
|
||||||
|
R180
|
||||||
|
E5
|
||||||
|
N2
|
||||||
|
F70
|
||||||
|
W5
|
||||||
|
F39
|
||||||
|
N3
|
||||||
|
W1
|
||||||
|
N5
|
||||||
|
W2
|
||||||
|
L90
|
||||||
|
N5
|
||||||
|
L90
|
||||||
|
S4
|
||||||
|
W2
|
||||||
|
L180
|
||||||
|
F62
|
||||||
|
S1
|
||||||
|
E4
|
||||||
|
F89
|
||||||
|
S2
|
||||||
|
W5
|
||||||
|
W4
|
||||||
|
S1
|
||||||
|
F86
|
||||||
|
F12
|
||||||
|
N5
|
||||||
|
F76
|
||||||
|
S2
|
||||||
|
W5
|
||||||
|
F32
|
||||||
|
R90
|
||||||
|
W2
|
||||||
|
F81
|
||||||
|
R90
|
||||||
|
W5
|
||||||
|
F6
|
||||||
|
S3
|
||||||
|
W5
|
||||||
|
F21
|
||||||
|
E4
|
||||||
|
F11
|
||||||
|
R90
|
||||||
|
S5
|
||||||
|
N5
|
||||||
|
W3
|
||||||
|
L180
|
||||||
|
W4
|
||||||
|
N4
|
||||||
|
L180
|
||||||
|
E2
|
||||||
|
F71
|
||||||
|
L90
|
||||||
|
E3
|
||||||
|
N5
|
||||||
|
R90
|
||||||
|
W3
|
||||||
|
R90
|
||||||
|
F1
|
||||||
|
W3
|
||||||
|
F67
|
||||||
|
R90
|
||||||
|
N5
|
||||||
|
F64
|
||||||
|
R90
|
||||||
|
N4
|
||||||
|
F2
|
||||||
|
E3
|
||||||
|
N4
|
||||||
|
R90
|
||||||
|
S2
|
||||||
|
F73
|
||||||
|
W4
|
||||||
|
R180
|
||||||
|
S5
|
||||||
|
L90
|
||||||
|
W4
|
||||||
|
F60
|
||||||
|
R90
|
||||||
|
W1
|
||||||
|
N5
|
||||||
|
F44
|
||||||
|
R90
|
||||||
|
S5
|
||||||
|
E3
|
||||||
|
F74
|
||||||
|
N5
|
||||||
|
F92
|
||||||
|
W3
|
||||||
|
R90
|
||||||
|
F65
|
||||||
|
N3
|
||||||
|
E3
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
F43
|
||||||
|
R90
|
||||||
|
F53
|
||||||
|
N5
|
||||||
|
L90
|
||||||
|
F75
|
||||||
|
W2
|
||||||
|
R90
|
||||||
|
F66
|
||||||
|
N4
|
||||||
|
F25
|
||||||
|
R180
|
||||||
|
N2
|
||||||
|
W5
|
||||||
|
F57
|
||||||
|
E4
|
||||||
|
F77
|
||||||
|
E5
|
||||||
|
R90
|
||||||
|
S5
|
||||||
|
F99
|
||||||
|
N3
|
||||||
|
F54
|
||||||
|
N5
|
||||||
|
F37
|
||||||
|
E5
|
||||||
|
F48
|
||||||
|
S1
|
||||||
|
F17
|
||||||
|
F49
|
||||||
|
L180
|
||||||
|
S2
|
||||||
|
R180
|
||||||
|
N3
|
||||||
|
L180
|
||||||
|
F100
|
||||||
|
E4
|
||||||
|
R90
|
||||||
|
E3
|
||||||
|
R90
|
||||||
|
F49
|
||||||
|
L180
|
||||||
|
W4
|
||||||
|
S3
|
||||||
|
E2
|
||||||
|
L90
|
||||||
|
N4
|
||||||
|
S3
|
||||||
|
F60
|
||||||
|
S5
|
||||||
|
F86
|
||||||
|
L90
|
||||||
|
E5
|
||||||
|
L180
|
||||||
|
F96
|
||||||
|
L90
|
||||||
|
W4
|
||||||
|
F30
|
||||||
|
S1
|
||||||
|
F31
|
||||||
|
S4
|
||||||
|
F78
|
||||||
|
E3
|
||||||
|
F51
|
||||||
|
S2
|
||||||
|
E5
|
||||||
|
S4
|
||||||
|
F5
|
||||||
|
S1
|
||||||
|
F45
|
||||||
|
R90
|
||||||
|
W2
|
||||||
|
S3
|
||||||
|
E5
|
||||||
|
F46
|
||||||
|
E4
|
||||||
|
R180
|
||||||
|
F9
|
||||||
|
W1
|
||||||
|
S5
|
||||||
|
W4
|
||||||
|
S1
|
||||||
|
R90
|
||||||
|
N1
|
||||||
|
W5
|
||||||
|
F87
|
||||||
|
N3
|
||||||
|
W2
|
||||||
|
F10
|
||||||
|
W1
|
||||||
|
L90
|
||||||
|
F34
|
||||||
|
S1
|
||||||
|
E2
|
||||||
|
L270
|
||||||
|
F98
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
F48
|
||||||
|
S4
|
||||||
|
F54
|
||||||
|
R90
|
||||||
|
N3
|
||||||
|
W3
|
||||||
|
R90
|
||||||
|
E4
|
||||||
|
S4
|
||||||
|
F93
|
||||||
|
N1
|
||||||
|
E2
|
||||||
|
F42
|
||||||
|
W4
|
||||||
|
L90
|
||||||
|
F29
|
||||||
|
E2
|
||||||
|
F51
|
||||||
|
S2
|
||||||
|
L90
|
||||||
|
F60
|
||||||
|
S4
|
||||||
|
R90
|
||||||
|
L90
|
||||||
|
S1
|
||||||
|
F58
|
||||||
|
S4
|
||||||
|
F81
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
S1
|
||||||
|
F28
|
||||||
|
S3
|
||||||
|
W5
|
||||||
|
F50
|
||||||
|
L180
|
||||||
|
S4
|
||||||
|
E4
|
||||||
|
F3
|
||||||
|
E2
|
||||||
|
R90
|
||||||
|
W4
|
||||||
|
F21
|
||||||
|
E2
|
||||||
|
S4
|
||||||
|
F99
|
||||||
|
N2
|
||||||
|
W1
|
||||||
|
F42
|
||||||
|
R180
|
||||||
|
S1
|
||||||
|
F9
|
||||||
|
L90
|
||||||
|
S4
|
||||||
|
W3
|
||||||
|
L90
|
||||||
|
F61
|
||||||
|
L90
|
||||||
|
F80
|
||||||
|
E2
|
||||||
|
N4
|
||||||
|
E1
|
||||||
|
R90
|
||||||
|
F62
|
||||||
|
W1
|
||||||
|
F59
|
||||||
|
R90
|
||||||
|
W4
|
||||||
|
N3
|
||||||
|
W1
|
||||||
|
L180
|
||||||
|
E2
|
||||||
|
R90
|
||||||
|
S1
|
||||||
|
F24
|
||||||
|
N1
|
||||||
|
R180
|
||||||
|
W5
|
||||||
|
F26
|
||||||
|
E4
|
||||||
|
N4
|
||||||
|
R90
|
||||||
|
E1
|
||||||
|
F19
|
||||||
|
W3
|
||||||
|
S2
|
||||||
|
L180
|
||||||
|
F18
|
||||||
|
L90
|
||||||
|
W2
|
||||||
|
F91
|
||||||
|
R90
|
||||||
|
E3
|
||||||
|
F88
|
||||||
|
N4
|
||||||
|
W4
|
||||||
|
F13
|
||||||
|
W4
|
||||||
|
F66
|
||||||
|
R90
|
||||||
|
E3
|
||||||
|
F33
|
||||||
|
L90
|
||||||
|
F24
|
||||||
|
L90
|
||||||
|
F17
|
||||||
|
S2
|
||||||
|
E1
|
||||||
|
F47
|
||||||
|
S4
|
||||||
|
F61
|
||||||
|
S3
|
||||||
|
R270
|
||||||
|
W1
|
||||||
|
L180
|
||||||
|
N2
|
||||||
|
E1
|
||||||
|
L90
|
||||||
|
F42
|
||||||
|
E3
|
||||||
|
R180
|
||||||
|
F58
|
||||||
|
W3
|
||||||
|
R90
|
||||||
|
W4
|
||||||
|
S3
|
||||||
|
F54
|
||||||
|
N3
|
||||||
|
L90
|
||||||
|
F49
|
||||||
|
L90
|
||||||
|
F49
|
||||||
|
E2
|
||||||
|
S3
|
||||||
|
F76
|
||||||
|
W2
|
||||||
|
N2
|
||||||
|
R90
|
||||||
|
F20
|
||||||
|
N4
|
||||||
|
R180
|
||||||
|
F34
|
||||||
|
N2
|
||||||
|
F44
|
||||||
|
W5
|
||||||
|
N3
|
||||||
|
F50
|
||||||
|
R180
|
||||||
|
F13
|
||||||
|
L90
|
||||||
|
F76
|
||||||
|
R270
|
||||||
|
F18
|
||||||
|
N2
|
||||||
|
F12
|
||||||
|
L90
|
||||||
|
W1
|
||||||
|
S5
|
||||||
|
L180
|
||||||
|
F72
|
||||||
|
N3
|
||||||
|
E3
|
||||||
|
W4
|
||||||
|
F36
|
||||||
|
E4
|
||||||
|
F74
|
||||||
|
S5
|
||||||
|
R90
|
||||||
|
F86
|
||||||
|
L90
|
||||||
|
F63
|
||||||
|
L90
|
||||||
|
S2
|
||||||
|
W4
|
||||||
|
F63
|
||||||
|
N3
|
||||||
|
E3
|
||||||
|
E3
|
||||||
|
S3
|
||||||
|
R90
|
||||||
|
W1
|
||||||
|
S3
|
||||||
|
L90
|
||||||
|
N1
|
||||||
|
E4
|
||||||
|
F4
|
||||||
|
E4
|
||||||
|
R90
|
||||||
|
F82
|
||||||
|
N3
|
||||||
|
F58
|
||||||
|
S5
|
||||||
|
R180
|
||||||
|
N3
|
||||||
|
F98
|
||||||
|
R90
|
||||||
|
R90
|
||||||
|
F29
|
||||||
|
S2
|
||||||
|
R180
|
||||||
|
W5
|
||||||
|
N1
|
||||||
|
F61
|
||||||
|
N3
|
||||||
|
E5
|
||||||
|
S3
|
||||||
|
E2
|
||||||
|
F30
|
||||||
|
N2
|
||||||
|
F66
|
||||||
|
W2
|
||||||
|
N2
|
||||||
|
F32
|
||||||
|
W4
|
||||||
|
R90
|
||||||
|
F2
|
||||||
|
E5
|
||||||
|
F90
|
||||||
|
R90
|
||||||
|
E2
|
||||||
|
R90
|
||||||
|
F7
|
||||||
|
R180
|
||||||
|
N5
|
||||||
|
E1
|
||||||
|
R90
|
||||||
|
S2
|
||||||
|
L90
|
||||||
|
F68
|
||||||
|
W3
|
||||||
|
F84
|
||||||
|
S4
|
||||||
|
E4
|
||||||
|
S4
|
||||||
|
E2
|
||||||
|
L90
|
||||||
|
S3
|
||||||
|
F83
|
||||||
|
R90
|
||||||
|
E4
|
||||||
|
R180
|
||||||
|
S2
|
||||||
|
L90
|
||||||
|
F92
|
||||||
|
F6
|
||||||
|
W5
|
||||||
|
R90
|
||||||
|
F5
|
||||||
|
R270
|
||||||
|
F85
|
||||||
|
E1
|
||||||
|
F9
|
||||||
|
L180
|
||||||
|
N5
|
||||||
|
L90
|
||||||
|
W1
|
||||||
|
N3
|
||||||
|
L90
|
||||||
|
E5
|
||||||
|
F10
|
||||||
|
R180
|
||||||
|
S3
|
||||||
|
W1
|
||||||
|
W1
|
||||||
|
L90
|
||||||
|
E1
|
||||||
|
F24
|
||||||
|
E5
|
||||||
|
F63
|
||||||
|
E4
|
||||||
|
F10
|
||||||
|
E3
|
||||||
|
F73
|
||||||
|
W3
|
||||||
|
F68
|
||||||
|
N5
|
||||||
|
W3
|
||||||
|
F90
|
||||||
|
R90
|
||||||
|
W2
|
||||||
|
F79
|
||||||
|
N5
|
||||||
|
R90
|
||||||
|
F71
|
||||||
|
E4
|
||||||
|
F51
|
||||||
|
E4
|
||||||
|
F11
|
||||||
|
W4
|
||||||
|
R90
|
||||||
|
N5
|
||||||
|
F41
|
||||||
|
L180
|
||||||
|
S4
|
||||||
|
L90
|
||||||
|
F18
|
||||||
|
R90
|
||||||
|
N3
|
||||||
|
W5
|
||||||
|
F38
|
||||||
|
S5
|
||||||
|
F24
|
||||||
|
S2
|
||||||
|
F25
|
||||||
|
W4
|
||||||
|
N2
|
||||||
|
E2
|
||||||
|
F36
|
||||||
|
N2
|
||||||
|
L90
|
||||||
|
F30
|
||||||
|
W1
|
||||||
|
F56
|
||||||
|
L90
|
||||||
|
W5
|
||||||
|
S2
|
||||||
|
E3
|
||||||
|
R90
|
||||||
|
F63
|
||||||
|
W2
|
||||||
|
F63
|
||||||
|
S4
|
||||||
|
W3
|
||||||
|
F81
|
||||||
|
R90
|
||||||
|
S1
|
||||||
|
L270
|
||||||
|
N5
|
||||||
|
L90
|
||||||
|
W2
|
||||||
|
F6
|
||||||
|
W4
|
||||||
|
L180
|
||||||
|
E2
|
||||||
|
L180
|
||||||
|
W3
|
||||||
|
R90
|
||||||
|
S3
|
||||||
|
R90
|
||||||
|
F49
|
||||||
|
N4
|
||||||
|
F23
|
||||||
|
R90
|
||||||
|
W4
|
||||||
|
N5
|
||||||
|
L90
|
||||||
|
F8
|
||||||
|
R90
|
||||||
|
F12
|
||||||
|
E2
|
||||||
|
L180
|
||||||
|
F95
|
132
solutions/2020/11.js
Normal file
132
solutions/2020/11.js
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
const { Glib, Vector, twodee } = require('../../lib');
|
||||||
|
|
||||||
|
const STATE = {
|
||||||
|
EMPTY: 'L',
|
||||||
|
FLOOR: '.',
|
||||||
|
OCCUPIED: '#',
|
||||||
|
NONE: 'X',
|
||||||
|
};
|
||||||
|
|
||||||
|
const step1 = (input) => {
|
||||||
|
let changes = 0n;
|
||||||
|
|
||||||
|
const output = input.glibEntries
|
||||||
|
.map(([pts, state]) => {
|
||||||
|
switch (state) {
|
||||||
|
case STATE.EMPTY:
|
||||||
|
if (
|
||||||
|
Vector.fromString(pts)
|
||||||
|
.neighbors()
|
||||||
|
.map((pt) => pt.string)
|
||||||
|
.lookupInMap(input, true)
|
||||||
|
.filter((neighborState) => neighborState === STATE.OCCUPIED)
|
||||||
|
.length === 0n
|
||||||
|
) {
|
||||||
|
changes++;
|
||||||
|
return [pts, STATE.OCCUPIED];
|
||||||
|
}
|
||||||
|
return [pts, STATE.EMPTY];
|
||||||
|
case STATE.OCCUPIED:
|
||||||
|
if (
|
||||||
|
Vector.fromString(pts)
|
||||||
|
.neighbors()
|
||||||
|
.map((pt) => pt.string)
|
||||||
|
.lookupInMap(input, true)
|
||||||
|
.filter((neighborState) => neighborState === STATE.OCCUPIED)
|
||||||
|
.length >= 4n
|
||||||
|
) {
|
||||||
|
changes++;
|
||||||
|
return [pts, STATE.EMPTY];
|
||||||
|
}
|
||||||
|
return [pts, STATE.OCCUPIED];
|
||||||
|
case STATE.FLOOR:
|
||||||
|
return [pts, STATE.FLOOR];
|
||||||
|
default:
|
||||||
|
console.log(pts, state);
|
||||||
|
throw new Error('invalid state');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toMap();
|
||||||
|
|
||||||
|
return [output, changes];
|
||||||
|
};
|
||||||
|
|
||||||
|
const visibleNeighbor = (point, direction, state) => {
|
||||||
|
let next = point.add(direction);
|
||||||
|
while (true) {
|
||||||
|
const nextString = next.string;
|
||||||
|
if (!state.has(nextString)) {
|
||||||
|
return state.NONE;
|
||||||
|
}
|
||||||
|
const found = state.get(nextString);
|
||||||
|
if (found !== STATE.FLOOR) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
next = next.add(direction);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const step2 = (input) => {
|
||||||
|
let changes = 0n;
|
||||||
|
|
||||||
|
const output = input.glibEntries
|
||||||
|
.map(([pts, state]) => {
|
||||||
|
const pt = Vector.fromString(pts);
|
||||||
|
switch (state) {
|
||||||
|
case STATE.EMPTY:
|
||||||
|
if (
|
||||||
|
twodee.ORIGIN.neighbors()
|
||||||
|
.map((direction) => visibleNeighbor(pt, direction, input))
|
||||||
|
.filter((neighborState) => neighborState === STATE.OCCUPIED)
|
||||||
|
.length === 0n
|
||||||
|
) {
|
||||||
|
changes++;
|
||||||
|
return [pts, STATE.OCCUPIED];
|
||||||
|
}
|
||||||
|
return [pts, STATE.EMPTY];
|
||||||
|
case STATE.OCCUPIED:
|
||||||
|
if (
|
||||||
|
twodee.ORIGIN.neighbors()
|
||||||
|
.map((direction) => visibleNeighbor(pt, direction, input))
|
||||||
|
.filter((neighborState) => neighborState === STATE.OCCUPIED)
|
||||||
|
.length >= 5n
|
||||||
|
) {
|
||||||
|
changes++;
|
||||||
|
return [pts, STATE.EMPTY];
|
||||||
|
}
|
||||||
|
return [pts, STATE.OCCUPIED];
|
||||||
|
case STATE.FLOOR:
|
||||||
|
return [pts, STATE.FLOOR];
|
||||||
|
default:
|
||||||
|
console.log(pts, state);
|
||||||
|
throw new Error('invalid state');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.toMap();
|
||||||
|
|
||||||
|
return [output, changes];
|
||||||
|
};
|
||||||
|
|
||||||
|
const solve = (input, stepFn) => {
|
||||||
|
let state = Glib.fromLines(input)
|
||||||
|
.flatMap((line, y) =>
|
||||||
|
Glib.fromIterable(line).map((cell, x) => [new Vector(x, y).string, cell]),
|
||||||
|
)
|
||||||
|
.toMap();
|
||||||
|
|
||||||
|
// only run 1k iterations, it's a fairly simple automota
|
||||||
|
// I wonder it it's possible to make a glider...
|
||||||
|
for (let i = 0n; i < 1000n; i++) {
|
||||||
|
const [newState, changes] = stepFn(state);
|
||||||
|
if (changes === 0n) {
|
||||||
|
return state.glibValues.filter((e) => e === STATE.OCCUPIED).length;
|
||||||
|
}
|
||||||
|
state = newState;
|
||||||
|
}
|
||||||
|
throw new Error('too many iterations');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
1: (input) => solve(input, step1),
|
||||||
|
2: (input) => solve(input, step2),
|
||||||
|
};
|
122
solutions/2020/12.js
Normal file
122
solutions/2020/12.js
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
const { Glib, Vector, twodee } = require('../../lib');
|
||||||
|
|
||||||
|
const LEFT = new Map([
|
||||||
|
[twodee.DIRECTIONS.UP.string, twodee.DIRECTIONS.LEFT],
|
||||||
|
[twodee.DIRECTIONS.LEFT.string, twodee.DIRECTIONS.DOWN],
|
||||||
|
[twodee.DIRECTIONS.DOWN.string, twodee.DIRECTIONS.RIGHT],
|
||||||
|
[twodee.DIRECTIONS.RIGHT.string, twodee.DIRECTIONS.UP],
|
||||||
|
]);
|
||||||
|
|
||||||
|
const RIGHT = new Map([
|
||||||
|
[twodee.DIRECTIONS.UP.string, twodee.DIRECTIONS.RIGHT],
|
||||||
|
[twodee.DIRECTIONS.RIGHT.string, twodee.DIRECTIONS.DOWN],
|
||||||
|
[twodee.DIRECTIONS.DOWN.string, twodee.DIRECTIONS.LEFT],
|
||||||
|
[twodee.DIRECTIONS.LEFT.string, twodee.DIRECTIONS.UP],
|
||||||
|
]);
|
||||||
|
|
||||||
|
const INSTRUCTIONS1 = {
|
||||||
|
N: (count, state) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
location: state.location.add(twodee.DIRECTIONS.UP.multiply(count)),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
S: (count, state) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
location: state.location.add(twodee.DIRECTIONS.DOWN.multiply(count)),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
E: (count, state) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
location: state.location.add(twodee.DIRECTIONS.RIGHT.multiply(count)),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
W: (count, state) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
location: state.location.add(twodee.DIRECTIONS.LEFT.multiply(count)),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
F: (count, state) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
location: state.location.add(state.direction.multiply(count)),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
L: (count, state) => {
|
||||||
|
let direction = state.direction;
|
||||||
|
for (let i = 0; i < count; i += 90) {
|
||||||
|
direction = LEFT.get(direction.string);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
direction,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
R: (count, state) => {
|
||||||
|
let direction = state.direction;
|
||||||
|
for (let i = 0; i < count; i += 90) {
|
||||||
|
direction = RIGHT.get(direction.string);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
direction,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const INSTRUCTIONS2 = {
|
||||||
|
...INSTRUCTIONS1,
|
||||||
|
F: (count, state) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
ship: state.ship.add(state.location.multiply(count)),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
// todo: (soon) implement a matrix library so this gets better
|
||||||
|
L: (count, state) => {
|
||||||
|
let location = state.location;
|
||||||
|
for (let i = 0; i < count; i += 90) {
|
||||||
|
location = new Vector(-location.v[1], location.v[0]);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
location,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
R: (count, state) => {
|
||||||
|
let location = state.location;
|
||||||
|
for (let i = 0; i < count; i += 90) {
|
||||||
|
location = new Vector(location.v[1], -location.v[0]);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
location,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const solve = (input, ops, start = twodee.ORIGIN) =>
|
||||||
|
Glib.fromLines(input, ops)
|
||||||
|
.map(([instruction, ...number]) => ({
|
||||||
|
instruction,
|
||||||
|
count: BigInt(number.join('')),
|
||||||
|
}))
|
||||||
|
.reduce(
|
||||||
|
(state, { instruction, count }) => {
|
||||||
|
return ops[instruction](count, state);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
location: start,
|
||||||
|
direction: twodee.DIRECTIONS.RIGHT,
|
||||||
|
ship: twodee.ORIGIN,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
1: (input) => solve(input, INSTRUCTIONS1).location.distance(twodee.ORIGIN),
|
||||||
|
2: (input) =>
|
||||||
|
solve(input, INSTRUCTIONS2, new Vector(10, 1)).ship.distance(twodee.ORIGIN),
|
||||||
|
};
|
|
@ -12,6 +12,8 @@ const results = {
|
||||||
8: [1553, 1877],
|
8: [1553, 1877],
|
||||||
9: [1721308972, 209694133],
|
9: [1721308972, 209694133],
|
||||||
10: [2277, 37024595836928],
|
10: [2277, 37024595836928],
|
||||||
|
11: [2359, 2131],
|
||||||
|
12: [508, 30761],
|
||||||
},
|
},
|
||||||
2019: {
|
2019: {
|
||||||
1: [3386686, 5077155],
|
1: [3386686, 5077155],
|
||||||
|
|
Loading…
Reference in a new issue