Anita is the baby sitter of Baron Von Hauser’s kids. Von Hauser is a famous physics professor, so the Von Hauser kids have weird toys, all of which Anita has to master to be able to effectively entertain the kids.
While Anita was cleaning the bathtub she found a new toy, a Squarelotron game. It is extremely weird, and posses a lot of mathematical symmetry. She is determined to understand this new toy, otherwise she won´t be able to play with Von Hauser’s kids. However the complexity of such an extreme toy makes it difficult to play.
A Squarelotron consist basically of a matrix of numbers. This matrix can
be decomposed as square rings which can rotate independently in 4
different ways: Upside-Down (↕), Left-Right (↔), reflected through the
|The green line shows the main diagonal.
Flipping the outer ring through the main
diagonal means interchanging 2 and 6,
3 and 11, ..., 20 and 24.
The inverse diagonal would be a line
running through 5, 9, 19, 17, and 21.
The following are examples of flips. They are not cumulative; each flip is shown as being from the initial state.
A Upside-Down Flip of the outer ring of the squarelotron yields:
A Left-Right Flip of the inner ring of the squarelotron yields:
A Flip through the Main Diagonal of the outer ring of the squarelotron yields:
An Inverse Diagonal flip of the inner ring yields:
Anita wants you to do a program which performs the following. It will print out the initial squarelotron. Then the program will let you tell it which flips to perform, and it will print out the new squarelotron after each flip. Finally, the program will let you start with a new squarelotron, or quit.
Write and unit test the following functions. You should try using TDD, Test-Driven Design, as illustrated in class:
Follow the specifications exactly, because we will also be using my
unit tests to check your work. Also as before, the design of the user
interface is up to you--but the program must provide clear instructions on
how to use it. Write a
main() function that we can use to
begin your program. To simplify running both the program and the uint
test, put the following lines at the end of your program:
if __name__ == "__main__":
Notice that in the squarelotron there are two rings that can be flipped
(the center is immobile). In each of the following functions, the
should be one of the two strings
all lowercase, with the obvious meanings.
make_list(squarelotron)returns A "flat" list of numbers
make_squarelotron. It returns a list of 25 numbers. (Note: Since I have not specified how to represent your squarelotron, I will depend heavily on the
make_listfunctions to check all the rest of your functions; so get them right!) Calling this function should not result in any input/output.
upside_down_flip(squarelotron, ring)returns A new squarelotron.
left_right_flip(squarelotron, ring)returns A new squarelotron.
inverse_diagonal_flip(squarelotron, ring)returns A new squarelotron.
main_diagonal_flip(squarelotron, ring)returns A new squarelotron.
You may want to write some helper functions. For each helper function that does computation, use TDD and write unit tests first. The functions that primarily interact with the user (and do no significant computation) do not need to be unit tested, and can do any required input/output.
This assignment is a modified version of the problem "10016 - Flip-Flop the Squarelotron," from Online Judge.