-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay05.apln
56 lines (50 loc) · 1.49 KB
/
Day05.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
:Namespace Day05
Silver←{
⍝ f1: ≥3 vowels ⋄ f2: dupe letter ⋄ f3: no ab,cd,pq,xy
F1←3≤1⊥∊∘'aeiou'
F2←∨/2=/⊢
F3←∧/2{~'ab' 'cd' 'pq' 'xy'∊⍨⊂⍺,⍵}/⊢
(F1∧F2∧F3)⍵
}
Gold←{
⍝ Pair appearing at least twice: self-index - first index ≥ 2
pairs←2,/⍵
p1←2≤⌈/(⍳≢pairs)-⍳⍨pairs
⍝ A char appearing twice with one char between
⍝ first = last on chunks of 3
p2←∨/{(⊃⍵)=⊃⌽⍵}¨3,/⍵
p1∧p2
}
SilverTest←{
f←⍺⍺
Assert←#.U.Assert
Assert 1≡f'ugknbfddgicrmopn':
Assert 1≡f'aaa':
Assert 0≡f'jchzalrnumimnmhp':
Assert 0≡f'haegwjzuvuyypxyu':
Assert 0≡f'dvszwmarrgswjxmb':
'All tests passed'
}
GoldTest←{
f←⍺⍺
Assert←#.U.Assert
Assert 1≡f'qjhvhtzxzqqjkmpb':
Assert 1≡f'xxyxx':
Assert 1≡f'xxxx':
Assert 0≡f'uurcxstgmygtbstg':
Assert 0≡f'ieodomkazucvgmuy':
'All tests passed'
}
∇ r←Data
r←#.U.ReadLines'input/2015/5.txt'
∇
Solve←{ ⍝ Apply to each row and sum
+/⍺⍺¨⍵
}
∇ TestAll
' Silver Test: ',Silver SilverTest 0
' Gold Test: ',Gold GoldTest 0
'Silver Solution: ',⍕Silver Solve Data
' Gold Solution: ',⍕Gold Solve Data
∇
:EndNamespace