Sync secret-handshake docs with problem-specifications (#263)
The secret-handshake exercise has been overhauled as part of a project to make practice exercises more consistent and friendly. For more context, please see the discussion in the forum, as well as the pull request that updated the exercise in the problem-specifications repository: - https://forum.exercism.org/t/new-project-making-practice-exercises-more-consistent-and-human-across-exercism/3943 - https://github.com/exercism/problem-specifications/pull/2219
This commit is contained in:
@@ -1,37 +1,47 @@
|
||||
# Description
|
||||
# Instructions
|
||||
|
||||
> There are 10 types of people in the world: Those who understand
|
||||
> binary, and those who don't.
|
||||
Your task is to convert a number between 1 and 31 to a sequence of actions in the secret handshake.
|
||||
|
||||
You and your fellow cohort of those in the "know" when it comes to
|
||||
binary decide to come up with a 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.
|
||||
|
||||
```text
|
||||
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.
|
||||
```
|
||||
|
||||
Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.
|
||||
Let's use the number `9` as an example:
|
||||
|
||||
Here's a couple of examples:
|
||||
- 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.
|
||||
|
||||
Given the decimal input 3, the function would return the following string_table:
|
||||
| Row | TABLE_LINE |
|
||||
| --- | ------------ |
|
||||
| 1 | wink |
|
||||
| 2 | double blink |
|
||||
That was the last digit, so the final code is:
|
||||
|
||||
This is because the decimal number 3 is 2+1 in powers of two and thus `11` in binary.
|
||||
```plaintext
|
||||
wink, jump
|
||||
```
|
||||
|
||||
Let's now examine the input 19 which is 16+2+1 in powers of two and thus `10011` in binary.
|
||||
Recalling that the addition of 16 (`10000` in binary) reverses the sequence and that we already know what result is returned given input 3, the string_table returned for input 19 is:
|
||||
Given the number 26, which is `11010` in binary, we get the following actions:
|
||||
|
||||
| Row | TABLE_LINE |
|
||||
| --- | ------------ |
|
||||
| 1 | double blink |
|
||||
| 2 | wink |
|
||||
- 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
|
||||
~~~~
|
||||
|
||||
@@ -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.
|
||||
Reference in New Issue
Block a user