Skip to content

Instantly share code, notes, and snippets.

@Sheeo
Created March 21, 2012 18:50
Show Gist options
  • Save Sheeo/2151173 to your computer and use it in GitHub Desktop.
Save Sheeo/2151173 to your computer and use it in GitHub Desktop.
let printMatrixRec2((mat : int[][])) =
let rec iterate r c =
match r, c with
| m,n when n = mat.[m].Length-1 && m = mat.Length-1 -> printf " %d" mat.[m].[n]; () // Base case, last entry: Stop recursion when r,c are at bounds of Mat int[][] array
| m,n when n = mat.[m].Length-1 -> printf " %d\n" mat.[m].[n]; iterate (m+1) 0 // Special case: last column of row m, print special and iterate next row
| m,n when n=0 -> printf "%d " mat.[m].[n]; iterate m (n+1) // Special case: first column of m
| m,n -> printf " %d " mat.[m].[n]; iterate m (n+1) // Normal case: entry m,n
iterate 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment