OCAML programming (Lights Out) The mechanics described in this exercise can be used to implement a game lights out. 1. Create a function flip val flip : bool array array -> int -> int -> bool array array = that given a bool matrix and two integers i; j. it negates the values (true!false, false!true) at location i; j in the matrix, as well negating the values on the (up to) 4 horizontally/vertically adjacent elements. 2. Create a function print matrix val print_matrix : bool array array -> unit = that given a bool matrix, it prints it on screen (true !"T", false!"F"). Sample input: # let matrix= [|[|false; true; true; false|]; [|true; false; false; true|]; [|false; false; true; true|]|];; # print_matrix matrix;; FTTF TFFT FFTT # flip matrix 1 4;; # print_matrix matrix;; FTFT TFFF FFTT
OCAML programming
(Lights Out)
The
1. Create a function flip
val flip : bool array array -> int -> int -> bool array array = <fun>
that given a bool matrix and two integers i; j. it negates the values
(true!false, false!true) at location i; j in the matrix, as well negating
the values on the (up to) 4 horizontally/vertically adjacent elements.
2. Create a function print matrix
val print_matrix : bool array array -> unit = <fun>
that given a bool matrix, it prints it on screen (true !"T", false!"F").
Sample input:
# let matrix= [|[|false; true; true; false|]; [|true; false; false; true|];
[|false; false; true; true|]|];;
# print_matrix matrix;;
FTTF
TFFT
FFTT
# flip matrix 1 4;;
# print_matrix matrix;;
FTFT
TFFF
FFTT
Trending now
This is a popular solution!
Step by step
Solved in 2 steps