-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay16.apln
37 lines (32 loc) · 1.11 KB
/
Day16.apln
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
:Namespace Day16
Segs←#.U.Segs
Silver←{ ⍝ ⍺←clues, ⍵←aunts, find the index of the real aunt
⍸⍺∘{
1=≢⍺~⍨↓⍵⍴⍨2,⍨0.5×≢⍵ ⍝ length(chunks of 2 ~ clues) = 1
}¨⍵
}
Gold←{ ⍝ ⍺←clues, ⍵←aunts, find the index of the real aunt
(cwords cvals)←↓⍉↑⍺
cvals←⍎¨cvals
⍸{
(awords avals)←↓⍉↑1↓↓⍵⍴⍨2,⍨0.5×≢⍵
avals←⍎¨avals
∧/{
(cval aval)←cvals avals⊃⍨¨cwords awords⍳¨⊂⊂⍵
(⊂⍵)∊'cats' 'trees':cval<aval
(⊂⍵)∊'pomeranians' 'goldfish':cval>aval
cval=aval
}¨awords ⍝ check all items match the clues
}¨⍵
}
∇ r←Clues
r←' :'∘Segs¨#.U.ReadLines'input/2015/16_clues.txt'
∇
∇ r←Data
r←' :,'∘Segs¨#.U.ReadLines'input/2015/16.txt'
∇
∇ TestAll
'Silver Solution: ',⍕Clues Silver Data
' Gold Solution: ',⍕Clues Gold Data
∇
:EndNamespace