15
1
Create a program that generates a drum fill. Your program will output a pattern of L
(left hand hits), 'R' (right hand hits), and K
for kick drum hits.
Rules
- The pattern must never have more than 2 of the same hits consecutively.
- The pattern must be loopable, so it mustn't have more than 2 of the same hits when it loops.
- Your program accepts 1 argument which is the length of the pattern. You can assume this will always be an integer > 1.
- Program output must be random each time it's ran. It should be properly random each time, so that every combination is possible, so for an input of 2 for example: LR, LK, RL, RK, KL, KR all have a chance of being generated.
- IO can be used with any convenient method.
- Standard loopholes are forbidden.
- This is code-golf, so smallest program wins!
Example valid output:
RLRRKKLL
LRLLKKLR
LKKRLRKLRRKL
LRLR
Example invalid output:
LRLL // 3 characters when looped
LRLRRRLLR // 3 characters in a row
RRLRLLRR // 4 characters when looped
1No it should be properly random each time, so that every combination is possible, so for an input of 2: LL, LR, LK, RR, RL, RK, KK, KL, KR all have a chance of being generated. I'll add something to the rules about that now. – TMH – 2020-01-06T17:08:52.633
1I've made those changes to the question, cheers! – TMH – 2020-01-06T23:10:55.330
1May we output using three other distinct characters instead of L, R, K? (e.g. A, B, C or 2, 3, 9) – Robin Ryder – 2020-01-06T23:13:30.840
"The pattern must never have more than 2 of the same hits consecutively." What is this mean? Should I read for output
hits[]
,forall i: hits[i] != hits[i+1]
? But the example outputRLRRKKLL
doesn't agree on what I mean. – tsh – 2020-01-07T01:12:36.0801@tsh more than 2, not 2 or more. – Adám – 2020-01-07T06:19:13.963
@Adám So, does it mean $ \forall i: hits_i = hits_{i+1} \implies hits_i \ne hits_{i+2} $? – tsh – 2020-01-07T06:32:42.193
1@tsh i'd make that $hits_{i+1\bmod n}$ and $hits_{i+2\bmod n}$, but yes. – Adám – 2020-01-07T06:35:32.383