diff --git a/config.json b/config.json index bbb2f7d..93de9f6 100644 --- a/config.json +++ b/config.json @@ -446,6 +446,14 @@ "practices": [], "prerequisites": [], "difficulty": 4 + }, + { + "slug": "secret-handshake", + "name": "Secret Handshake", + "uuid": "17246658-c302-4df0-adde-92dac6f77a8d", + "practices": [], + "prerequisites": [], + "difficulty": 2 } ] }, diff --git a/exercises/practice/secret-handshake/.docs/instructions.md b/exercises/practice/secret-handshake/.docs/instructions.md new file mode 100644 index 0000000..d2120b9 --- /dev/null +++ b/exercises/practice/secret-handshake/.docs/instructions.md @@ -0,0 +1,48 @@ +# Instructions + +Your task is to convert a number between 1 and 31 to a sequence of actions in the secret handshake. + +The sequence of actions is chosen by looking at the rightmost five digits of the number once it's been converted to binary. +Start at the right-most digit and move left. + +The actions for each number place are: + +```plaintext +00001 = wink +00010 = double blink +00100 = close your eyes +01000 = jump +10000 = Reverse the order of the operations in the secret handshake. +``` + +Let's use the number `9` as an example: + +- 9 in binary is `1001`. +- The digit that is farthest to the right is 1, so the first action is `wink`. +- Going left, the next digit is 0, so there is no double-blink. +- Going left again, the next digit is 0, so you leave your eyes open. +- Going left again, the next digit is 1, so you jump. + +That was the last digit, so the final code is: + +```plaintext +wink, jump +``` + +Given the number 26, which is `11010` in binary, we get the following actions: + +- double blink +- jump +- reverse actions + +The secret handshake for 26 is therefore: + +```plaintext +jump, double blink +``` + +~~~~exercism/note +If you aren't sure what binary is or how it works, check out [this binary tutorial][intro-to-binary]. + +[intro-to-binary]: https://medium.com/basecs/bits-bytes-building-with-binary-13cb4289aafa +~~~~ diff --git a/exercises/practice/secret-handshake/.docs/introduction.md b/exercises/practice/secret-handshake/.docs/introduction.md new file mode 100644 index 0000000..176b92e --- /dev/null +++ b/exercises/practice/secret-handshake/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +You are starting a secret coding club with some friends and friends-of-friends. +Not everyone knows each other, so you and your friends have decided to create a secret handshake that you can use to recognize that someone is a member. +You don't want anyone who isn't in the know to be able to crack the code. + +You've designed the code so that one person says a number between 1 and 31, and the other person turns it into a series of actions. diff --git a/exercises/practice/secret-handshake/.meta/config.json b/exercises/practice/secret-handshake/.meta/config.json new file mode 100644 index 0000000..97578c5 --- /dev/null +++ b/exercises/practice/secret-handshake/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "SimaDovakin" + ], + "files": { + "solution": [ + "secretHandshake.u" + ], + "test": [ + "secretHandshake.test.u" + ], + "example": [ + ".meta/examples/secretHandshake.example.u" + ] + }, + "blurb": "Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.", + "source": "Bert, in Mary Poppins", + "source_url": "https://www.imdb.com/title/tt0058331/quotes/?item=qt0437047" +} diff --git a/exercises/practice/secret-handshake/.meta/examples/secretHandshake.example.u b/exercises/practice/secret-handshake/.meta/examples/secretHandshake.example.u new file mode 100644 index 0000000..3144b99 --- /dev/null +++ b/exercises/practice/secret-handshake/.meta/examples/secretHandshake.example.u @@ -0,0 +1,23 @@ +unique type secretHandshake.Command + = Wink + | DoubleBlink + | CloseYourEyes + | Jump + +secretHandshake.commands : Nat -> [Command] +secretHandshake.commands encodedMessage = + collectCommand = cases + acc, (code, command) | and encodedMessage code != 0 -> command(acc) + acc, _ -> acc + reverseOrNot message cmds = + match and message 16 != 0 with + true -> cmds + false -> List.reverse cmds + [ + (1, List.cons Wink), + (2, List.cons DoubleBlink), + (4, List.cons CloseYourEyes), + (8, List.cons Jump) + ] + |> List.foldLeft collectCommand [] + |> reverseOrNot encodedMessage diff --git a/exercises/practice/secret-handshake/.meta/testAnnotation.json b/exercises/practice/secret-handshake/.meta/testAnnotation.json new file mode 100644 index 0000000..cb67680 --- /dev/null +++ b/exercises/practice/secret-handshake/.meta/testAnnotation.json @@ -0,0 +1,46 @@ +[ + { + "name": "secretHandshake.commands.tests.ex1", + "test_code": "expect ([Wink] === secretHandshake.commands 1)\n |> Test.label \"wink for 1\"" + }, + { + "name": "secretHandshake.commands.tests.ex2", + "test_code": "expect ([DoubleBlink] === secretHandshake.commands 2)\n |> Test.label \"double blink for 10\"" + }, + { + "name": "secretHandshake.commands.tests.ex3", + "test_code": "expect ([CloseYourEyes] === secretHandshake.commands 4)\n |> Test.label \"close your eyes for 100\"" + }, + { + "name": "secretHandshake.commands.tests.ex4", + "test_code": "expect ([Jump] === secretHandshake.commands 8)\n |> Test.label \"jump for 1000\"" + }, + { + "name": "secretHandshake.commands.tests.ex5", + "test_code": "expect ([Wink, DoubleBlink] === secretHandshake.commands 3)\n |> Test.label \"combine two actions\"" + }, + { + "name": "secretHandshake.commands.tests.ex6", + "test_code": "expect ([DoubleBlink, Wink] === secretHandshake.commands 19)\n |> Test.label \"reverse two actions\"" + }, + { + "name": "secretHandshake.commands.tests.ex7", + "test_code": "expect ([Jump] === secretHandshake.commands 24)\n |> Test.label \"reversing one action gives the same action\"" + }, + { + "name": "secretHandshake.commands.tests.ex8", + "test_code": "expect ([] === secretHandshake.commands 16)\n |> Test.label \"reversing no actions still gives no actions\"" + }, + { + "name": "secretHandshake.commands.tests.ex9", + "test_code": "expect ([Wink, DoubleBlink, CloseYourEyes, Jump] === secretHandshake.commands 15)\n |> Test.label \"all possible actions\"" + }, + { + "name": "secretHandshake.commands.tests.ex10", + "test_code": "expect ([Jump, CloseYourEyes, DoubleBlink, Wink] === secretHandshake.commands 31)\n |> Test.label \"reverse all possible actions\"" + }, + { + "name": "secretHandshake.commands.tests.ex11", + "test_code": "expect ([] === secretHandshake.commands 0)\n |> Test.label \"do nothing for zero\"" + } +] \ No newline at end of file diff --git a/exercises/practice/secret-handshake/.meta/testLoader.md b/exercises/practice/secret-handshake/.meta/testLoader.md new file mode 100644 index 0000000..de16f95 --- /dev/null +++ b/exercises/practice/secret-handshake/.meta/testLoader.md @@ -0,0 +1,9 @@ +# Testing transcript for secret-handshake exercise + +```ucm +.> load ./secretHandshake.u +.> add +.> load ./secretHandshake.test.u +.> add +.> move.term secretHandshake.tests tests +``` diff --git a/exercises/practice/secret-handshake/.meta/tests.toml b/exercises/practice/secret-handshake/.meta/tests.toml new file mode 100644 index 0000000..f318e52 --- /dev/null +++ b/exercises/practice/secret-handshake/.meta/tests.toml @@ -0,0 +1,43 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[b8496fbd-6778-468c-8054-648d03c4bb23] +description = "wink for 1" + +[83ec6c58-81a9-4fd1-bfaf-0160514fc0e3] +description = "double blink for 10" + +[0e20e466-3519-4134-8082-5639d85fef71] +description = "close your eyes for 100" + +[b339ddbb-88b7-4b7d-9b19-4134030d9ac0] +description = "jump for 1000" + +[40499fb4-e60c-43d7-8b98-0de3ca44e0eb] +description = "combine two actions" + +[9730cdd5-ef27-494b-afd3-5c91ad6c3d9d] +description = "reverse two actions" + +[0b828205-51ca-45cd-90d5-f2506013f25f] +description = "reversing one action gives the same action" + +[9949e2ac-6c9c-4330-b685-2089ab28b05f] +description = "reversing no actions still gives no actions" + +[23fdca98-676b-4848-970d-cfed7be39f81] +description = "all possible actions" + +[ae8fe006-d910-4d6f-be00-54b7c3799e79] +description = "reverse all possible actions" + +[3d36da37-b31f-4cdb-a396-d93a2ee1c4a5] +description = "do nothing for zero" diff --git a/exercises/practice/secret-handshake/secretHandshake.test.u b/exercises/practice/secret-handshake/secretHandshake.test.u new file mode 100644 index 0000000..454e699 --- /dev/null +++ b/exercises/practice/secret-handshake/secretHandshake.test.u @@ -0,0 +1,57 @@ +secretHandshake.commands.tests.ex1 = + expect ([Wink] === secretHandshake.commands 1) + |> Test.label "wink for 1" + +secretHandshake.commands.tests.ex2 = + expect ([DoubleBlink] === secretHandshake.commands 2) + |> Test.label "double blink for 10" + +secretHandshake.commands.tests.ex3 = + expect ([CloseYourEyes] === secretHandshake.commands 4) + |> Test.label "close your eyes for 100" + +secretHandshake.commands.tests.ex4 = + expect ([Jump] === secretHandshake.commands 8) + |> Test.label "jump for 1000" + +secretHandshake.commands.tests.ex5 = + expect ([Wink, DoubleBlink] === secretHandshake.commands 3) + |> Test.label "combine two actions" + +secretHandshake.commands.tests.ex6 = + expect ([DoubleBlink, Wink] === secretHandshake.commands 19) + |> Test.label "reverse two actions" + +secretHandshake.commands.tests.ex7 = + expect ([Jump] === secretHandshake.commands 24) + |> Test.label "reversing one action gives the same action" + +secretHandshake.commands.tests.ex8 = + expect ([] === secretHandshake.commands 16) + |> Test.label "reversing no actions still gives no actions" + +secretHandshake.commands.tests.ex9 = + expect ([Wink, DoubleBlink, CloseYourEyes, Jump] === secretHandshake.commands 15) + |> Test.label "all possible actions" + +secretHandshake.commands.tests.ex10 = + expect ([Jump, CloseYourEyes, DoubleBlink, Wink] === secretHandshake.commands 31) + |> Test.label "reverse all possible actions" + +secretHandshake.commands.tests.ex11 = + expect ([] === secretHandshake.commands 0) + |> Test.label "do nothing for zero" + +test> secretHandshake.tests = runAll [ + secretHandshake.commands.tests.ex1, + secretHandshake.commands.tests.ex2, + secretHandshake.commands.tests.ex3, + secretHandshake.commands.tests.ex4, + secretHandshake.commands.tests.ex5, + secretHandshake.commands.tests.ex6, + secretHandshake.commands.tests.ex7, + secretHandshake.commands.tests.ex8, + secretHandshake.commands.tests.ex9, + secretHandshake.commands.tests.ex10, + secretHandshake.commands.tests.ex11 +] diff --git a/exercises/practice/secret-handshake/secretHandshake.u b/exercises/practice/secret-handshake/secretHandshake.u new file mode 100644 index 0000000..106e2b5 --- /dev/null +++ b/exercises/practice/secret-handshake/secretHandshake.u @@ -0,0 +1,8 @@ +unique type secretHandshake.Command + = Wink + | DoubleBlink + | CloseYourEyes + | Jump + +secretHandshake.commands : Nat -> [Command] +secretHandshake.commands = todo "implement commands"