tubular

transpose/2

Mar 19th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.37 KB | None | 0 0
  1. % transpose/2
  2. transpose([[]|_], []).
  3. transpose(I, [O|Os]) :- transpose(I, O, R), transpose(R, Os).
  4.  
  5. % transpose/3
  6. transpose([], [], []).
  7. transpose([[L|Ls]|I], [L|O], [Ls|R]) :- transpose(I, O, R).
  8.  
  9. % /3 peels off the leftmost column and returns the two pieces
  10. % i.e. [[1,2,3],[4,5,6],[7,8,9]] -> [1,4,7] and [[2,3],[5,6],[8,9]]
  11. % /2 makes a list of the peels from /3
Advertisement
Add Comment
Please, Sign In to add comment