I'm a musician, and I need more polyrhythms in my life!
A polyrhythm occurs in music (and in nature) when two events (claps, notes, fireflies flashing etc.) are occurring at two different regular intervals. The two kinds of event happen a different number of times in the same interval.
If I tap with my left hand twice, and with my right hand 3 times, in the same space of time, it looks a little bit like this:
------
R . . .
L . .
The hyphens at the top denote the length of the polyrthmic pattern, which is the lowest common multiple or 2 and 3. This can be understood as the point at which the pattern repeats.
There's also a 'metarhythm', which is the pattern produced when either hand is tapping:
------
R . . .
L . .
M . ...
This is a simple, and very common polyrhythm, with a ratio of 3:2.
Let's just say I don't want to do a simple polyrhythm that I can work out in my head, so I need something to work it out for me. I could do it long-form on paper, or...
Rules:
- Write some code to generate and display a polyrhythm diagram, as described above.
- Any old language, try for the fewest bytes.
- Your code takes two arguments:
- Number of taps with the Left hand (positive integer)
- Number of taps with the right hand (positive integer)
- It will work out the length, which is the lowest common multiple for the two arguments.
- The top line will consist of two whitespace characters followed by hyphens displaying the length (length * '-')
- The second and third lines will show the pattern for the right and left hands:
- It will start with an R or L, do denote which hand it is, followed by a space.
- The interval for that hand is the length divided by it's argument.
- The taps will start at the third character, denoted by any character you choose. From then on it will display the same character 'interval' characters apart.
- It will not be longer than the length line.
- The fourth line is the metarhythm:
- It will start with an upper case M, followed by a space.
- From the third character onwards, it will show a character (any character you choose) in every position where there's a tap on either the right or the left hand.
- Trailing whitespace is irrelevant.
Test cases:
r = 3, l = 2
------
R . . .
L . .
M . ...
r = 4, l = 3
------------
R . . . .
L . . .
M . .. . ..
r = 4, l = 5
--------------------
R . . . .
L . . . . .
M . .. . . . ..
r = 4, l = 7
----------------------------
R . . . .
L . . . . . . .
M . . .. . . . .. .
r = 4, l = 8
--------
R . . . .
L ........
M ........
Happy golfing!
r
andl
as two separate values? Could we accept a two-element array instead, for example? How about the order of them, is that strictlyr
followed byl
? \$\endgroup\$