Intro to Computer Science

PA04

Latin Squares


Programs are due 3/3 at 11:59pm 

You can submit up to 2 days late for a 10% penalty per day.

Main program is worth 25 points. Extra credit worth +4 points.


Introduction

The aim of this project is practice the use of for loops, while loops, and conditional statements within a project that is a little bit bigger than ones you have been working on.  This will give you some practice with program development.  Take the time to really think about this problem and work through the process before you begin to code.  Write small snippets of code to make sure you can perform smaller pieces of the assignment rather than jumping in and writing the whole program at once.


Background

A Latin Square is an n*n table filled with n different symbols in such a way that each symbol occurs exactly once in each row and exactly once in each column (see this link). For example, two possible Latin Squares of order 6:

The top-left numbers are 1 and 3 respectively.


Project Description (squares.py)

Your program will ask user to input two numbers. The first number is the order of square; the second one is the top-left number of the square. Note that the second number should be between 1 and the first number, so your program should check this situation. Then, your program will print the corresponding Latin Square. Here is some example output:

Here are some hints:
1. The range function and the % (modulus) operator are both useful for this project.
2. How would you generate a sequence beginning with 1 of the appropriate order? A sequence of order 5 would be 1 2 3 4 5
3. How would you generate a sequence of the appropriate order beginning with a number other than 1? For a sequence of order 5 starting with 3 would be 3 4 5 1 2
4. How would you generate the second in the Latin sequence? For example, starting with 1 2 3 4 the next sequence would be 2 3 4 1

Getting points for the project:
In this case, the autograder will award partial points for solutions that have some working components. You will get some points for

Warning: If I see that you are trying to "hardcode" or print things in order to defeat the autograder, I reserve the right to deduct points. I also reserve the right to deduct points if you leave off the program header and/or use bad programming style (such as picking bad variable names).


Extra credit 4pts - add a loop to continue...

Add a loop to your squares.py program to ask the user to continue. For example:


Final Submission

Use the Program Submission System to submit your code. Note: you must submit the extra credit and regular versions of the code in the separate designated places! The autograder will not give you the extra credit if you submit the extra credit version to the regular submission spot.