let pl= [|[| DownLeft; UpDownRight; UpDownRight; UpDown; DownLeft; DownLeftRight; UpDown Right|]; [| UpDownRight; LeftRight; DownLeftRight; Lef tRight; DownLeftRight; DownLeft; DownLeft|]; [ | DownLeft; DownLeft; DownLeftRight; LeftRig ht; UpRight; DownLeftRight; LeftRight]; [| DownLeft; UpDown; UpDown; UpDown; UpDownRi ght; UpDown; UpDown |]; [| LeftRight; DownRight; DownLeft; LeftRight; UpRight; DownLeft; DownRight|]; [| DownRight; UpDown; UpDownRight; LeftRight; UpRight; UpRight; UpDown | ] | ] ; ; let p2=[|[|LeftRight; DownLeftRight; DownLeftRig ht; DownRight; UpRight; DownLeft; |]; UpRight; DownRight; DownLeft; UpDownRight [| UpDownRight; UpDownRight; UpRight; DownLef t; UpDown; DownRight; ht|]; UpDownRight; UpRight; UpDownRight; LeftRig [| LeftRight; UpDownRight; LeftRight; UpDown; DownLeftRight; DownLeft; UpDown; DownLeftRight; LeftRight; DownLeft Right|]; [| UpDown; UpRight; DownLeftRight; DownLeft; DownLeft; UpDown; n]; UpDownRight; LeftRight; UpDownRight; UpDow [ | DownLeftRight; DownLeftRight; UpDownRight; DownLeft; UpDownRight; UpDownRight; DownRight; UpDown; DownLeft; UpDownRight | ]|];; 1 Pipe matrix You are given the type type pipe= LeftRight | UpDown | DownRight | DownLeft Up Right UpDownRight | DownLeftRight;; Each of the cases represent one of the following characters (in the same order): let chars=[ |"\u{02550}";"\u{02551}";"\u{0255 4}";"\u{02557}";"\u{0255A}"; "\u{02560}"; "\u{02566}"|]; ; Note that these wont print via print_string in older OCaml versions, but they work in https://try.ocamlpro.com/. a. Write a function \(\verb+getleaks: pipe array array -> (int * int) list = +\) whose input is a rectangular pipe matrix. The pipe at (0,0) has flow and spreads it through the neighboring pipes if the corresponding pipes match / characters visually match. Note that the lack of an "UpLeft" piece implies there are no cycles and the flow can essentially only move right or down, however it can split into multiple streams. The functions should print the original matrix via the corresponding characters, followed by printing the pipes with flow, replacing pipes without flow with \(\verb+"\u{2588}"+\). A leak happens at (i,j), if a pipe at (i,j) has flow and attempts to spread it to a neighboring pipe that cannot receive flow from such direction (disregarding pipes that exit the matrix). Return the locations of leaks as a list of pairs (in any order).

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
Need help Ocaml test cases: getleaks p1 ;; ╗╠╠║╗╦╠ ╠═╦═╦╗╗ ╗╗╦═╚╦═ ╗║║║╠║║ ═╔╗═╚╗╔ ╔║╠═╚╚║ ╗██████ ╠═╦═╦╗█ ████╚╦═ █████║█ ███████ ███████ - : (int * int) list = [(1, 0); (1, 2); (3, 5); (1, 5)] getleaks p2 ;; ═╦╦╔╚╗╚╔╗╠ ╠╠╚╗║╔╠╚╠═ ═╠═║╦╗║╦═╦ ║╚╦╗╗║╠═╠║ ╦╦╠╗╠╠╔║╗╠ ═╦╦███████ █╠╚╗██████ █╠═║██████ █╚╦╗██████ ██╠╗██████ - : (int * int) list = [(3, 3); (2, 2); (1, 1); (2, 3); (0, 2)]
let pl= [|[| DownLeft; UpDownRight; UpDownRight;
UpDown; DownLeft; DownLeftRight;
UpDown Right|];
[| UpDownRight; LeftRight; DownLeftRight; Lef
tRight; DownLeftRight;
DownLeft; DownLeft|];
[ | DownLeft; DownLeft; DownLeftRight; LeftRig
ht; UpRight; DownLeftRight;
LeftRight];
[| DownLeft; UpDown; UpDown; UpDown; UpDownRi
ght; UpDown; UpDown |];
[| LeftRight; DownRight; DownLeft; LeftRight;
UpRight; DownLeft;
DownRight|];
[| DownRight; UpDown; UpDownRight; LeftRight;
UpRight; UpRight; UpDown | ] | ] ; ;
let p2=[|[|LeftRight; DownLeftRight; DownLeftRig
ht; DownRight; UpRight; DownLeft;
|];
UpRight; DownRight; DownLeft; UpDownRight
[| UpDownRight; UpDownRight; UpRight; DownLef
t; UpDown; DownRight;
ht|];
UpDownRight; UpRight; UpDownRight; LeftRig
[| LeftRight; UpDownRight; LeftRight; UpDown;
DownLeftRight; DownLeft;
UpDown; DownLeftRight; LeftRight; DownLeft
Right|];
[| UpDown; UpRight; DownLeftRight; DownLeft;
DownLeft; UpDown;
n];
UpDownRight; LeftRight; UpDownRight; UpDow
[ | DownLeftRight; DownLeftRight; UpDownRight;
DownLeft; UpDownRight;
UpDownRight; DownRight; UpDown; DownLeft;
UpDownRight | ]|];;
Transcribed Image Text:let pl= [|[| DownLeft; UpDownRight; UpDownRight; UpDown; DownLeft; DownLeftRight; UpDown Right|]; [| UpDownRight; LeftRight; DownLeftRight; Lef tRight; DownLeftRight; DownLeft; DownLeft|]; [ | DownLeft; DownLeft; DownLeftRight; LeftRig ht; UpRight; DownLeftRight; LeftRight]; [| DownLeft; UpDown; UpDown; UpDown; UpDownRi ght; UpDown; UpDown |]; [| LeftRight; DownRight; DownLeft; LeftRight; UpRight; DownLeft; DownRight|]; [| DownRight; UpDown; UpDownRight; LeftRight; UpRight; UpRight; UpDown | ] | ] ; ; let p2=[|[|LeftRight; DownLeftRight; DownLeftRig ht; DownRight; UpRight; DownLeft; |]; UpRight; DownRight; DownLeft; UpDownRight [| UpDownRight; UpDownRight; UpRight; DownLef t; UpDown; DownRight; ht|]; UpDownRight; UpRight; UpDownRight; LeftRig [| LeftRight; UpDownRight; LeftRight; UpDown; DownLeftRight; DownLeft; UpDown; DownLeftRight; LeftRight; DownLeft Right|]; [| UpDown; UpRight; DownLeftRight; DownLeft; DownLeft; UpDown; n]; UpDownRight; LeftRight; UpDownRight; UpDow [ | DownLeftRight; DownLeftRight; UpDownRight; DownLeft; UpDownRight; UpDownRight; DownRight; UpDown; DownLeft; UpDownRight | ]|];;
1 Pipe matrix
You are given the type
type pipe=
LeftRight | UpDown | DownRight | DownLeft Up
Right UpDownRight | DownLeftRight;;
Each of the cases represent one of the following characters (in
the same order):
let chars=[ |"\u{02550}";"\u{02551}";"\u{0255
4}";"\u{02557}";"\u{0255A}";
"\u{02560}"; "\u{02566}"|]; ;
Note that these wont print via print_string in older OCaml
versions, but they work in https://try.ocamlpro.com/.
a. Write a function \(\verb+getleaks: pipe array array -> (int
*
int) list = <fun>+\) whose input is a rectangular pipe
matrix. The pipe at (0,0) has flow and spreads it through
the neighboring pipes if the corresponding pipes match /
characters visually match. Note that the lack of an
"UpLeft" piece implies there are no cycles and the flow
can essentially only move right or down, however it can
split into multiple streams. The functions should print the
original matrix via the corresponding characters, followed
by printing the pipes with flow, replacing pipes without
flow with \(\verb+"\u{2588}"+\). A leak happens at (i,j), if a
pipe at (i,j) has flow and attempts to spread it to a
neighboring pipe that cannot receive flow from such
direction (disregarding pipes that exit the matrix). Return
the locations of leaks as a list of pairs (in any order).
Transcribed Image Text:1 Pipe matrix You are given the type type pipe= LeftRight | UpDown | DownRight | DownLeft Up Right UpDownRight | DownLeftRight;; Each of the cases represent one of the following characters (in the same order): let chars=[ |"\u{02550}";"\u{02551}";"\u{0255 4}";"\u{02557}";"\u{0255A}"; "\u{02560}"; "\u{02566}"|]; ; Note that these wont print via print_string in older OCaml versions, but they work in https://try.ocamlpro.com/. a. Write a function \(\verb+getleaks: pipe array array -> (int * int) list = <fun>+\) whose input is a rectangular pipe matrix. The pipe at (0,0) has flow and spreads it through the neighboring pipes if the corresponding pipes match / characters visually match. Note that the lack of an "UpLeft" piece implies there are no cycles and the flow can essentially only move right or down, however it can split into multiple streams. The functions should print the original matrix via the corresponding characters, followed by printing the pipes with flow, replacing pipes without flow with \(\verb+"\u{2588}"+\). A leak happens at (i,j), if a pipe at (i,j) has flow and attempts to spread it to a neighboring pipe that cannot receive flow from such direction (disregarding pipes that exit the matrix). Return the locations of leaks as a list of pairs (in any order).
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE 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