[Question]
  [
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](https://en.wikipedia.org/wiki/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](/questions/tagged/code-golf "show questions tagged '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>
```
  
[Answer]
# [Jelly](http://github.com/DennisMitchell/jelly), ~~12~~ 9 [bytes](https://github.com/DennisMitchell/jelly/blob/master/docs/code-page.md)
```
=‚Äúe‚Äù¬µ<^\O
```
As a program, the above code requires quotes around the input. Since that is not allowed, this is a function submission. The output is 1-based. ~~Try it online!~~
### How it works
```
=‚Äúe‚Äù¬µ<^\O    Monadic link. Argument: s (string)
=‚Äúe‚Äù         Check each character for equality with 'e'. Yields a Boolean array.
    ¬µ        Start a new, monadic chain.
      ^\     Compute the array of partial reductions by XOR, i. e., the parities
             of all prefixes of the Boolean array.
     <       Check if the Booleans are strictly smaller than the parities.
             A truthy outcome indicates an off-beat quarter note.
        O    Yield all indices of 1's.
```
### Update
The above code doesn't work anymore in the latest version of Jelly, since we need a *character* **e**, but `‚Äúe‚Äù` yields a string. Fixing that saves a byte, for a total of **8 bytes**.
```
=‚Äùe¬µ<^\O
```
This works as a full program. [Try it online!](http://jelly.tryitonline.net/#code=PeKAnWXCtTxeXE8&input=&args=cXFxZXFxZWVlZXFlcWVxZXFxZXFxZXFx)
[Answer]
# Ruby, 46
```
i=e=0
gets.bytes{|n|e^=n
e&4|n>114&&p(i)
i+=1}
```
Input to stdin. Output to stdout, newline separated.
Commented
```
i=e=0               #i keeps index, e keeps track of 8ths.
gets.bytes{|n|      #iterate through bytes in the input
e^=n                #xor e with input. We're interested in the 4's bit, which is only affected by ascii e, not ascii q
e&4|n>114&&p(i)     #e&4 evaluates to 4 or 0. OR with n and if the value is greater than ascii code for q, print index
i+=1}               #increment index
```
[Answer]
# JavaScript ES7, ~~50~~ 48 bytes
Pretty short for JS, if you ask me. `[for...of]` syntax, basically combined map and filter, comes in handy for this challenge.
```
s=>[for(c of(i=f=0,s))if(++i&&c>'e'?f%2:f++&0)i]
```
Defines an anonymous function that outputs a 1-indexed array.
### Test snippet
This uses an ungolfed, un-ES7'd version of the code.
```
a = function(s) {   // Create a function a that takes in a parameter s and does these things:
  var r = [],       // Set variable r to an empty array,
  i = 0, f = 0;     // i to 0, and f to 0.
  for(c of s) {     // For each character c in s:
    i++;            //  Increment i by 1.
    if(             //  If
      c == 'q' ?    //   if c == 'q',
      f%2 === 1 :   //    f is even; otherwise,
      f++ && false) //    increment f and don't execute this:
      r.push(i);    //   Add i to the end of r.
  } return r;       // Return r.
}
```
```
<input type="text" value="eqqqe" id=O />
<button onclick="P.innerHTML='['+a(O.value)+']'">Try it</button>
<p id=P />
```
[Answer]
## J, ~~20 19~~ 17 bytes
```
=&'e'(I.@:<~:/\@)
```
Thanks to randomra for saving a byte, and to Dennis for saving two.
This is an unnamed monadic verb, used as follows:
```
  f =: =&'e'(I.@:<~:/\@)
  f 'eqqqe'
1 2 3
```
[Try it here.](http://tryj.tk/)
## Explanation
```
=&'e'(I.@:<~:/\@)
=&'e'               Replace every 'e' with 1, other chars with 0
     (         @)   Apply the verb in parentheses to the resulting 0-1 vector
           ~:/\     Cumulative reduce with XOR (parity of 'e'-chars to the left)
          <         Element-wise less-than with original vector
      I.@:          Positions of 1s in that vector
```
[Answer]
# GNU grep, ~~3+17=20~~ 3 + 15 = 18 bytes
The program requires the options `boP`.
The code is
```
q(?!(q|eq*e)*$)
```
Save it as `synco`, then run as `grep -boPf synco`.
The output separator is `:q` followed by a newline. E.g. the output for `eqqqe` is
```
1:q
2:q
3:q
```
The meanings of the flags are:
* `P`: Use PCRE regexes.
* `o`: This means to print only the part of the line that matches the regular expression, but that's not why it's important. `o` is used because it has the effect of allowing multiple matches per line.
* `b`: Print the offset in bytes of the beginning of each match from the beginning of the file.
The pattern checks that there is not an even number of eighth notes after a quarter note.
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 12 ~~14~~ ~~16~~ bytes
```
j101=tYs2\<f
```
*Thanks to Dennis for removing 2 bytes (and for hosting MATL in his awesome online platform!)*
This uses [current version (9.3.0)](https://github.com/lmendo/MATL/releases/tag/9.3.0) of the language/compiler.
Input and output are through stdin and stdout. The result is 1-based.
**Example**:
```
>> matl j101=tYs2\<f
> eeeeeqeeqeeqqqqeqeqeeqe
6  9 12 13 14 15 19 22
```
Or [**try it online!**](http://matl.tryitonline.net/#code=ajEwMT10WXMyXDxm&input=cXFxZXFxZWVlZXFlcWVxZXFxZXFxZXFx)
## Explanation
```
j             % input string
101=          % vector that equals 1 at 'e' characters and 0 otherwise
t             % duplicate
Ys2\          % cumulative sum modulo 2
<             % detect where first vector is 0 and second is 1
f             % find (1-based) indices of nonzero values
```
[Answer]
# Python 2, ~~94~~ ~~85~~ ~~79~~ ~~75~~ 66 bytes
**EDIT:** Thanks Doorknob and Alex A.
**EDIT:** Thanks Alex A.
**EDIT:** Now using input() so the input must be a string with the quotes.
**EDIT:** Thanks Zgarb for recommending me to use enumerate.
Simply counts number of e's and if q, check if e count is odd, then print index.
```
e=0
for j,k in enumerate(input()):
 if"q">k:e+=1
 elif e%2:print j
```
[Try it here](http://ideone.com/UX6pf8)
[Answer]
## Haskell, ~~58~~ 51 bytes
```
f x=[i|(i,'q')<-zip[0..]x,odd$sum[1|'e'<-take i x]]
```
Usage example: `f "eeeeeqeeqeeqqqqeqeqeeqe"` -> `[5,8,11,12,13,14,18,21]`.
Go through the list and output the current index `i` for every char `'q'` if there's an odd number of `'e'`s before it.
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 12 bytes
```
(‚ç∏~√ó‚â†\)'e'‚àò=
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v9f41HvjrrD0x91LojRVE9Vf9Qxw/Z/2qO2CY96@x51NR9ab/yobeKjvqnBQc4KQCrEwzP4f5qCemphYWGqOheQVZgKhBAWUAiIgKAQAqEILJkKEQcjsEIIB6YRSREQqAMA "APL (Dyalog Classic) ‚Äì Try It Online")
Outputs 1-indexed.
### Explanation:
```
       'e'‚àò=    ‚çù Map each element to whether it is equal to 'e'
(     )         ‚çù Then apply the train
  ~             ‚çù Not the array into indexes of 'p'
   √ó            ‚çù Multiply this by
    ‚â†\          ‚çù The cumulative reduction by inequality 
 ‚ç∏              ‚çù And get the indexes of the ones in the array
```
[Answer]
## [Minkolang 0.15](https://github.com/elendiastarman/Minkolang), 28 bytes
```
(o"q"=7&z1+$z8!z2%,2&iN$I$).
```
[Try it here.](http://play.starmaninnovations.com/minkolang/?code=%28o%22q%22%3D7%26z1%2B%24z8!z2%25%2C2%26iN%24I%24%29%2E&input=eeeeeqeeqeeqqqqeqeqeeqe)
### Explanation
```
(                        Open while loop
 o                       Read in character from input
  "q"                    Push the character "q"
     =                   1 if the top two items on stack are equal, 0 otherwise
      7&                 Pop and jump 7 spaces if truthy
        z                Push register value on stack
         1+              Add one
           $z            Pop top of stack and store in register
             8!          Jump eight spaces
        z                Push register value on stack
         2%              Modulo by 2
           ,             boolean not
            2&           Pop and jump two spaces if truthy
              i          Push loop counter
               N         Output as number
                $I       Push length of input
                  $).    Close while loop when top of stack is 0 and stop.
```
[Answer]
# C (function), 65
Thanks to @Dennis for the extra golfing!
```
i,n;f(char*m){for(i=n=0;*m;i++)*m++&4?++n:n%2?printf("%d ",i):0;}
```
[Answer]
# Python 3, ~~109~~ ~~95~~ ~~80~~ ~~90~~ ~~88~~ ~~76~~ ~~68~~ ~~67~~ ~~66~~ 64 bytes
Counts the number of `q`s and `e`s and adds the index of the current `q` if the number of preceding `e`s is odd.
**Edit:** Now it prints a list of the indices of s that are `q` and have an odd number of `e`s preceding them. Eight bytes saved thanks to [Doorknob](https://codegolf.stackexchange.com/users/3808/doorknob) and two more thanks to [feersum](https://codegolf.stackexchange.com/users/30688/feersum).
```
lambda s:[x for x,m in enumerate(s)if("e"<m)*s[:x].count("e")%2]
```
**Ungolfed:**
```
def f(s):
    c = []
    for index, item in enumerate(s):
        if item == "q":
            if s[:index].count("e")%2 == 1:
                c.append(index)
    return c
```
[Answer]
# JavaScript ES6, ~~63~~ ~~60~~ 58 bytes
```
x=>[...x].map((e,i)=>e>'e'?n%2&&a.push(i):n++,a=[],n=0)&&a
```
Anonymous function that outputs an array. Thanks to user81655 for saving two bytes. Here is an ungolfed version that uses better supported syntax.
```
f=function(x) {
  a=[] // Indeces of syncopated notes
  n=0 // Number of e's encountered so far
  x.split('').map(function(e,i) { // For each letter...
    e>'e'? // If the letter is q...
      n%2&& // ...and the number of e's is odd...
        a.push(i): // ...add the current index to the array
      n++ // Otherwise, it is e so increment the counter
  })
  return a
}
run=function(){document.getElementById('output').textContent=f(document.getElementById('input').value)};document.getElementById('run').onclick=run;run()
```
```
<input type="text" id="input" value="qqqeqqeeeeqeqeqeqqeqqeqq" /><button id="run">Run</button><br />
<samp id="output"></samp>
```
[Answer]
# Mathematica, 76 bytes
```
Flatten[Range[#+1,#2-1]&@@@StringPosition[#,"e"~~"q"..~~"e",Overlaps->1<0]]&
```
Something interesting I noticed. All of the syncopated parts are of form `eqqq..qqe`, so I just detect those and give the indices of the `q`s.
[Answer]
# Japt, ~~29~~ ~~23~~ 21 bytes
Not non-competing anymore!
```
0+U ¬¨¬Æ¬•'e} √•^ √§¬© m¬© f
```
[Try it online!](http://ethproductions.github.io/japt?v=master&code=MCtVIKyupSdlfSDlXiDkqSBtqSBm&input=ImVxcXFlcWVxZXFlcSI=)
### How it works
```
         // Implicit: U = input string, e.g.    "eqqeqeq"
0+U      // Add a 0 to the beginning.           "0eqqeqeq"
¬¨        // Split into chars.                   ['0,'e,'q,'q,'e,'q,'e,'q]
¬Æ¬•'e}    // Map each item X to (X == 'e).       [F, T, F, F, T, F, T, F]
√•^       // Cumulative reduce by XOR'ing.       [0, 1, 1, 1, 0, 0, 1, 1]
√§¬©       // Map each consecutive pair with &&.  [0, 1, 1, 0, 0, 0, 1]
m¬©       // Map each item with &&. This performs (item && index):
         //                                     [0, 1, 2, 0, 0, 0, 6]
f        // Filter out the falsy items.         [   1, 2,          6]
         // Implicit output                     [1,2,6]
```
### Non-competing version, 18 bytes
```
U¬¨m¬•'e √•^ √§¬©0 m¬© f
```
[Try it online!](http://ethproductions.github.io/japt?v=master&code=VaxtpSdlIOVeIOSpMCBtqSBm&input=ImVxcXFlcWVxZXFlcSI=)
[Answer]
# Befunge, 43 bytes
```
:~:0\`#@_5%2/:99p1++\>2%#<9#\9#.g#:*#\_\1+\
```
[Try it online!](http://befunge.tryitonline.net/#code=On46MFxgI0BfNSUyLzo5OXAxKytcPjIlIzw5I1w5Iy5nIzoqI1xfXDErXA&input=ZXFxZXFxZXFxZQ)
**Explanation**
We start with two implicit zeros on the stack: the note number, and a beat count.
```
:               Make a duplicate of the beat count.
~               Read a character from stdin.
:0\`#@_         Exit if it's less than zero (i.e. end-of-file).
5%2/            Take the ASCII value mod 5, div 2, translating q to 1 and e to 0.
:99p            Save a copy in memory for later use.
1+              Add 1, so q maps to 2 and e to 1.
+               Then add that number to our beat count.
\               Get the original beat count that we duplicated at the start.
2%              Mod 2 to check if it's an off-beat.
99g*            Multiply with the previously saved note number (1 for q, 0 for e).
_               Essentially testing if it's a quarter note on an off-beat.
       \.:\     If true, we go turn back left, get the beat count, and output it.
         >2     Then push 2 onto the stack, and turn right again.
2%              That 2 modulo 2 is just zero.
99g*            Then multiplied by the saved note number is still zero.
_               And thus we branch right on the second pass.
\1+\            Finally we increment the note number and wrap around to the start again.
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 11 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
√∞√à√∏¬¨?Tu:!¬∞T
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&header=cQ&code=8Mj4rD9UdTohsFQ&input=ImVlZWVlcWVlcWVlcXFxcWVxZXFlZXFlIg)
]