Homework 1b - for these 2 problems, you decompose out helper functions to support the main function.
Solve these problems using loops and logic like the lecture examples (not using Python features like for, range, int counting, break .. which have not covered yet.)
For this problem, bit starts facing west next to a "rectangle" made of 1 or more blocks. First bit does one "side" move, moving forward while there are blocks to the left, painting squares red. There's a boundary detail here: paint the squares next to a block red, but not the last square.
Before side move:
After side move:
To complete the rectangle, turn left, move, and do another side move, but with the color green.
Then do the last side with blue. That completes one rectangle, which looks like this:
The overall "triple" problem is just 3 rectangles put together, with a right turn making the transition to the 2nd and 3rd rectangles, like this:
After the whole triple:
The main function for this problem is called triple() and it solves the whole problem. You should decompose out 2 or more helper functions to help solve the problem. (Nick's solution uses 2 helper functions.) For each decomposed helper function write a 1 or 2 sentence description within the """triple quotes""" at the top of the function summarizing what the function does. For the wording of your description, you may assume the reader is familiar with the definitions and terminology of the problem itself. Your description should address the pre and post conditions of the function (and of course you need to have those ideas clear in your head in order to mesh the functions together).
For this problem, bit starts in the upper left corner, facing south. Move bit to the south-west corner, filling in all the rows with a checkerboard pattern, like this:
It's handy to have terms for the two row types - we'll say the topmost row is "type 0", since the blue squares begin right away, and the second row is "type 1". This is a classic, algorithmic CS106A problem. Make a little diagram to think through each function.
Your code should be able to solve any size world that is 2x2 or larger, and the world may not be square.
The main function for this project is called checkerboard() and it solves the whole problem. As with the Triple problem, decompose out 2 or more helper functions to help solve the problem. (Nick's solution uses 2 helper functions.) For each decomposed helper function write a 1 or 2 sentence description within the """triple quotes""" at the top of the function describing what it does as above. For this problem, a clear definition of bit's position and facing in the pre/post conditions is important to mesh the functions together.
Suggestion: It's tempting to do, say, one type of row left-to-right, and the other type of row going right-to-left. That scheme seems reasonable, but unfortunately it makes it very hard to mesh the pre and post conditions of the helper functions. It works out more cleanly to do all the rows in the same direction.
Generally you work on your functions running 1 case at a time. When everything is working, try the "Run All" option to run your functions on all the test cases. If the code passes all the cases it reports "All Correct" at the top. Once solved, you'll see a "Noted: All Correct" note below your code too. You should also check that your code is clean and has proper style. We'll have separate instructions for how to submit the code online to your section leader.
Turn In Update: Use Turn In page to submit work to Paperless