Flood a. Write a function print_int_matrix : int array array -> unit = < fun> That prints a rectangular integer matrix on screen. b. Write a function flood : ’a array array -> ’a -> unit = that changes the values of the input matrix according to the rules of the game Flood: https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/ flood.html. In short, it changes the value of the top left element, along with every element of the same value that is reachable from it, to the specified ’a value. An element is reachable if there exist a path from the top left element by going down, left, up, or right along same value elements. here is how the compilation should be: 1 # let generate_matrix rows columns vals seed = Random . init seed ; Array . make_matrix rows columns 0 | > Array . map ( Array . map (fun x - > Random . int vals ) ) ;; 2 val generate_matrix : int -> int -> int -> int -> int array array = (this is continue on the images)
Flood
a. Write a function print_int_matrix : int array array -> unit = < fun> That prints a rectangular integer matrix on screen.
b. Write a function flood : ’a array array -> ’a -> unit = that changes the values of the input matrix according to the rules of the game Flood: https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/ flood.html. In short, it changes the value of the top left element, along with every element of the same value that is reachable from it, to the specified ’a value. An element is reachable if there exist a path from the top left element by going down, left, up, or right along same value elements.
here is how the compilation should be:
1 # let generate_matrix rows columns vals seed = Random .
init seed ; Array . make_matrix rows columns 0 | >
Array . map ( Array . map (fun x - > Random . int vals ) ) ;;
2 val generate_matrix : int -> int -> int -> int -> int
array array = <fun >(this is continue on the images)
Step by step
Solved in 3 steps with 1 images