f=: 1358+([*[+3+2*])+]*1+] o=: [:-2|[:+/#: gen =: [:|:([:i.[)(o@f)"0 0/[:i.] directions =: 4 : 0 d =. 0 2$0 for_xy. (+,-)0 1,:1 0 do. if. 0=x{~<(<:$x)<.0>.y+xy do. d=.d,y+xy end. end. d ) go =: 4 : 0 NB. uses x show tgt to display the maze at the end next =. 0 2$0 [ 'ends tgt cnt p maxp' =. y if. p<:maxp do. cnt =. cnt + #ends end. for_xy. ends do. x=.p (