15
0
Challenge :
Check if the given number forms a number staircase
or not
Input :
A integer (greater than 0 and not decimal). NOTE : You can take input as string , array of digits.
Output :
a truthy / falsy value depending on whether the number forms a staircase or not
Number staircase :
A number staircase is an integer that , when read from left to right :
- Starts with 1
- which may be followed by 2
- which may be followed by 3
- and so on till
n
- then the number descends starting at n - 1
- then n - 2
- then n - 3
- and so on till it reaches 1
Note :
The may be part is used to indicate that if length > is greater than 1. If it is the order must be followed as is. i.e : 12321
Example :
12321 ---> true
12345654321 ---> true
9 ---> false
1 ---> true
2 ---> false
123421 ---> false
112312318901323 ---> false
123456789101110987654321 ---> true
Note :
The input given will always be an integer greater than 0 and will not be a decimal. Your output must be a truthy or falsy
value depending on the input
Restrictions :
This is code-golf so shortest code in bytes (for each programming language ) wins.
2Can we take input as a list of digits? Like
[1,2,3,4,5,6,7,8,9,1,0,1,1,1,0,9,8,7,6,5,4,3,2,1]
for123456789101110987654321
? – Mr. Xcoder – 2018-04-30T15:50:23.963@Mr.Xcoder : I would rather prefer if you didn't but I guess you can – Muhammad Salman – 2018-04-30T16:06:37.113
Is there an upper limit on the input? – mypetlion – 2018-04-30T16:23:30.413
@mypetlion : Not really , it is as high as your code can support (excluding hardcoded and purposedly low ones.) Normally the highest your language can support (but not in this case) – Muhammad Salman – 2018-04-30T16:26:42.860
May we take a string of characters as input to a function? (or is this only acceptable input for a full-program?) – Jonathan Allan – 2018-04-30T16:54:20.923
@JonathanAllan : You may take that as a function. – Muhammad Salman – 2018-05-01T00:44:47.860
@JoKing : normally yes , but in this case I do since this . Although it is different sadly the name is same so
– Muhammad Salman – 2018-05-01T03:58:03.247@JoKing : Why not! – Muhammad Salman – 2018-05-01T04:16:34.367
"and so on till it reaches 0" - should be "and so on till it reaches 1". – djhurio – 2018-05-01T05:09:11.613
@djhurio : nice catch. Thanks. – Muhammad Salman – 2018-05-01T05:10:52.593
Very closely related, nearly a dupe. It's slightly different, since this one allows the string to go above 9, but other than that they're the same. – James – 2018-05-01T16:34:43.270