← Back to challenges

Slidey Numbers

PythonHardnumbersvalidation

Instructions

A number is considered slidey if for every digit in the number, the next digit from that has an absolute difference of one. Check the examples below.

Examples

is_slidey(123454321) ➞ True

is_slidey(54345) ➞ True

is_slidey(987654321) ➞ True

is_slidey(1123) ➞ False

is_slidey(1357) ➞ False

Notes

  • A number cannot slide properly if there is a "flat surface" (example #4), or has gaps (example #5).
  • All single digit numbers can be considered slidey numbers!
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Tower of Hanoi