[Question]
  [
My two kids like to play with the following toy:
[![Turtle](https://i.stack.imgur.com/BYhak.jpg)](https://i.stack.imgur.com/BYhak.jpg)
The colored areas with the shapes inside can be touched and the turtle then lights the area and plays a sound or says the name of the color or the shape inside. The middle button changes the mode. There is one mode in which the areas play different musical notes when touched, with a twist: if the kid touches three consecutive areas clockwise, a special melody 1 is played. If the three consecutive areas touched are placed counterclockwise, a special melody 2 is played.
### The challenge
Let's simulate the internal logic of the toy. Given a string with 3 presses of the kid, return two distinct, coherent values if the three presses are for consecutive areas (clockwise or counterclockwise) and a third distinct value if they are not.
### Details
* The input areas will be named with a character each, which can be their color: `ROYGB` for red, orange, yellow, green and blue; or their shape: `HSRTC` for heart, square, star (`R`), triangle and circle. Case does not matter, you can choose to work with input and output just in uppercase or in lowercase.
* The program will receive a string (or char array or anything equivalent) with three presses. Examples (using the colors): `RBO`, `GYO`, `BBR`, `YRG`, `YGB`, `ORB`...
* The program will output three distinct, coherent values to represent the three possible outcomes: a first value if the combination does not trigger a special melody, a second value if the combination triggers the clockwise special melody, and a third value if the combination triggers the counterclockwise special melody. Example: `0` for no special combination, `1` for the melody triggered by a clockwise combination and `-1` for the melody triggered by a counterclockwise combination.
* You do not need to worry about handling wrong input.
### Test cases
```
Input   Output      // Input based on colors
--------------
RBO     0           // No special combination
GYO     -1          // Counterclockwise melody triggered
BBR     0           // No special combination
YRG     0           // No special combination
YGB     1           // Clockwise melody triggered
ORB     -1          // Counterclockwise melody triggered
OOO     0           // No special combination
BRO     1           // Clockwise melody triggered
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so may the shortest code for each language win!
  
[Answer]
# Java 8, ~~48~~ ~~39~~ 33 bytes
```
s->"ROYGBRO BGYORBG".indexOf(s)|7
```
-6 bytes thanks to *@RickHitchcock*, so make sure [to upvote him as well](https://codegolf.stackexchange.com/a/174590/52210)!
Takes uppercase color as input-String. Outputs `-1` for none, `7` for clockwise, and `15` for counterclockwise.
[Try it online.](https://tio.run/##jVE9j8IwDN37K6xO7UAZke4EQxgy0Uhhqk4MIQ0oUBJEUg4E/e3FLTBCukSy/Zz34Z04i9Gu3LeyEs7BQmhziwC08eq0EVJB3pV9A2Sy9CdttuDSX2w2ET7OC68l5GBgCq0bzWLOCko4A0ILxgmNM21KdWGbxKX3SdstHut1hTuv1bPVJRyQ9/X73wpE@iQdjyG3Rv30xfLqvDpktvbZEXG@MonJZBJzwuK0F/QZQwgPYgpOgxjGvnLh5K17Xlm5/9cuIB6jCovnYYMY@lBhtu5uK4fpwxuGQ@EDPNAi7IG8D9BETfsA)
**Explanation:**
```
s->      // Method with String parameter and integer return-type
   "ROYGBRO BGYORBG".indexOf(s)
         //  Get the index of the input in the String "ROYGBRO BGYORBG",
         //  which will result in -1 if the input is not a substring of this String
    |7   //  Then take a bitwise-OR 7 of this index, and return it as result
```
---
**Old 39 bytes answer:**
```
s->(char)"ROYGBRO BGYORBG".indexOf(s)/7
```
Takes uppercase color as input-String. Outputs `9362` for none, `0` for clockwise, and `1` for counterclockwise.
[Try it online.](https://tio.run/##jZGxbsMgEIZ3P8XJEwyxx0qp2oEMTDUSmawqA8UkwXEgMjhpFfnZXey6Y4IXpLv7j@@/u1pcxaquToNshHPwIbS5JwDaeNXuhVRQjOGUAIm2vtXmAA6/hmSfhMd54bWEAgy8weBW70geRYtTzkpKOANCS8YJTTNtKvXN9sjh/GUY2y/dVxM65w@uVldwDvSZ8bkDgf/QeQ6FNWo9Bdsf59U5s53PLkHnG4NMJlHKCUvxZOuxhhAe1ZScRjWMPWWFyr/vTWPl6aZdxHxYVdw8Xwy13Xg9uYwd7hMfmC/wR8tZ0yf98As)
**Explanation:**
```
s->      // Method with String parameter and integer return-type
   (char)"ROYGBRO BGYORBG".indexOf(s)
         //  Get the index of the input in the String "ROYGBRO BGYORBG",
         //  which will result in -1 if the input is not a substring of this String
         //  And cast it to a char (-1 becomes character with unicode value 65535)
    /7   //  Integer-divide it by 7 (the char is implicitly converted to int doing so)
```
[Answer]
# JavaScript (ES6), 41 bytes
Takes color initials as input. Returns `2` for none, `true` for clockwise or `false` for counterclockwise.
```
s=>~(x='ROYGBRO_ORBGYOR'.search(s))?x<5:2
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/Y1q5Oo8JWPcg/0t0pyD/eP8jJPdI/SF2vODWxKDlDo1hT077CxtTK6H9yfl5xfk6qXk5@ukaahnqQk7@6pqaCvr6CEReaFNAAqFRaYk5xKrq0k1MQLp2RQe44pdydoFIlRaUYZgKdjc9Kf3@cjgV6Gsnc/wA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 36 bytes
```
lambda i:'ROYGBRO ORBGYOR'.find(i)/7
```
`-1` - None  
`0` - Clockwise  
`1` - Counterclockwise 
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHTSj3IP9LdKchfwT/IyT3SP0hdLy0zL0UjU1Pf/H9BUWZeiUKahnqQk7@6JhecC1SHzHVyCkLmRga5o3DdnZC5QGtQuP6oRgUBuf8B "Python 2 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~15~~ 11 bytes
Saved 4 bytes thanks to *Kevin Cruijssen* and *Magic Octopus Urn*.
Uses shapes.  
Output `[0, 0]` for *none*, `[1, 0]` for *clockwise* and `[0, 1]` for *counter-clockwise*
```
Â‚.•ÌöJη•så
```
[Try it online!](https://tio.run/##yy9OTMpM/f//cNOjhll6jxoWHe45vM3r3HYgq/jw0v//i0qSAQ "05AB1E – Try It Online")
or as a [Test suite](https://tio.run/##yy9OTMpM/V9TVln5/3DTo4ZZeo8aFh3uObzN69x2IKv48NL/lUqH9yvo2iko2ev8z0gu5iopKuZKTs7gKsoo4SoqSeYqzgDiYqBYRjEA)
**Explanation**
```
Â‚            # pair the input with its reverse
  .•ÌöJη•     # push the string "hsrtchs"
         så   # check if the input or its reverse is in this string
```
[Answer]
## Excel, 29 bytes
```
=FIND(A1,"ROYGBRO_RBGYORB")<6
```
Uppercase colours as input.
Returns `#VALUE!` for no pattern, `TRUE` for clockwise, `FALSE` for anti-clockwise.
Can wrap in `IFERROR( ,0)` for `+11 bytes` to handle exception , and return '0' for no-pattern cases instead.
[Answer]
# JavaScript (ES6), 32 bytes
```
s=>'ROYGBRO_ORBGYOR'.search(s)|7
```
Returns -1 if no combination, 15 if counterclockwise, 7 if clockwise.
```
let f =
s=>'ROYGBRO_ORBGYOR'.search(s)|7
console.log(f('RBO')) // -1
console.log(f('GYO')) // 15
console.log(f('BBR')) // -1
console.log(f('YRG')) // -1
console.log(f('YGB')) // 7
console.log(f('ORB')) // 15
console.log(f('OOO')) // -1
console.log(f('BRO')) // 7
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~42~~ 36 bytes
```
{"ROYGBRO","ORBGYOR"}~StringCount~#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78H1CUmVcS/b9aKcg/0t0pyF9JR8k/yMk90j9IqbYuuAQom@6cX5pXUqes9l/fQQGozslfSUFHQQmoBEwDdYFpoC4I7Q8RB5mlUBv7HwA "Wolfram Language (Mathematica) – Try It Online")
Counts the number of times the input appears in both `"ROYGBRO"` and `"ORBGYOR"`. Returns `{1,0}` for clockwise, `{0,1}` for counterclockwise, and `{0,0}` for no special combination.
At the cost of only one more byte, we can get outputs of `0` for nothing, `1` for clockwise, and `2` for counterclockwise with `"ROYGBRO.ORBGYORBGYOR"~StringCount~#&`.
[Answer]
# x86 machine code, ~~39~~ 36 bytes
```
00000000: f30f 6f29 b815 0000 0066 0f3a 6328 0c89  ..o).....f.:c(..
00000010: c883 c807 c352 4f59 4742 524f 2042 4759  .....ROYGBRO BGY
00000020: 4f52 4247                                ORBG
```
Assembly:
```
section .text
	global func
func:					;the function uses fastcall conventions
					;no stack setup needed because we don't need to use stack
	movdqu xmm5,[ecx]		;Move DQword (16 bytes) from 1st arg to func(ecx) to SSE reg
	mov eax, msg			;Load address of constant str 'msg' into eax
	PcmpIstrI xmm5, [eax], 1100b	;Packed Compare String Return Index, get idx of [eax] in xmm5
	mov eax, ecx			;Move returned result into reg eax
	or eax, 7			;Bitwise OR eax with 7 to get consistent values
	ret				;return to caller, eax is the return register
	msg db 'ROYGBRO BGYORBG'
```
[Try it online!](https://tio.run/##bVNRT9swEH6Of8WpEmtTGtaCNiQKPGSwDmkoLDwhqCrHdtKwxM5spw1C/PbunKyi1cjDKT5/33ff@eyEmuWGUQvn59fRd7iEz7asPtMjasqNEczmSsKRFY0lXlaohBaQ1pIRF848903tUrS5FlobYSClxjJaFMCUXAnpNgzpwFKBsZT9BiNsXYEUggsOiWAUmbAWwJXs2zYPVjm5Dk@8Uq34nxqasvwyehSsmaParVoJuPq1VprDYPIVkhcrjA@pViVMjAWqM6fi3A2Q4rvF/f01aJG1giBoM4LSZM7aT0U5UM61MAZU6sxjaWnRgIY@gvqQSxRADvHuWFnd4MZNZwgeMTsfwWQyHife9A4dYwPfVFlRLeDe6lxmEGPLWsKN5AKrZsJCzhtXqSWjeKu1Ywwte9sudUtGUbRXF7azgn10dpTuGKcOH@Z2nePBRbFLwjq3Szh1rbuSrqvcWJwKrGhRCxwMSrez6Uo4oBue0KOWnhtwE/63iRUdW6NLkwFPoB9HD7MwjiCcPURxOOtv8BoR8t@NMrZOjhjBiyRQBt3DYkEtHkxSW7FYDAbbS@P73bzYkuqhPwXisCXN5cB/JV6bxSFb8zi/eO3FYdQb9bAyxjCMMT7EMxdnIUb042LU7sYYx29T4qVKD5xmfjGedkr5fJofHjp5r8JJ2XTQOzBncMCfZG@0hYxaV9uV76PSG3kjbbcSXwsEqSjSk@OdBwSB6lZMcXGkSMbYfgoJu6ezC4ZAqqDKBQTlyTFRyTNT1QsEESS5pBr/nrtnucd5/0cUcSxelxUEVxDcujMXxR788tMxEWyJtQT0nuRwOAzxAeEVqaU9w1WvRazRNIPzffEPuD9E46q9E5uGf0Aie@1v/gI "Try It Online")
Output is `23` for none, `7` for clockwise, and `15` for counter-clockwise. Based on @RickHitchcock 's answer.
Edit 1: Saved 3 bytes by using an SSE string comparison instruction instead of using libc.
Edit 2: Use proper calling convention for SSE (use XMM5 instead of XMM2) and improve formatting on Bash.
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 30 bytes
```
$_=ROYGBRO=~/$_/-ORBGYOR=~/$_/
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3jbIP9LdKcjftk5fJV5f1z/IyT3SPwjC@/8fKPEvv6AkMz@v@L@ur6megaHBf90CAA "Perl 5 – Try It Online")
[Answer]
# APL(Dyalog), ~~22~~ 18 bytes
```
+/(⍷-⍷∘⌽)∘'ROYGBRO'
```
*-4 bytes thanks to @ngn*
Takes a string of color initials. Outputs 0 for no special pattern, -1 for counterclockwise, 1 for clockwise.
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///X1tf41Hvdl0gftQx41HPXk0gpR7kH@nuFOSv/j/tUduER719j/qmevo/6mo@tN74UdtEIC84yBlIhnh4Bv9PUw9y8lfnSlN3jwRTTk5BICoyyB1MuTuBKP8gCOUPUQI0GgA)
[Answer]
# [Python 2](https://docs.python.org/2/), ~~45~~ 43 bytes
```
lambda i,a='ROYGBRO':(i in a)-(i[::-1]in a)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSFTJ9FWPcg/0t0pyF/dSiNTITNPIVFTVyMz2spK1zAWzPtfUJSZV6KQpqEe5OSvrskF57pHonCdnIKQuZFB7ihcdydkrn8QKtcf1SigazT/AwA "Python 2 – Try It Online")
With ideas from and serious credit to @DeadPossum
-2 with thanks to @JoKing. Now outputs -1 = counterclockwise, 0 = none, 1 = clockwise.
My original effort is below for historical purposes.
# [Python 2](https://docs.python.org/2/), ~~52~~ 51 bytes
```
lambda i,a='ROYGBRO':((0,1)[i[::-1]in a],2)[i in a]
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSFTJ9FWPcg/0t0pyF/dSkPDQMdQMzoz2spK1zA2M08hMVbHCMhXADP/FxRl5pUopGmoBzn5q2tywbnukShcJ6cgZG5kkDsK190JmesfhMr1RzUK6CrN/wA "Python 2 – Try It Online")
0 = none, 1 = counterclockwise, 2 = clockwise
[Answer]
# [Python 2](https://docs.python.org/2/), ~~35~~ 36 bytes
+1 - for some reason I thought all buttons would be distinct >\_<
*Developed independently from [what I have just seen](https://codegolf.stackexchange.com/a/174582/53748) (and now up-voted) by Dead Possum*
```
lambda s:'ORBGYO.BROYGBR'.find(s)/7
```
**[Try it online!](https://tio.run/##lZBRS8NADMff@ynylha6CvogDCqsRcpQLFRBhvOha6/stL077lLET19znQ6GOPAeApf88/snMZ@01@py6tLt1NfDrq3BLbGssmJTVklWlZsiqzDppGpDF11cT/l9md89rx9vIYUX5DrGyCKOrOTo5TFyI74Gq4en9amewVxlutcUvpd9fG9ZsT4wVioCzHvdvH9IJ5YYdNoCCUcgFRxZywD4HdS@GAMubjCGLvS/6IeDR@JKkVw0f2BPxvw3uqS9sGC0c3LXC@aZkRwbWD2AJGFJ696BHIy2xFzdjg3N9sZ7fydCnC/NPlYYUVN6FR0GmWdM2S9501KFJpqzsvt9Ezi/kX@N5jOoUZxfcfoC "Python 2 – Try It Online")**
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~14~~ 13 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ù♀e▌d─█£F'♦O▬
```
[Run and debug it](https://staxlang.xyz/#p=970c65dd64c4db9c4627044f16&i=RBO%0AGYO%0ABBR%0AYRG%0AYGB%0AORB%0AOOO%0ABRO&a=1&m=2)
The output is
* 1 for no special combination
* 2 for counter-clockwise melody
* 3 for clockwise melody
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 19 bytes
```
Y"ROYGBRO"OaNyaNRVy
```
Outputs `10` for clockwise, `01` for counterclockwise, `00` for neither. [Try it online!](https://tio.run/##K8gs@P8/UinIP9LdKchfyT/RrzLRLyis8v///0AxAA "Pip – Try It Online")
### Explanation
```
                     a is 1st cmdline argument
Y"ROYGBRO"           Yank that string into y variable
           aNy       Count of occurrences of a in y
          O          Output without newline
                RVy  y reversed
              aN     Count of occurrences of a in that string
                     Print (implicit)
```
[Answer]
# [J](http://jsoftware.com/), 21 bytes
```
-&(OR@E.&'ROYGBRO')|.
```
[Try it online!](https://tio.run/##y/qvpKegnqZga6WuoKNQa6VgoADE/3XVNPyDHFz11NSD/CPdnYL81TVr9P5rcqUmZ@QrANXYKqQpqAc5@atDROINISLukTARmBonpyA0kcggd5gIVBfQAjRz/IOc0HT5@/uj6QI56j8A "J – Try It Online")
### How it works
```
-&(OR@E.&'ROYGBRO')|.  Monadic 2-verb hook. Input: a string.
                   |.  Map over [input string, input string reversed]:
      E.&'ROYGBRO'     Find exact matches of input in 'ROYGBRO'
  (OR@            )    Reduce with OR; is it a substring of 'ROYGBRO'?
-&                     Reduce with -; result is 1 for CW, -1 for CCW, 0 otherwise
```
Achieves maximum amount of function reuse.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
,Ṛẇ€“¤ƈẎṬ%Ȥ»
```
[Try it online!](https://tio.run/##ASkA1v9qZWxsef//LOG5muG6h@KCrOKAnMKkxojhuo7huawlyKTCu////2d5bw "Jelly – Try It Online")
-4 thanks to [Jonathan Allan](https://codegolf.stackexchange.com/questions/174564/playing-with-the-musical-turtle/174588?noredirect=1#comment420882_174588).
Clockwise: `[1, 0]`  
Counter-clockwise: `[0, 1]`  
Other: `[0, 0]`
[Answer]
# [R](https://www.r-project.org/), 38 bytes
```
grep(scan(,''),c('ROYGBRO','ORBGYOR'))
```
[Try it online!](https://tio.run/##pZJBb4MgFMfvfoqX9IAkatYem20HdvA2Em4eKT4dqaJBjGuWfXYHtWt6WbpNTgT@P/i9B3bewGRl36MF1wG2YyMdwuBKbfrRwaTdG0ioRqOc7gzEg2wRDiefUd1oHI2qp@/N@J1@DEqax/S6kmUZtehGGzbn2mIfh0ScEEITFRPBi5wJThLCBcsLLgil82cUbUCcqQH2fg4pvHYw9Ki0bPy97UEbeda5GXvQxmGNNn6gsEAvwRCtajp1nPSA0GLTlSdwVtc@iKWHdpfoz5nr@dsoqrwy44QCbH6h5Ef6fKMVcF/kgt@XW/BdoBgTay4tRL4Kz9nF@W6XFnwbKP@i/6iU81XtDZ/pb6rzFw "R – Try It Online")
Returns :
* No special combination : `integer(0)`
* Counterclockwise melody triggered : `2`
* Clockwise melody triggered : `1`
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 18 bytes
```
≔ROYGBROηＩ⁻№ηθ№⮌ηθ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/9@xuDgzPU9DKcg/0t0pyF9JRyFD05oroCgzr0TDObG4RMM3M6@0WMM5vxQokKGjUKipowDhBKWWpRYVp2pkaIJEgcD6/3//IKf/umU5AA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
 ROYGBRO            Literal string
≔       η           Assign to variable
            η   η   Value of variable
               ⮌    Reversed
             θ   θ  Input string
           №  №     Count matches
          ⁻         Subtract
         Ｉ          Cast to string
                    Implicitly print
```
[Answer]
# [Common Lisp](http://www.clisp.org/), 68 bytes
```
(defun x(s)(cond((search s "ROYGBRO")1)((search s "BGYORBG")-1)(0)))
```
[Try it online!](https://tio.run/##Zc0xCsMwDIXhvacQnvSGQnMFLR4N2jwGJyWB4Ia4hdzeEZkSd/349ZSWuay18jC@f5l2LuD0yQNzGfstTVTIaYheNDh0uLL4GFS8w9P8BaDyus35S7zbjViPx0WsbkREG4lqcyC6mZemsq@thL9tPaUe "Common Lisp – Try It Online")
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 63 bytes
```
import StdEnv,Text
$s=map((>)0o indexOf s)["ROYGBRO","BGYORBG"]
```
[Try it online!](https://tio.run/##S85JTcz7n5ufUpqTqpCbmJn3PzO3IL@oRCG4JMU1r0wnJLWihEul2DY3sUBDw07TIF8hMy8ltcI/TaFYM1opyD/S3SnIX0lHyck90j/IyV0p9n9wSSJQu62CioISUE7p/7/ktJzE9OL/up4@/10q8xJzM5MhnICcxJK0/KJcAA "Clean – Try It Online")
`[True, True]` for no special noises, `[True, False]` for counterclockwise, `[False, True]` for clockwise.
[Answer]
# Japt, ~~17~~ 14 bytes
Takes the colours as input, in lowercase. Returns `0` for clockwise, `1` for counterclockwise or `-1` if there's no combo.
```
`ygß`ê qÔbøU
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=YJ55Z9+WYOogcdRi+FU=&input=InJibyI=)
---
## Expanation
```
`...`            :Compressed string "roygbrow"
     ê           :Palindromise
       qÔ        :Split on "w"
         b       :Index of the first element
          ø      : That contains
           U     :  The input string
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~53~~ 36 bytes
```
->n{"\a\fDch+".index(""<<n%111)&./3}
```
[Try it online!](https://tio.run/##DclBDoIwEAXQq5gmEolDzZ8ZdujKW5QuUGx0QUOakEiAsxe276XpNedwz9UjLqbt2vB8f6/G/mL/@V@MaZp4BlAW9iZbdmClWphUQSJCYCGWw8CEWkmPE4a3Qzcua1rHk0sUXPJ@yzs "Ruby – Try It Online")
Input: a 3-digit integer, where the digits represent colors:
* 1 - red
* 2 - orange
* 3 - yellow
* 4 - green
* 5 - blue
Output:0 for clockwise, 1 for counterclockwise, `nil` otherwise.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 55 bytes
Returns 0 for none, -1 for CCW and 1 for CW.
```
f(char*s){s=!strstr("ORBGYOR",s)-!strstr("ROYGBRO",s);}
```
[Try it online!](https://tio.run/##PY6xCsMwDET3foVqCNiJM3ROs3jJKNAW2g7BJamHpsUOWUK@XZVLKQh09ySO8/XkPfOo/WOIZTJbao9piTJaIbmuR1I2mfoPCfvOEWbY7BzmBZ5DmHUWQ5y8hRwEZSlmNbAdAMZX/J5De2ognPOX7Koy8I7CR62KBC0U9@usbA5ZL@FmYdQ/aUxz2JnJIUsddo64p46lBktDRhRG@AE "C (gcc) – Try It Online")
]