Playing with the musical turtle

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












My two kids like to play with the following toy:



Turtle



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!










share|improve this question

























    up vote
    3
    down vote

    favorite












    My two kids like to play with the following toy:



    Turtle



    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!










    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      My two kids like to play with the following toy:



      Turtle



      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!










      share|improve this question













      My two kids like to play with the following toy:



      Turtle



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 54 mins ago









      Charlie

      7,0882184




      7,0882184




















          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!






          share|improve this answer





























            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






            share|improve this answer




















              Your Answer




              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("mathjaxEditing", function ()
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
              );
              );
              , "mathjax-editing");

              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "200"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              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






























              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!






              share|improve this answer


























                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!






                share|improve this answer
























                  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!






                  share|improve this 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!







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 27 mins ago

























                  answered 37 mins ago









                  Arnauld

                  66.6k583281




                  66.6k583281




















                      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






                      share|improve this answer
























                        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






                        share|improve this answer






















                          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






                          share|improve this answer













                          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







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 26 mins ago









                          Emigna

                          43.9k431133




                          43.9k431133



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              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













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery