Question
A Latin Square is an NxN array of N symbols such that each symbol appears in each row and each column exactly once. Write a
A Latin Square is an NxN array of N symbols such that each symbol appears in each row and each column exactly once. Write a function in python which takes in two parameters and returns a Latin square as a string. The function should take in two parameters, the first an integer telling the size N of the square, and the second a single character to use as the upper-left corner.
Here are some examples:
>>> print(latinSquare(4,'A'))
A,B,C,D
B,C,D,A
C,D,A,B
D,A,B,C
>>> print(latinSquare(5,'D'))
D,E,A,B,C
E,A,B,C,D
A,B,C,D,E
B,C,D,E,A
C,D,E,A,B
Your program should use N consecutive letters starting with A as the symbols in the square (you can assume the size N is an integer that is 26 or less, and that the letter provided as the second argument is one of the first N uppercase letters in the alphabet). You should have commas between each character on the same row, and newlines at the end of each row. There should not be an extra newline character at the end of the result string, space between commas, or any other character, such as a dot anywhere. Hint: Start with a Latin square of just numbers before trying letters.
Break the problem into stages: 1) Only worry about the size of the square; 2) Get the correct top left value; 3) Use letters instead of numbers
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started