Recently I had a Maths test and noticed that a certain number on the test matched an interesting pattern. The number (28384
) matched a generic digit sequence that looks like this
(n)(x)(n+1)(x)(n+2)(x)(n+3) etc...
where n
and x
are single digit integers. The sequence can begin with either x
or n
and end with either x
or n+y
.
Your task is, given a multi digit positive integer, output a truthy or falsey value, depending on whether the input matches the pattern. The input will be between 4 and 18 digits long. You may take input as a string representation of the integer. The input will not begin with a 0 but can contain or end with 0s.
n+y
will always be a single digit number (hence why the length limit is 18).
Test Cases
These should output a truthy value
182838485868788898
4344
85868
12223242526
And these should be falsey
12345
6724013635
36842478324836
1222232425
5859510511
As with all code golfs, shortest code wins! Good luck and may the odds, be ever in your favour!
x
andn
non-zero for numbers that fit the rule? \$\endgroup\$