20
2
My two kids like to play with the following toy:
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, so may the shortest code for each language win!
Is
[0,0]
,[1,0]
,[0,1]
allowed as output? I see the Mathematica answer doing that, and it would save 3 bytes in the 05AB1E answer. – Kevin Cruijssen – 2018-10-23T14:52:44.5101@KevinCruijssen of course you can. The output values can be anything as long as they are distinct and consistent. – Charlie – 2018-10-23T14:55:35.290