Slidey Numbers

Published by Matt in

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!
Watch a quick demo on how Edabit works.