Skip to content

Commit 785ca6b

Browse files
authoredAug 2, 2024··
secret-handshake-exercise: Added new exercise (#134)
1 parent 324743a commit 785ca6b

10 files changed

+268
-0
lines changed
 

‎config.json

+8
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,14 @@
446446
"practices": [],
447447
"prerequisites": [],
448448
"difficulty": 4
449+
},
450+
{
451+
"slug": "secret-handshake",
452+
"name": "Secret Handshake",
453+
"uuid": "17246658-c302-4df0-adde-92dac6f77a8d",
454+
"practices": [],
455+
"prerequisites": [],
456+
"difficulty": 2
449457
}
450458
]
451459
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Instructions
2+
3+
Your task is to convert a number between 1 and 31 to a sequence of actions in the secret handshake.
4+
5+
The sequence of actions is chosen by looking at the rightmost five digits of the number once it's been converted to binary.
6+
Start at the right-most digit and move left.
7+
8+
The actions for each number place are:
9+
10+
```plaintext
11+
00001 = wink
12+
00010 = double blink
13+
00100 = close your eyes
14+
01000 = jump
15+
10000 = Reverse the order of the operations in the secret handshake.
16+
```
17+
18+
Let's use the number `9` as an example:
19+
20+
- 9 in binary is `1001`.
21+
- The digit that is farthest to the right is 1, so the first action is `wink`.
22+
- Going left, the next digit is 0, so there is no double-blink.
23+
- Going left again, the next digit is 0, so you leave your eyes open.
24+
- Going left again, the next digit is 1, so you jump.
25+
26+
That was the last digit, so the final code is:
27+
28+
```plaintext
29+
wink, jump
30+
```
31+
32+
Given the number 26, which is `11010` in binary, we get the following actions:
33+
34+
- double blink
35+
- jump
36+
- reverse actions
37+
38+
The secret handshake for 26 is therefore:
39+
40+
```plaintext
41+
jump, double blink
42+
```
43+
44+
~~~~exercism/note
45+
If you aren't sure what binary is or how it works, check out [this binary tutorial][intro-to-binary].
46+
47+
[intro-to-binary]: https://medium.com/basecs/bits-bytes-building-with-binary-13cb4289aafa
48+
~~~~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
You are starting a secret coding club with some friends and friends-of-friends.
4+
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.
5+
You don't want anyone who isn't in the know to be able to crack the code.
6+
7+
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"authors": [
3+
"SimaDovakin"
4+
],
5+
"files": {
6+
"solution": [
7+
"secretHandshake.u"
8+
],
9+
"test": [
10+
"secretHandshake.test.u"
11+
],
12+
"example": [
13+
".meta/examples/secretHandshake.example.u"
14+
]
15+
},
16+
"blurb": "Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.",
17+
"source": "Bert, in Mary Poppins",
18+
"source_url": "https://www.imdb.com/title/tt0058331/quotes/?item=qt0437047"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
unique type secretHandshake.Command
2+
= Wink
3+
| DoubleBlink
4+
| CloseYourEyes
5+
| Jump
6+
7+
secretHandshake.commands : Nat -> [Command]
8+
secretHandshake.commands encodedMessage =
9+
collectCommand = cases
10+
acc, (code, command) | and encodedMessage code != 0 -> command(acc)
11+
acc, _ -> acc
12+
reverseOrNot message cmds =
13+
match and message 16 != 0 with
14+
true -> cmds
15+
false -> List.reverse cmds
16+
[
17+
(1, List.cons Wink),
18+
(2, List.cons DoubleBlink),
19+
(4, List.cons CloseYourEyes),
20+
(8, List.cons Jump)
21+
]
22+
|> List.foldLeft collectCommand []
23+
|> reverseOrNot encodedMessage
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"name": "secretHandshake.commands.tests.ex1",
4+
"test_code": "expect ([Wink] === secretHandshake.commands 1)\n |> Test.label \"wink for 1\""
5+
},
6+
{
7+
"name": "secretHandshake.commands.tests.ex2",
8+
"test_code": "expect ([DoubleBlink] === secretHandshake.commands 2)\n |> Test.label \"double blink for 10\""
9+
},
10+
{
11+
"name": "secretHandshake.commands.tests.ex3",
12+
"test_code": "expect ([CloseYourEyes] === secretHandshake.commands 4)\n |> Test.label \"close your eyes for 100\""
13+
},
14+
{
15+
"name": "secretHandshake.commands.tests.ex4",
16+
"test_code": "expect ([Jump] === secretHandshake.commands 8)\n |> Test.label \"jump for 1000\""
17+
},
18+
{
19+
"name": "secretHandshake.commands.tests.ex5",
20+
"test_code": "expect ([Wink, DoubleBlink] === secretHandshake.commands 3)\n |> Test.label \"combine two actions\""
21+
},
22+
{
23+
"name": "secretHandshake.commands.tests.ex6",
24+
"test_code": "expect ([DoubleBlink, Wink] === secretHandshake.commands 19)\n |> Test.label \"reverse two actions\""
25+
},
26+
{
27+
"name": "secretHandshake.commands.tests.ex7",
28+
"test_code": "expect ([Jump] === secretHandshake.commands 24)\n |> Test.label \"reversing one action gives the same action\""
29+
},
30+
{
31+
"name": "secretHandshake.commands.tests.ex8",
32+
"test_code": "expect ([] === secretHandshake.commands 16)\n |> Test.label \"reversing no actions still gives no actions\""
33+
},
34+
{
35+
"name": "secretHandshake.commands.tests.ex9",
36+
"test_code": "expect ([Wink, DoubleBlink, CloseYourEyes, Jump] === secretHandshake.commands 15)\n |> Test.label \"all possible actions\""
37+
},
38+
{
39+
"name": "secretHandshake.commands.tests.ex10",
40+
"test_code": "expect ([Jump, CloseYourEyes, DoubleBlink, Wink] === secretHandshake.commands 31)\n |> Test.label \"reverse all possible actions\""
41+
},
42+
{
43+
"name": "secretHandshake.commands.tests.ex11",
44+
"test_code": "expect ([] === secretHandshake.commands 0)\n |> Test.label \"do nothing for zero\""
45+
}
46+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Testing transcript for secret-handshake exercise
2+
3+
```ucm
4+
.> load ./secretHandshake.u
5+
.> add
6+
.> load ./secretHandshake.test.u
7+
.> add
8+
.> move.term secretHandshake.tests tests
9+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[b8496fbd-6778-468c-8054-648d03c4bb23]
13+
description = "wink for 1"
14+
15+
[83ec6c58-81a9-4fd1-bfaf-0160514fc0e3]
16+
description = "double blink for 10"
17+
18+
[0e20e466-3519-4134-8082-5639d85fef71]
19+
description = "close your eyes for 100"
20+
21+
[b339ddbb-88b7-4b7d-9b19-4134030d9ac0]
22+
description = "jump for 1000"
23+
24+
[40499fb4-e60c-43d7-8b98-0de3ca44e0eb]
25+
description = "combine two actions"
26+
27+
[9730cdd5-ef27-494b-afd3-5c91ad6c3d9d]
28+
description = "reverse two actions"
29+
30+
[0b828205-51ca-45cd-90d5-f2506013f25f]
31+
description = "reversing one action gives the same action"
32+
33+
[9949e2ac-6c9c-4330-b685-2089ab28b05f]
34+
description = "reversing no actions still gives no actions"
35+
36+
[23fdca98-676b-4848-970d-cfed7be39f81]
37+
description = "all possible actions"
38+
39+
[ae8fe006-d910-4d6f-be00-54b7c3799e79]
40+
description = "reverse all possible actions"
41+
42+
[3d36da37-b31f-4cdb-a396-d93a2ee1c4a5]
43+
description = "do nothing for zero"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
secretHandshake.commands.tests.ex1 =
2+
expect ([Wink] === secretHandshake.commands 1)
3+
|> Test.label "wink for 1"
4+
5+
secretHandshake.commands.tests.ex2 =
6+
expect ([DoubleBlink] === secretHandshake.commands 2)
7+
|> Test.label "double blink for 10"
8+
9+
secretHandshake.commands.tests.ex3 =
10+
expect ([CloseYourEyes] === secretHandshake.commands 4)
11+
|> Test.label "close your eyes for 100"
12+
13+
secretHandshake.commands.tests.ex4 =
14+
expect ([Jump] === secretHandshake.commands 8)
15+
|> Test.label "jump for 1000"
16+
17+
secretHandshake.commands.tests.ex5 =
18+
expect ([Wink, DoubleBlink] === secretHandshake.commands 3)
19+
|> Test.label "combine two actions"
20+
21+
secretHandshake.commands.tests.ex6 =
22+
expect ([DoubleBlink, Wink] === secretHandshake.commands 19)
23+
|> Test.label "reverse two actions"
24+
25+
secretHandshake.commands.tests.ex7 =
26+
expect ([Jump] === secretHandshake.commands 24)
27+
|> Test.label "reversing one action gives the same action"
28+
29+
secretHandshake.commands.tests.ex8 =
30+
expect ([] === secretHandshake.commands 16)
31+
|> Test.label "reversing no actions still gives no actions"
32+
33+
secretHandshake.commands.tests.ex9 =
34+
expect ([Wink, DoubleBlink, CloseYourEyes, Jump] === secretHandshake.commands 15)
35+
|> Test.label "all possible actions"
36+
37+
secretHandshake.commands.tests.ex10 =
38+
expect ([Jump, CloseYourEyes, DoubleBlink, Wink] === secretHandshake.commands 31)
39+
|> Test.label "reverse all possible actions"
40+
41+
secretHandshake.commands.tests.ex11 =
42+
expect ([] === secretHandshake.commands 0)
43+
|> Test.label "do nothing for zero"
44+
45+
test> secretHandshake.tests = runAll [
46+
secretHandshake.commands.tests.ex1,
47+
secretHandshake.commands.tests.ex2,
48+
secretHandshake.commands.tests.ex3,
49+
secretHandshake.commands.tests.ex4,
50+
secretHandshake.commands.tests.ex5,
51+
secretHandshake.commands.tests.ex6,
52+
secretHandshake.commands.tests.ex7,
53+
secretHandshake.commands.tests.ex8,
54+
secretHandshake.commands.tests.ex9,
55+
secretHandshake.commands.tests.ex10,
56+
secretHandshake.commands.tests.ex11
57+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
unique type secretHandshake.Command
2+
= Wink
3+
| DoubleBlink
4+
| CloseYourEyes
5+
| Jump
6+
7+
secretHandshake.commands : Nat -> [Command]
8+
secretHandshake.commands = todo "implement commands"

0 commit comments

Comments
 (0)
Please sign in to comment.