M is [0 0 0 0 0 0; 0 0 1 0 0 0; 0 1 0 0 0 0; 0 1 1 1 1 0; 0 0 0 0 0 0] gen M where gen x is f x (adj x) where (f x y is (x&2=y)|3=y) where adj x is +/[r'r x;r'l x;l'r x;l'l x;l'x;r'x;r x;l x] where (r is -1!) where l is 1! gen M where gen x is f x (adj x) where (f x y is (x&2=y)|3=y) where adj x is +/[-1!'-1!x;-1!'1!x;1!'-1!x;1!'1!x;1!'x;-1!'x;-1!x;1!x] \ gen:{(x&2=k)|3=k:+/adj x} adj:{(r'r@;r'l@;l'r@;l'l@;l';r';r:-1!;l:1!)@\:x}