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

More By Author:

Check out these other kata created by brodiemark

Stats:

CreatedMay 13, 2023
PublishedMay 15, 2023
Warriors Trained5403
Total Skips119
Total Code Submissions4280
Total Times Completed1886
Python Completions614
C Completions91
Java Completions311
JavaScript Completions627
CoffeeScript Completions10
Scala Completions18
C# Completions126
Kotlin Completions53
Swift Completions35
C++ Completions82
Rust Completions34
Total Stars71
% of votes with a positive feedback rating88% of 232
Total "Very Satisfied" Votes188
Total "Somewhat Satisfied" Votes33
Total "Not Satisfied" Votes11
Total Rank Assessments26
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • brodiemark Avatar
  • pavloslav Avatar
  • rowcased Avatar
  • hobovsky Avatar
  • dfhwze Avatar
  • KayleighWasTaken Avatar
  • LosBlobbos Avatar
Ad