Skip to content

Instantly share code, notes, and snippets.

@graup
Last active February 7, 2020 04:09
Show Gist options
  • Save graup/70b09323bfa7182fe693eecb8e749896 to your computer and use it in GitHub Desktop.
Save graup/70b09323bfa7182fe693eecb8e749896 to your computer and use it in GitHub Desktop.
def balanced_latin_squares(n):
l = [[((j//2+1 if j%2 else n-j//2) + i) % n + 1 for j in range(n)] for i in range(n)]
if n % 2: # Repeat reversed for odd n
l += [seq[::-1] for seq in l]
return l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment