7 kyu
Latin Squares
614 of 1,886brodiemark
Description:
A latin square is an n × n array filled with the integers 1 to n, each occurring once in each row and column.
Here are examples of latin squares of size 4 and 7:
[[1, 4, 3, 2], [[2, 3, 1, 7, 4, 6, 5],
[4, 3, 2, 1], [7, 1, 6, 5, 2, 4, 3],
[3, 2, 1, 4], [6, 7, 5, 4, 1, 3, 2],
[2, 1, 4, 3]] [4, 5, 3, 2, 6, 1, 7],
[5, 6, 4, 3, 7, 2, 1],
[1, 2, 7, 6, 3, 5, 4],
[3, 4, 2, 1, 5, 7, 6]]
Latin squares have many practical uses, for example in error-correcting-codes and the design of agricultural experiments. See https://en.wikipedia.org/wiki/Latin_square for more details. Sudoku is a special type of 9 x 9 latin square, with additional conditions.
Task: Write a function that returns a latin square for any positive integer n.
You might also enjoy Latin Square Validator and Euler Squares.
Arrays
Similar Kata:
Stats:
Created | May 13, 2023 |
Published | May 15, 2023 |
Warriors Trained | 5403 |
Total Skips | 119 |
Total Code Submissions | 4280 |
Total Times Completed | 1886 |
Python Completions | 614 |
C Completions | 91 |
Java Completions | 311 |
JavaScript Completions | 627 |
CoffeeScript Completions | 10 |
Scala Completions | 18 |
C# Completions | 126 |
Kotlin Completions | 53 |
Swift Completions | 35 |
C++ Completions | 82 |
Rust Completions | 34 |
Total Stars | 71 |
% of votes with a positive feedback rating | 88% of 232 |
Total "Very Satisfied" Votes | 188 |
Total "Somewhat Satisfied" Votes | 33 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 26 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |