Fall 2016, David Matuszek

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
Inverse Diagonal `/`

)`\`

)

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:

- Start with a function that doesn't do anything
- Write a test for the function.
- Run the test, and make sure it
**fails**. - Add code to the function to try to make the test pass.
- Run the test again.
- If the test fails, debug the function (or the test) until the test passes.
- If the test passes, continue.

- Is the function complete (does it do everything it should do)?
- If the function isn't complete, add code to the test to check the new functionality. Go to step 3.
- If the function is complete, you are done with this function.

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__":`

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 *ring*`'outer'`

and `'inner'`

,
all lowercase, with the obvious meanings.

`make_squarelotron(`

*list*)

**returns**A "squarelotron"- Given a "flat" list of 25 numbers, make and return a squarelotron. You
probably want to represent the squarelotron as a list of lists, but
that's up to you: Represent it however you like. It could even be just
the list given as an argument. The first 5 numbers are the top row of
the squarelotron, the next 5 numbers are the second row, etc. Calling
this function should
**not**result in any input/output. `make_list(`

*squarelotron*)

**returns**A "flat" list of numbers- This function is the inverse of
`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_squarelotron`

and`make_list`

functions 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.- This function performs the Upside-Down Flip of the squarelotron, as
described above, and returns the new squarelotron. The original
squarelotron should not be modified (I will check for this). Calling
this function should
**not**result in any input/output. `left_right_flip(`

*squarelotron*,*ring*)

**returns**A new squarelotron.- This function performs the Left-Right Flip of the squarelotron, as
described above, and returns the new squarelotron. The original
squarelotron should not be modified (I will check for this). Calling
this function should
**not**result in any input/output. `inverse_diagonal_flip(`

*squarelotron*,*ring*)

**returns**A new squarelotron.- This function performs the Main Inverse Diagonal of the squarelotron,
as described above, and returns the new squarelotron. The original
squarelotron should not be modified (I will check for this). Calling
this function should
**not**result in any input/output. `main_diagonal_flip(`

*squarelotron*,*ring*)

**returns**A new squarelotron.- This function performs the Main Diagonal Flip of the squarelotron, as
described above, and returns the new squarelotron. The original
squarelotron should not be modified (I will check for this). Calling
this function should
**not**result in any input/output.

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.