|
1 | 1 | # Instructions
|
2 | 2 |
|
3 |
| -> There are 10 types of people in the world: Those who understand |
4 |
| -> binary, and those who don't. |
| 3 | +Your task is to convert a number between 1 and 31 to a sequence of actions in the secret handshake. |
5 | 4 |
|
6 |
| -You and your fellow cohort of those in the "know" when it comes to |
7 |
| -binary decide to come up with a secret "handshake". |
8 |
| - |
9 |
| -```text |
10 |
| -1 = wink |
11 |
| -10 = double blink |
12 |
| -100 = close your eyes |
13 |
| -1000 = jump |
| 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. |
14 | 7 |
|
| 8 | +The actions for each number place are: |
15 | 9 |
|
| 10 | +```plaintext |
| 11 | +00001 = wink |
| 12 | +00010 = double blink |
| 13 | +00100 = close your eyes |
| 14 | +01000 = jump |
16 | 15 | 10000 = Reverse the order of the operations in the secret handshake.
|
17 | 16 | ```
|
18 | 17 |
|
19 |
| -Given a decimal number, convert it to the appropriate sequence of events for a secret handshake. |
| 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: |
20 | 33 |
|
21 |
| -Here's a couple of examples: |
| 34 | +- double blink |
| 35 | +- jump |
| 36 | +- reverse actions |
22 | 37 |
|
23 |
| -Given the input 3, the function would return the array |
24 |
| -["wink", "double blink"] because 3 is 11 in binary. |
| 38 | +The secret handshake for 26 is therefore: |
| 39 | + |
| 40 | +```plaintext |
| 41 | +jump, double blink |
| 42 | +``` |
25 | 43 |
|
26 |
| -Given the input 19, the function would return the array |
27 |
| -["double blink", "wink"] because 19 is 10011 in binary. |
28 |
| -Notice that the addition of 16 (10000 in binary) |
29 |
| -has caused the array to be reversed. |
| 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 | +[intro-to-binary]: https://medium.com/basecs/bits-bytes-building-with-binary-13cb4289aafa |
| 47 | +~~~~ |
0 commit comments