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)

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
icon
Related questions
Question

 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)

> # let
colormatrix-generate_matrix
val colormatrix : int array array =
[[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 ;;
5
7 204123
s 324233
> 304330
10 132021
unit = ()
12 # flood colormatrix 3 ;;
unit = ()
13
14#print_int_matrix colormatrix ;;
as 304123
16 324233
17 304330
18 132021
19 unit = ()
20 # flood colormatrix 2 ;;
21
unit = ()
22 #print_int_matrix colormatrix ;;
23 204123
24 224233
2 204330
26132021
4 6 50;;
27
unit = ()
25 # flood colormatrix 4 ;;
29
unit = ()
30 # print_int_matrix colormatrix ;;
31404123
32 444233
33404330
34 132021
35 unit = ()
36 #flood colormatrix 3 ;;
37 unit = ()
35 #print_int_matrix colormatrix ;;
39 303123
40 333233
41303330
42 132021
unit = ()
#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
45 val colormatrix2 int array array =
Transcribed Image Text:> # let colormatrix-generate_matrix val colormatrix : int array array = [[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 ;; 5 7 204123 s 324233 > 304330 10 132021 unit = () 12 # flood colormatrix 3 ;; unit = () 13 14#print_int_matrix colormatrix ;; as 304123 16 324233 17 304330 18 132021 19 unit = () 20 # flood colormatrix 2 ;; 21 unit = () 22 #print_int_matrix colormatrix ;; 23 204123 24 224233 2 204330 26132021 4 6 50;; 27 unit = () 25 # flood colormatrix 4 ;; 29 unit = () 30 # print_int_matrix colormatrix ;; 31404123 32 444233 33404330 34 132021 35 unit = () 36 #flood colormatrix 3 ;; 37 unit = () 35 #print_int_matrix colormatrix ;; 39 303123 40 333233 41303330 42 132021 unit = () #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 45 val colormatrix2 int array array =
46
47
[[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; 0;
[13; 3; 3; 3; 3; 0; 2111]
colormatrix2 ;;
45
49 # print_int_matrix
so 2033333
51 3135443
52 3233320
53 3446310
54 3333302
unit ()
s6 # flood colormatrix2 3 ;;
57
unit = ()
#print_int_matrix colormatrix2 ;;
59 3033333
60 3135443
613233320
62 3446310
633333302
Gunit = ()
6s #flood colormatrix2 4 ;;
unit ()
67 # print_int_matrix colormatrix2 ;;
G4044444
4145444
TO 4244420
71 4446410
72 4444402
73 unit = ()
Transcribed Image Text:46 47 [[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; 0; [13; 3; 3; 3; 3; 0; 2111] colormatrix2 ;; 45 49 # print_int_matrix so 2033333 51 3135443 52 3233320 53 3446310 54 3333302 unit () s6 # flood colormatrix2 3 ;; 57 unit = () #print_int_matrix colormatrix2 ;; 59 3033333 60 3135443 613233320 62 3446310 633333302 Gunit = () 6s #flood colormatrix2 4 ;; unit () 67 # print_int_matrix colormatrix2 ;; G4044444 4145444 TO 4244420 71 4446410 72 4444402 73 unit = ()
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education