# 找到对应词

33

``````eqqeqqeqqe
**    **
12    78
Output: 1 2 7 8
``````

``````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>
``````

1

Luis Mendo

1

1
@LuisMendo当然可以，如果它会使您的代码更短。
Doorknob

@PeterTaylor好的，是您想的那样吗？

12

# 果冻，12 9 字节

``````=“e”µ<^\O
``````

### 怎么运行的

``````=“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.
``````

### 更新资料

``````=”eµ<^\O
``````

7

# Ruby，46岁

``````i=e=0
gets.bytes{|n|e^=n
e&4|n>114&&p(i)
i+=1}
``````

``````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
``````

6

# 的JavaScript ES7，50 48个字节

``````s=>[for(c of(i=f=0,s))if(++i&&c>'e'?f%2:f++&0)i]
``````

### 测试片段

``````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 />``````

3

Aᴄʜᴇʀᴏɴғᴀɪʟ

@Neil我尝试将ES6帖子更新为ES6 / 7，但是OP撤消了编辑。同时，这里是：codegolf.stackexchange.com/a/61489/42545
ETHproductions 2016年

5

## J，20 19 17字节

``````=&'e'(I.@:<~:/\@)
``````

``````  f =: =&'e'(I.@:<~:/\@)
f 'eqqqe'
1 2 3
``````

## 说明

``````=&'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
``````

5

# GNU grep，3 + 17 = 20 3 + 15 = 18个字节

``````q(?!(q|eq*e)*\$)
``````

``````1:q
2:q
3:q
``````

• `P`：使用PCRE正则表达式。
• `o`：这意味着仅打印与正则表达式匹配的行部分，但这并不是为什么它很重要。`o`之所以使用，是因为它具有允许每行进行多个匹配的效果。
• `b`：从文件的开头打印每个匹配项开头的偏移量（以字节为单位）。

Digital Trauma

@DigitalTrauma我不明白为什么不...它可以使用PCRE正则表达式，因此它至少应该是图灵完整的，并且可以从文件中执行代码，如下所示。
feersum

Digital Trauma

@DigitalTrauma Huh，看来我因图灵完备性而受骗。
feersum

5

# MATL，12 14 16字节

``````j101=tYs2\<f
``````

``````>> matl j101=tYs2\<f
> eeeeeqeeqeeqqqqeqeqeeqe
6  9 12 13 14 15 19 22
``````

## 说明

``````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
``````

3

# 蟒蛇2，94 85 79 75 66字节

``````e=0
for j,k in enumerate(input()):
if"q">k:e+=1
elif e%2:print j
``````

Alex A.

Alex A.

Alex A.

2
@TanMath我问Doorknob，因为它将为我节省2个字节来输入带引号的输入。但这无法完成
Luis Mendo

3

``````f x=[i|(i,'q')<-zip[0..]x,odd\$sum[1|'e'<-take i x]]
``````

2

## Minkolang 0.15，28个字节

``````(o"q"=7&z1+\$z8!z2%,2&iN\$I\$).
``````

### 说明

``````(                        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
\$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.
``````

2

# C（功能），65

``````i,n;f(char*m){for(i=n=0;*m;i++)*m++&4?++n:n%2?printf("%d ",i):0;}
``````

1

2

# Python 3、109 95 80 90 88 76 68 67 66 64字节

``````lambda s:[x for x,m in enumerate(s)if("e"<m)*s[:x].count("e")%2]
``````

``````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
``````

1

Doorknob

feersum

2

# JavaScript的ES6，63个60 58字节

``x=>[...x].map((e,i)=>e>'e'?n%2&&a.push(i):n++,a=[],n=0)&&a``

``````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>``````

0

# Mathematica，76个字节

``````Flatten[Range[#+1,#2-1]&@@@StringPosition[#,"e"~~"q"..~~"e",Overlaps->1<0]]&
``````

0

# Japt，29 23 21字节

``````0+U ¬®¥'e} å^ ä© m© f
``````

### 怎么运行的

``````         // 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]
``````

### 非竞争版本，18字节

``````U¬m¥'e å^ ä©0 m© f
``````

0

# Befunge，43个字节

``````:~:0\`#@_5%2/:99p1++\>2%#<9#\9#.g#:*#\_\1+\
``````

``````:               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.
``````