Write a function print_int_matrix : int array array -> unit = < fun> That prints a rectangular integer matrix on screen. 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, right along same value elements. #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)) ;; a val generate_matrix : int->int -> int -> int -> int array array = #let colormatrix-generate_matrix 4 650;; 4 val colormatrix : int array array =
Write a function print_int_matrix : int array array -> unit = < fun> That prints a rectangular integer matrix on screen. 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, right along same value elements. #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)) ;; a val generate_matrix : int->int -> int -> int -> int array array = #let colormatrix-generate_matrix 4 650;; 4 val colormatrix : int array array =
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
OCaml, functional

Transcribed Image Text:Write a function print_int_matrix: int array array -> unit = <
fun> That prints a rectangular integer matrix on screen.
Write a function flood: 'a array array -> 'a -> unit = <fun> 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, right along same value elements.
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>
3 # let colormatrix-generate_matrix 4 6 5 0 ; ;
4 val colormatrix : int array array =
![5
T204123
8 324233
9304330
10 132021
11
unit = ()
12 # flood colormatrix 3 ;;
13
: unit - ()
14 # print_int_matrix colormatrix ;;
15 304123
16 324233
17 304330
18 132021
19
20
[I[12; 0; 4; 1; 2; 31]; [13; 2; 4; 2; 3; 31]; [13;
0; 4; 3; 3; 01]; [11; 3; 2; 0; 2; 11]|]
#print_int_matrix colormatrix ;;
: unit = ()
#flood colormatrix 2 ;;
-
21
: unit = ()
22 # print_int_matrix colormatrix ;;
23 204123
24 224233
25 204330
26 132021
27-
: unit = ()
28 # flood colormatrix 4 ;;
unit ()
29
30 # print_int_matrix colormatrix ;;
31 404123
32 444233
33 404330
34 132021
35
unit = ()
36 # flood colormatrix 3 ;;
37
: unit = ()
38 # print_int_matrix colormatrix ;;
39 303123
40 333233
41 303330
42 132021
43
47
unit = ()
44#let colormatrix2
= [1 [12; 0; 3; 3; 3; 3; 31]; [13; 1; 3; 5; 4; 4;31]; [13; 2; 3; 3; 3; 2; 01]; [13; 4; 4; 6; 3; 1; 01
4 val colormatrix2 : int array array =
46
[I[12; 0; 3; 3; 3; 3; 311; [13; 1; 3; 5; 4; 4; 31];
[13; 2; 3; 3; 3; 2; 01]; [13; 4; 4; 6; 3; 1; 0;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fcb9e9b7e-2b69-474f-89fc-484e48dbb94a%2F8fd4d9c6-f2e6-49ee-8534-0dd79198e4d5%2Ffc0b3lf_processed.png&w=3840&q=75)
Transcribed Image Text:5
T204123
8 324233
9304330
10 132021
11
unit = ()
12 # flood colormatrix 3 ;;
13
: unit - ()
14 # print_int_matrix colormatrix ;;
15 304123
16 324233
17 304330
18 132021
19
20
[I[12; 0; 4; 1; 2; 31]; [13; 2; 4; 2; 3; 31]; [13;
0; 4; 3; 3; 01]; [11; 3; 2; 0; 2; 11]|]
#print_int_matrix colormatrix ;;
: unit = ()
#flood colormatrix 2 ;;
-
21
: unit = ()
22 # print_int_matrix colormatrix ;;
23 204123
24 224233
25 204330
26 132021
27-
: unit = ()
28 # flood colormatrix 4 ;;
unit ()
29
30 # print_int_matrix colormatrix ;;
31 404123
32 444233
33 404330
34 132021
35
unit = ()
36 # flood colormatrix 3 ;;
37
: unit = ()
38 # print_int_matrix colormatrix ;;
39 303123
40 333233
41 303330
42 132021
43
47
unit = ()
44#let colormatrix2
= [1 [12; 0; 3; 3; 3; 3; 31]; [13; 1; 3; 5; 4; 4;31]; [13; 2; 3; 3; 3; 2; 01]; [13; 4; 4; 6; 3; 1; 01
4 val colormatrix2 : int array array =
46
[I[12; 0; 3; 3; 3; 3; 311; [13; 1; 3; 5; 4; 4; 31];
[13; 2; 3; 3; 3; 2; 01]; [13; 4; 4; 6; 3; 1; 0;
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education