33
1
Given an input of a string consisting entirely of q
s representing quarter
notes and e
s representing eighth notes, output the indices of the quarter
notes that are syncopated.
Syncopation is complex, but for the purposes of this challenge, our definition of "syncopated" will be very simple: a quarter note that starts on the "off-beat"—that is, the beats counted as "and" in n/4 time.
This may alternatively be defined as any quarter note that is preceded by an
odd number of eighth notes. For example, the notes marked with *
below are considered syncopated, and their indices are also shown:
eqqeqqeqqe
** **
12 78
Output: 1 2 7 8
The input will always consist of a whole number of measures in 4/4 time (a quarter note is a quarter of a measure, and an eighth note is an eighth of a measure). (The input will also never be empty.) Output can either be a single string with elements separated by any delimiter that does not contain numbers or an array/list/etc. The output may be 1-based (i.e. the first index is 1 instead of 0) if you wish, and it may also be in any numeric base (unary, decimal, etc.).
Since this is code-golf, the shortest code in bytes wins.
Test cases:
In Out
-----------------------------------------------
eqqqe 1 2 3
qeqeq 2
qqqeqqeeeeqeqeqeqqeqqeqq 4 5 10 14 19 20
eeeeeqeeqeeqqqqeqeqeeqe 5 8 11 12 13 14 18 21
qqqq <none>
eeeeeeee <none>
1Can output be 1-based? – Luis Mendo – 2016-01-15T22:15:36.680
1Could you do a worked example to show how the indices work? – Peter Taylor – 2016-01-15T22:16:59.200
1@LuisMendo Sure, if it makes your code shorter. – Doorknob – 2016-01-15T22:24:49.657
@PeterTaylor Okay, is something like that what you were thinking of? – Doorknob – 2016-01-15T22:25:07.213
Can the input be a string including the quote signs?
'eqqqe'
instead ofeqqqe
– Luis Mendo – 2016-01-15T23:38:25.813@LuisMendo No, it has to be exactly the strings specified in the test cases. – Doorknob – 2016-01-16T01:37:33.943
Ah, so it's index in the string and not in the score. – Peter Taylor – 2016-01-16T09:08:46.283