Created
March 29, 2016 18:02
-
-
Save alarsyo/efbc8f7f6c3e6623959580703aef9442 to your computer and use it in GitHub Desktop.
TP04 3.1
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
(* --- 3.1 Cellule --- *) | |
let get_cell (x, y) board = | |
let rec row list n = match (list, n) with (* this function reads the y value of the row sent by column *) | |
|[], _ -> invalid_arg "y coordinate doesn't exist !" | |
|e::l, 1 -> e (* return the cell value *) | |
|e::l, n -> row l (n-1) | |
in let rec column board n = match (board, n) with (* this function sends the correct row (our 'int list' inside our 'list') to the 'row' function *) | |
|[], _ -> invalid_arg "x coordinate doesn't exist !" | |
|e::l, 1 -> row e y (* when column reaches the correct n, it sends the selected row to the 'row' function along with the y parameter *) | |
|e::l, n -> column l (n-1) | |
in column board x ;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment