mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-10 02:07:08 -06:00
79 lines
2.8 KiB
Markdown
79 lines
2.8 KiB
Markdown
# Secret Handshake
|
|
|
|
> There are 10 types of people in the world: Those who understand
|
|
> binary, and those who don't.
|
|
|
|
You and your fellow cohort of those in the "know" when it comes to
|
|
binary decide to come up with a secret "handshake".
|
|
|
|
```text
|
|
1 = wink
|
|
10 = double blink
|
|
100 = close your eyes
|
|
1000 = 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.
|
|
|
|
Here's a couple of examples:
|
|
|
|
Given the input 3, the function would return the array
|
|
["wink", "double blink"] because 3 is 11 in binary.
|
|
|
|
Given the input 19, the function would return the array
|
|
["double blink", "wink"] because 19 is 10011 in binary.
|
|
Notice that the addition of 16 (10000 in binary)
|
|
has caused the array to be reversed.
|
|
|
|
## Exception messages
|
|
|
|
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
a message.
|
|
|
|
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
`raise Exception`, you should write:
|
|
|
|
```python
|
|
raise Exception("Meaningful message indicating the source of the error")
|
|
```
|
|
|
|
## Running the tests
|
|
|
|
To run the tests, run the appropriate command below ([why they are different](https://github.com/pytest-dev/pytest/issues/1629#issue-161422224)):
|
|
|
|
- Python 2.7: `py.test secret_handshake_test.py`
|
|
- Python 3.4+: `pytest secret_handshake_test.py`
|
|
|
|
Alternatively, you can tell Python to run the pytest module (allowing the same command to be used regardless of Python version):
|
|
`python -m pytest secret_handshake_test.py`
|
|
|
|
### Common `pytest` options
|
|
|
|
- `-v` : enable verbose output
|
|
- `-x` : stop running tests on first failure
|
|
- `--ff` : run failures from previous test before running other test cases
|
|
|
|
For other options, see `python -m pytest -h`
|
|
|
|
## Submitting Exercises
|
|
|
|
Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/secret-handshake` directory.
|
|
|
|
You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`.
|
|
|
|
For more detailed information about running tests, code style and linting,
|
|
please see [Running the Tests](http://exercism.io/tracks/python/tests).
|
|
|
|
## Source
|
|
|
|
Bert, in Mary Poppins [http://www.imdb.com/title/tt0058331/quotes/qt0437047](http://www.imdb.com/title/tt0058331/quotes/qt0437047)
|
|
|
|
## Submitting Incomplete Solutions
|
|
|
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|