The Narrative
You are a bad musician. You never bothered to learn how to count rhythms. To remedy this shortcoming, you decide to write a program that will tell you how to count in any given time signature. You are still a bad musician, but you can at least pretend that you can count rhythms.
The Objective
Given a time signature, output a possible counting pattern for said time signature.
For those who don't know musical terms:
A measure is, essentially, a group of notes, useful for organizing music and making sure the musicians don't lose their place in the music.
A time signature is a set of numbers in a piece of music which tells you how many beats are in a measure, and which note-length is the beat. For example, a 3/4
time signature tells you that each measure has 3
beats, and the quarter note (4
) is the beat. An 11/16
T.S. tells you that there are 11
sixteenth note beats (16
) in one measure.
A counting pattern is a way to verbally express the division of a measure. For example, a song in 3/4
can simply be counted as "1 2 3"
. 11/16
can be counted as "1 la li 2 e & a 3 e & a"
(this is more intuitive than counting to 11; I will define this later)
It's important to note that the bottom number of almost all T.S.'s are a power of 2. For this challenge, we will ignore irrational T.S.'s. We will also not look at T.S.'s with a beat greater than 16.
How to Generate a Counting Pattern:
Time signatures with a X/1
, X/2
, or X/4
can simply be counted with numbers (4/2
can be counted as "1 2 3 4"
).
T.S.'s with a X/8
or X/16
are a bit more tricky. These can be counted by grouping beats together to form larger beats (6/8
, despite having 6
'beats', is very often treated as 2
beats with a triplet subdivision). For this challenge, beats should be grouped in groups of 1
("1"
), 2
("1 &"
), 3
("1 la li"
), or 4
("1 e & a"
)
For X/8
, groups of 3
should be prioritized over 2
, but 1
should be avoided if possible. (For 7/8
, even though 3+3+1
prioritizes 3
's, 3+2+2
is better because it avoids 1
)
For X/16
, groups of 3
should be prioritized over 4
, but 2
and 1
should be avoided if possible. (For 11/16
, even though 3+3+3+2
prioritizes 3
's, 3+4+4
is better because it avoids 2
)
It is important to note that the ordering of the groups is not important, i.e. 3+2
and 2+3
are both acceptable groupings of 5/8
. This would be important normally, but you are a bad musician.
Also note that T.S.'s 'larger' than 1/8
can be grouped entirely with 2
's and 3
's; T.S.'s 'larger' than 5/16
can be grouped entirely with 3
's and 4
's.
Whew! What a mouthful!
The Specs
You will take a time signature as input. this may be formatted within reason (use common sense!).
You will output an acceptable counting pattern. This will be a string of counts (1
, la
, &
, etc.) separated by spaces. Your output should not include leading or trailing whitespace.
Test Cases:
To clarify, the 'numerator' is a positive integer, and the 'denominator' is 1
, 2
, 4
, 8
, or 16
.
Again, note that some T.S.'s have multiple valid outputs.
"Input", "Output"
"1/1", "1"
"3/2", "1 2 3"
"4/4", "1 2 3 4"
"1/8", "1"
"10/8", "1 la li 2 la li 3 & 4 &"
"2/16", "1 &"
"5/16", "1 la li 2 &"
"29/16", "1 la li 2 la li 3 la li 4 la li 5 la li 6 la li 7 la li 8 e & a 9 e & a"
"Input", "Invalid Output"
"6/4", "1 la li 2 la li"
"7/8", "1 la li 2 la li 3"
"10/8", "1 & 2 & 3 & 4 & 5 &"
"12/16", "1 e & a 2 e & a 3 e & a"
This is code-golf, so the shortest answer in bytes wins!
1 & 2 & 3 & 4 & 5 &
valid? \$\endgroup\$10/8
example is grouped as3+3+2+2
… maybe you misread? 2 groups of 2 look like”1 & 2 &”
, while 1 group of 4 looks like”1 e & a”
. Hope this helps! \$\endgroup\$5/3
for 6/4 time \$\endgroup\$