De Bruijn Sequences (2011) [video]
youtube.com
youtube.com
The basic unit of Sanskrit metre is called Gana and is composed of 3 syllables. Since a syllable can be either short (I) or long (U), we have 2^3 = 8 Ganas in total corresponding to UUU, UUI, UIU etc. To know the composition of a specific Gana say for example Ja Gana, one has to find the index of "Ja" in the aforementioned phrase and extract the next two syllables as well so Ja Gana equals Ja-Bhaa-Na => IUI (because Ja is short, Bhaa is long and Na is short again).
Code in Python if my explanation wasn't clear
mnemonic = "Ya-Maa-Taa-Raa-Ja-Bhaa-Na-Sa-La-Gaam"
def symbol(syllable):
if syllable.count("a") == 1:
return "I"
else:
return "U"
def ganaSymbol(ganaName):
mnerray = mnemonic.split("-")
ganaIndex = mnerray.index(ganaName)
return "".join([symbol(syllable) for syllable in mnerray[ganaIndex : ganaIndex + 3]])
Metres are then defined in terms of Ganas and the number of lines in a stanza, for example Utpala Mala metre can be defined simply as Na-Ja-Bhaa-Ja-Ja-Ja-Raa, 4 which means a stanza in that meter should comprise of 4 lines, with each line having 21 syllables corresponding to Na-Ja-Bhaa-Ja-Ja-Ja-Raa sequence utpalaMala = "Na-Ja-Bhaa-Ja-Ja-Ja-Raa"
def printMetre(metreGanas, numLines):
print("\n".join(["".join([ganaSymbol(ganaName) for ganaName in metreGanas.split("-")])]*numLines))
Edits: Formatting[0] https://graphics.stanford.edu/~seander/bithacks.html#Integer...
https://golem.ph.utexas.edu/category/2015/01/mathematics_and...
If I did get it right, Ron Graham as the second mathematician makes perfect sense too :)