Playing with the musical turtle
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
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 user will receive a string (or char array or anything equivalent) with three presses. Examples (using the colors):
RBO
,GYO
,BBR
,YRG
,YGB
,ORB
... - The user 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!
code-golf string subsequence classification
add a comment |Â
up vote
3
down vote
favorite
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 user will receive a string (or char array or anything equivalent) with three presses. Examples (using the colors):
RBO
,GYO
,BBR
,YRG
,YGB
,ORB
... - The user 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!
code-golf string subsequence classification
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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 user will receive a string (or char array or anything equivalent) with three presses. Examples (using the colors):
RBO
,GYO
,BBR
,YRG
,YGB
,ORB
... - The user 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!
code-golf string subsequence classification
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 user will receive a string (or char array or anything equivalent) with three presses. Examples (using the colors):
RBO
,GYO
,BBR
,YRG
,YGB
,ORB
... - The user 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!
code-golf string subsequence classification
code-golf string subsequence classification
asked 54 mins ago


Charlie
7,0882184
7,0882184
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
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!
add a comment |Â
up vote
1
down vote
05AB1E, 15 bytes
Uses shapes.
Output 0
for none, 1
for clockwise and 2
for counter-clockwise
.•ÌöJη•Â)εIå}ƶO
Try it online!
or as a Test suite
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
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!
add a comment |Â
up vote
3
down vote
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!
add a comment |Â
up vote
3
down vote
up vote
3
down vote
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!
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!
edited 27 mins ago
answered 37 mins ago


Arnauld
66.6k583281
66.6k583281
add a comment |Â
add a comment |Â
up vote
1
down vote
05AB1E, 15 bytes
Uses shapes.
Output 0
for none, 1
for clockwise and 2
for counter-clockwise
.•ÌöJη•Â)εIå}ƶO
Try it online!
or as a Test suite
add a comment |Â
up vote
1
down vote
05AB1E, 15 bytes
Uses shapes.
Output 0
for none, 1
for clockwise and 2
for counter-clockwise
.•ÌöJη•Â)εIå}ƶO
Try it online!
or as a Test suite
add a comment |Â
up vote
1
down vote
up vote
1
down vote
05AB1E, 15 bytes
Uses shapes.
Output 0
for none, 1
for clockwise and 2
for counter-clockwise
.•ÌöJη•Â)εIå}ƶO
Try it online!
or as a Test suite
05AB1E, 15 bytes
Uses shapes.
Output 0
for none, 1
for clockwise and 2
for counter-clockwise
.•ÌöJη•Â)εIå}ƶO
Try it online!
or as a Test suite
answered 26 mins ago


Emigna
43.9k431133
43.9k431133
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174564%2fplaying-with-the-musical-turtle%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password