|
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 binary decide to come up with a secret "handshake". |
| 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 | 7 |
|
8 | | -```text |
| 8 | +The actions for each number place are: |
| 9 | + |
| 10 | +```plaintext |
9 | 11 | 00001 = wink |
10 | 12 | 00010 = double blink |
11 | 13 | 00100 = close your eyes |
12 | 14 | 01000 = jump |
13 | | -
|
14 | 15 | 10000 = Reverse the order of the operations in the secret handshake. |
15 | 16 | ``` |
16 | 17 |
|
17 | | -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. |
18 | 25 |
|
19 | | -Here's a couple of examples: |
| 26 | +That was the last digit, so the final code is: |
| 27 | + |
| 28 | +```plaintext |
| 29 | +wink, jump |
| 30 | +``` |
20 | 31 |
|
21 | | -Given the decimal input 3, the function would return the array ["wink", "double blink"] because the decimal number 3 is 2+1 in powers of two and thus `11` in binary. |
| 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 | +``` |
22 | 43 |
|
23 | | -Let's now examine the input 19 which is 16+2+1 in powers of two and thus `10011` in binary. |
24 | | -Recalling that the addition of 16 (`10000` in binary) reverses an array and that we already know what array is returned given input 3, the array returned for input 19 is ["double blink", "wink"]. |
| 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