/
day13.ua
45 lines (41 loc) · 1.13 KB
/
day13.ua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
I ← &fras "input.txt"
$ #.##..##.
$ ..#.##.#.
$ ##......#
$ ##......#
$ ..#.##.#.
$ ..##..##.
$ #.#.##.#.
$
$ #...##..#
$ #....#..#
$ ..##..###
$ #####.##.
$ #####.##.
$ ..##..###
$ #....#..#
II ←
PP ← ⊜□¬↥⊃∘(↻¯1)⌕"\n\n". # separate blocks
P ← =@#⊜∘≠@\n. # parse block into bitmask matrix
# S! takes the whole input and a reducing scoring function
S! ← (
PP # get blocks
≡(
# for every block
⊃∘⍉⊐P # get bitmask and its transpose
∩(
# for bitmask and transpose
⊠(/+=0=). # cross with itself to determine num of per-row differences
⍜⍉≡/+⇡△. # get indices of elements in anti-diagonals
⊕^1∩♭ # extract anti-diagonals with reducing transformation
°¤↘1⍉↯¯1_2 # throw away odd-numbered diagonals (since reflection has to be in-between rows)
×⊃∊(+1⊗)1 # get index of matching row pair
)
+×100 # calc final score
)
/+ # sum across blocks
)
S!(/×=0) I # reflection with no differences
&p $"Part 1: _"
S!(=2/+) I # reflection with single difference (2 because symmetrical matrix)
&p $"Part 2: _"