|
| 1 | +# Palindrome Products |
| 2 | + |
| 3 | +Detect palindrome products in a given range. |
| 4 | + |
| 5 | +A palindromic number is a number that remains the same when its digits are |
| 6 | +reversed. For example, `121` is a palindromic number but `112` is not. |
| 7 | + |
| 8 | +Given a range of numbers, find the largest and smallest palindromes which |
| 9 | +are products of numbers within that range. |
| 10 | + |
| 11 | +Your solution should return the largest and smallest palindromes, along with the |
| 12 | +factors of each within the range. If the largest or smallest palindrome has more |
| 13 | +than one pair of factors within the range, then return all the pairs. |
| 14 | + |
| 15 | +## Example 1 |
| 16 | + |
| 17 | +Given the range `[1, 9]` (both inclusive)... |
| 18 | + |
| 19 | +And given the list of all possible products within this range: |
| 20 | +`[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 15, 21, 24, 27, 20, 28, 32, 36, 25, 30, 35, 40, 45, 42, 48, 54, 49, 56, 63, 64, 72, 81]` |
| 21 | + |
| 22 | +The palindrome products are all single digit numbers (in this case): |
| 23 | +`[1, 2, 3, 4, 5, 6, 7, 8, 9]` |
| 24 | + |
| 25 | +The smallest palindrome product is `1`. Its factors are `(1, 1)`. |
| 26 | +The largest palindrome product is `9`. Its factors are `(1, 9)` and `(3, 3)`. |
| 27 | + |
| 28 | +## Example 2 |
| 29 | + |
| 30 | +Given the range `[10, 99]` (both inclusive)... |
| 31 | + |
| 32 | +The smallest palindrome product is `121`. Its factors are `(11, 11)`. |
| 33 | +The largest palindrome product is `9009`. Its factors are `(91, 99)`. |
| 34 | + |
| 35 | +## Exception messages |
| 36 | + |
| 37 | +Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to |
| 38 | +indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not |
| 39 | +every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include |
| 40 | +a message. |
| 41 | + |
| 42 | +To raise a message with an exception, just write it as an argument to the exception type. For example, instead of |
| 43 | +`raise Exception`, you should write: |
| 44 | + |
| 45 | +```python |
| 46 | +raise Exception("Meaningful message indicating the source of the error") |
| 47 | +``` |
| 48 | + |
| 49 | +## Running the tests |
| 50 | + |
| 51 | +To run the tests, run the appropriate command below ([why they are different](https://github.com/pytest-dev/pytest/issues/1629#issue-161422224)): |
| 52 | + |
| 53 | +- Python 2.7: `py.test palindrome_products_test.py` |
| 54 | +- Python 3.3+: `pytest palindrome_products_test.py` |
| 55 | + |
| 56 | +Alternatively, you can tell Python to run the pytest module (allowing the same command to be used regardless of Python version): |
| 57 | +`python -m pytest palindrome_products_test.py` |
| 58 | + |
| 59 | +### Common `pytest` options |
| 60 | + |
| 61 | +- `-v` : enable verbose output |
| 62 | +- `-x` : stop running tests on first failure |
| 63 | +- `--ff` : run failures from previous test before running other test cases |
| 64 | + |
| 65 | +For other options, see `python -m pytest -h` |
| 66 | + |
| 67 | +## Submitting Exercises |
| 68 | + |
| 69 | +Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/palindrome-products` directory. |
| 70 | + |
| 71 | +You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`. |
| 72 | + |
| 73 | +For more detailed information about running tests, code style and linting, |
| 74 | +please see the [help page](http://exercism.io/languages/python). |
| 75 | + |
| 76 | +## Source |
| 77 | + |
| 78 | +Problem 4 at Project Euler [http://projecteuler.net/problem=4](http://projecteuler.net/problem=4) |
| 79 | + |
| 80 | +## Submitting Incomplete Solutions |
| 81 | + |
| 82 | +It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
0 commit comments