Created
March 21, 2012 18:50
-
-
Save Sheeo/2151173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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