Skip to content

Instantly share code, notes, and snippets.

@alarsyo
Created March 29, 2016 18:02
Show Gist options
  • Save alarsyo/efbc8f7f6c3e6623959580703aef9442 to your computer and use it in GitHub Desktop.
Save alarsyo/efbc8f7f6c3e6623959580703aef9442 to your computer and use it in GitHub Desktop.
TP04 3.1
(* --- 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