aboutsummaryrefslogtreecommitdiff
path: root/challenge-042/conor-hoekstra/apl/ch-2.apl
blob: 0e8c692c3df81a51aa9f20c1acda3842a31911bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
isValid  ((0=⊃)0.≤⊢)(+\-)'()'∘.=⊢

⍝ Tests
(isValid,⊢) '()'[?2?10] ⍝ 0 ()))))()(
(isValid,⊢) '()'[?2?10] ⍝ 1 (())
(isValid,⊢) '()'[?2?10] ⍝ 0 (((())
(isValid,⊢) '()'[?2?10] ⍝ 1 ()((()))
(isValid,⊢) '()'[?2?10] ⍝ 0 ((( 

⍝ Tacit Tree Visualization

              isValid
            ┌────┴─────┐  
                   ┌──┼─┐
      ┌─────┴─────┐ () . 
  ┌───┼───┐     ┌─┴─┐ ┌┴┐ 
┌─┼─┐  ┌─┼─┐   \     = 
0 =    0 .  ┌─┘ ┌─┘     
   ┌┴┐   ┌┴┐  +   -