Logic games in APL: Save the cow

Source code

mat ← 10 10⍴0
mat[1;]  ← 0 0 0 0 0 0 0 0 0 1
mat[2;]  ← 0 0 0 0 0 0 0 0 0 0
mat[3;]  ← 0 0 0 0 0 0 0 0 0 1
mat[4;]  ← 0 0 0 1 0 0 1 0 0 0
mat[5;]  ← 0 0 0 1 0 0 0 0 0 0
mat[6;]  ← 0 0 0 0 0 0 0 1 1 0
mat[7;]  ← 1 0 0 0 0 0 1 1 1 0
mat[8;]  ← 1 0 0 1 1 0 0 1 0 0
mat[9;]  ← 0 0 0 1 0 0 0 0 0 0
mat[10;] ← 0 0 0 0 0 0 0 0 1 0

∇ z ← y f m;l;pi;pl;na;ok;ls
  pl ← ⍸0=m
  pi ← 1↑pl
  ls ← {⍵/⍨~1∊¨×⍵}pi-cows,⊂1+,⍨dim
  :If 0≠≢ls
      l ← {(⊃⍵)+⍳|-/⍵}{⍵[2⍴⍋⍵]}⌈/¨|ls
      l ← {⍵/⍨∧/¨dim≥¯1+pi+⍵}l
      na ← {pi+¯1+⍳,⍨⍵}¨l
      ok ← {⍵/⍨~1∊¨(⊂0≠m)∧⍵}{⍵∊⍨⍳,⍨dim}¨na
      z ← (⊂m)+y×ok
  :EndIf
∇

solver ← {⊃{⍵/⍨~0∊¨⍵}⊃{⊃,/⍺ f¨⍵}/(⌽⍳⍴cows←⍸⍵),⊂⊂(0⍴⍨⍴)⍵⊣dim←≢⍵}