[Question]
  [
A staircase number is a positive integer **x** such that its **n**th digit (one indexed starting with the least significant digit) is equal to **x % (n + 1)**. Thats a bit of a mouthful so lets look at an example. Take **7211311**, if we take the modular residues of **7211311** on the range 2-8 we get the following:
```
7211311 % 2 = 1
7211311 % 3 = 1
7211311 % 4 = 3
7211311 % 5 = 1
7211311 % 6 = 1
7211311 % 7 = 2
7211311 % 8 = 7
```
These are the digits of **7211311**! Thus **7211311** is a staircase number.
## Task
Write code that takes when given a positive number as input, will output two distinct values one if the number *is* a staircase number and the other if it is not.
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") competition so your aim should be to minimize the number of bytes in your source code.
## Test Cases
Here are the first 13 staircase numbers:
```
1, 10, 20, 1101, 1121, 11311, 31101, 40210, 340210, 4620020, 5431101, 7211311, 12040210
```
  
[Answer]
# Haskell, 55 ~~57~~ bytes
```
f m|let n#x=n==0||n`mod`10==m`mod`x&&div n 10#(x+1)=m#2
```
A different approach than the other Haskell solution.
*Thanks xnor for saving 2 bytes.*
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~25~~ ~~21~~ ~~16~~ 14 bytes
```
{it+‚ÇÇ;?‚Üî%}·∂†‚Üîc?
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/vzqzRPtRU5O1/aO2Kaq1D7ctANLJ9v//mxsZGhobGgIA "Brachylog ‚Äì Try It Online")
First Brachylog submission :D ~~probably very ungolfed~~...many thanks to Leaky Nun and Fatalize for encouragement and help to golf this from 25 all the way down to just 14. :) :)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
### Code:
```
ƒÅ>%JRQ
```
Uses the **05AB1E** encoding. [Try it online!](https://tio.run/##MzBNTDJM/f//SKOdqldQ4P//JmZGBgZGBgA "05AB1E ‚Äì Try It Online")
### Explanation:
```
ƒÅ        # Get the range [1 .. len(input)]
 >       # Increment by 1
  %      # Vectorized modulo
   J     # Join the array into a single number
    RQ   # Reverse that number and check if it's equal to the original input
```
[Answer]
# Javascript, ~~42~~ ~~41~~ ~~39~~ 38 bytes
-4 bytes thanks to @Shaggy and @ETHProductions
```
s=>[...s].some(d=>s%i++^d,i=~s.length)
```
This takes the number as a string and returns `false` if the number is a staircase number and `true` otherwise.
Example code snippet:
```
f=
s=>[...s].some(d=>s%i++^d,i=~s.length)
function update() {
  o.innerText = f(document.getElementById("i").value)
}
```
```
<input id="i" type="number">
<button onclick="update()">Test</button>
<p id="o">
```
[Answer]
# [Python 2](https://docs.python.org/2/), 54 bytes
```
f=lambda n,x=0:10**x>n or(`n%(x+2)`==`n`[~x])*f(n,x+1)
```
[Try it online!](https://tio.run/##DcrRCsIgFAbg@57iv4l5nMX0cuBeJAKNsoR2HOKFY6xXt33X37KWT2LTWrBfPz@eHqyqHUY9SFknRsrC8VnU3pCz1rG7/eqdZBBH6zW1kDIiIiN7fr@EVjCaxhOw5MgF3bbjMmHbu@sxZ19EVAgiErU/ "Python 2 ‚Äì Try It Online")
[Answer]
# Haskell, 60 bytes
Takes the number as an int
```
x n|s<-show n=reverse s==(rem n.(+1)<$>[1..length s]>>=show)
```
[Answer]
# Mathematica, 60 bytes
```
FromDigits@Reverse@Mod[#,Range@Length@IntegerDigits@#+1]==#&
```
[Try it online!](https://tio.run/##y00sychMLv6fZvvfrSg/1yUzPbOk2CEotSy1qDjVwTc/JVpZJygxLz3VwSc1L70kw8EzryQ1PbUIqlBZ2zDW1lZZ7X9AUWZeiYKDQpqCg6GRgYmBkaHBfwA "Mathics ‚Äì Try It Online")
@alephalpha golfed it to 48
# Mathematica, 48 bytes
```
FromDigits@Reverse@Mod[#,Range[2,Log10@#+2]]==#&
```
next one is 24120020
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~9~~ ~~7~~ 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Takes input as a string.
```
√î¬∂¬°%¬¥J
```
2 bytes saved with help from [ETHproductions](https://codegolf.stackexchange.com/users/42545/ethproductions).
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=1LahJbRK&input=IjcyMTEzMTEi)
```
√î¬∂¬°%¬¥J     :Implicit input of string U
√î          :Reverse
 ¬∂         :Test for equality with 
  ¬°        :Map U
   %       :  Modulo
    ¬¥J     :  J (initially -1) prefix decremented
```
[Answer]
# [Neim](https://github.com/okx-code/Neim), 6 bytes
```
ùêß·õñùïÑùê´ùê£ùîº
```
Explanation:
```
ùêß         Get the length of the input, then create an exclusive range
 ·õñ        Add 2 to each element
  ùïÑ       Modulus
    ùê´      Reverse
     ùê£     Join
      ùîº   Check for equality
```
[Try it online!](https://tio.run/##y0vNzP3//8PcCcsfzp72Ye7UFiBzNRAv/jB3yp7//w0NAA "Neim ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
DJ‚Äò‚Å∏%‚Åº·πö
```
[Try it online!](https://tio.run/##y0rNyan8/9/F61HDjEeNO1QfNe55uHPW////zY0MDY0NDQE "Jelly ‚Äì Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 56 bytes
```
lambda x:all(`x%(i+2)`==`x`[~i]for i in range(len(`x`)))
```
[Try it online!](https://tio.run/##K6gsycjPM/qfll@kkKmQmaeQlplTklqkofE/JzE3KSVRocIqMSdHI6FCVSNT20gzwdY2oSIhui4zFq6hKDEvPVUjJzUPqChBU1Pzv6YOVMzQAAw0Na24FICgoCgzr0Qh8/9/AA "Python 2 ‚Äì Try It Online")
[Answer]
# [Perl 6](http://perl6.org/), 32 bytes
```
{$_ eq[~] $_ ¬´%¬´(1+.comb...2)}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/WiVeIbUwui5WAcg4tFr10GoNQ2295PzcJD09PSPN2v/WCsWJlQrpRakFQA06CoZ6eoZGBgYG/wE "Perl 6 ‚Äì Try It Online")
* `.comb` is the number of characters in the string representation of the input argument `$_` (that is, the number of digits).
* `1 + .comb ... 2` is the sequence of numbers from one greater than the number of digits down to 2.
* `¬´%¬´` is the modulus hyperoperator that gives the remainder when `$_`, the input argument on its left, is divided by each of the elements of the sequence on its right: `$_ % 2, $_ % 3, ...`.
* `[~]` concatenates those digits into a new number, which is compared with the input argument using the string equality operator `eq`.
[Answer]
# [PHP](https://php.net/), 43 bytes
```
for(;$r<$a=$argn;)$r=$a%~++$i.$r;echo$r>$a;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwJVaVJRfFF@UWpBfVJKZl65R5xrv5x/i6eyqac2lkliUnmerZG5kaGhsaKhk/T8tv0jDWqXIRiXRFixnralSBGSp1mlrq2TqqRRZpyZn5KsU2akkWv//DwA "PHP ‚Äì Try It Online")
# [PHP](https://php.net/), 44 bytes
prints 1 for true and nothing for false
```
for(;$r<$a=$argn;)$r=$a%~++$i.$r;echo$r==$a;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRwJVaVJRfFF@UWpBfVJKZl65R5xrv5x/i6eyqac2lkliUnmerZG5kaGhsaKhk/T8tv0jDWqXIRiXRFixnralSBGSp1mlrq2TqqRRZpyZn5AOFgGLW//8DAA "PHP ‚Äì Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 13 bytes
-1 bytes thanks to [Okx](https://codegolf.stackexchange.com/users/26600/okx).
```
qsjk_m%QhdSl`
```
[Try it online!](https://pyth.herokuapp.com/?code=qsjk_m%25QhdSl%60&input=7211311&debug=0)
**Explanation**
```
             QQ    # Implicit input
          Sl`Q     # Generate [1, len(str(Q))]
     m%Qhd         # For digit d in above range, perform Q % (d + 1)
 sjk_              # Reverse, then convert to number
q             Q    # Test equality with input
```
**Alternate solution**, still 13 bytes (thanks to [karlkastor](https://codegolf.stackexchange.com/users/56557/karlkastor))
```
qi_.e%Q+2k`QT
```
[Try it online!](https://pyth.herokuapp.com/?code=qi_.e%25Q%2B2k%60QT&input=7211311&debug=0) That's essentially the same as the first solution, excepted that it uses `i` to convert from array of numbers to a number, and that the range is generated differently.
[Answer]
# C++,104 bytes
1) original version:
```
int main(){int N,T,R=1;cin>>N;T=N;for(int i=1;i<=log10(N)+1;i++){if(N%(i+1)!=T%10){R=0;}T/=10;}cout<<R;}
```
2) in a readable form:
```
int main()
{
    int N, T, R = 1;
    cin >> N;
    T = N;
    for (int i = 1; i <= log10(N) + 1; i++)
    {
        if (N % (i + 1) != T % 10)
        {
            R = 0;
        }
        T /= 10;
    }
    cout << R;
}
```
[Try it Online!](https://tio.run/##RYtNDoMgGET3noKmMYFgU1nzcwQWhgsQRPslBYzgynh2iquu5s2bjNu21@pcfUJ032P2SEDKZfc2qO7vXLDlo7ojQ1xRtMHnzTqPcpl5hVhQsBAxOW/UgxkmybiDqJTmRmq@pB3fEzQNQn7TykasCW2N0vZasO4xUEYe0vRsJOckR36Zt2QtXDqKEBO/amU/)
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~21~~ 19 bytes
```
{‚çµ=10‚ä•‚åΩ‚çµ|‚ç®1‚Üì‚ç≥1+‚â¢‚çï‚çµ}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/v/pR71ZbQ4NHXUsf9ewFsmse9a4wfNQ2@VHvZkPtR52LHvVOBYrW/k971DbhUW/fo67mR71rHvVuObTe@FHbxEd9U4ODnIFkiIdn8P80BTOuNAVzI0NDY0NDAA "APL (Dyalog Extended) ‚Äì Try It Online")
Creates two lists of digits and check if they are equal.
## Explanation
```
{‚çµ=10‚ä•‚åΩ‚çµ|‚ç®1‚Üì‚ç≥1+‚â¢‚çï‚çµ} ‚çµ ‚Üí¬†input
               ‚â¢‚çï‚çµ  length of ‚çµ as a string
             1+     +1
            ‚ç≥       range from 1 to that
          1‚Üì        Drop first element 
       ‚çµ|‚ç®          ‚çµ mod each element in range
      ‚åΩ             reversed
   10‚ä•              converted from base 10
 ‚çµ=                 equals the input?
```
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 42 bytes
```
n->Vecrev(s=digits(n))==[n%d|d<-[2..#s+1]]
```
[Try it online!](https://tio.run/##K0gsytRNL/ifpmCr8D9P1y4sNbkotUyj2DYlMz2zpFgjT1PT1jY6TzWlJsVGN9pIT0@5WNswNvZ/Wn6RRh5Qj6GOgqGBgY5CQVFmXglQRElB1w5IpIE0av4HAA "Pari/GP ‚Äì Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~66 60 58~~ 57 bytes
* Thanks to @Leaky nun for 6 bytes: remove unneeded `x and` (shouldnot check for 0)
* Thanks to @Einkorn Enchanter for 1 byte: use of `enumerate`
```
lambda x:all(a==`x%(i+2)`for i,a in enumerate(`x`[::-1]))
```
[Try it online!](https://tio.run/##HYrRCsIwDADf/Yq8CAkquD0G@iUqNGKrgS4bpUL9@sztng7ull/7zDZ6DncvMj1fAp2lFJQQYj@inkaKea6gZwE1SPadUpWWMPZ4Y74MDyLfhy1XsXfC4bpDfADNkFGJYalq7W/uKw "Python 2 ‚Äì Try It Online")
[Answer]
# Python 3: 63 Bytes
```
lambda m:all(int(x)==m%(n+2)for n,x in enumerate(str(m)[::-1]))
```
If I could count the number of times I wished 'enumerate' were shorter...
[Try it online!](https://tio.run/##FctBCoAgEADAr@wl2KWCrJvgS6KDkVHgrqIG9Xqr4xwmPuUIMtWajbe8bhZYW@/xlII3GcMNSjsS7CGBdDecAk4udskWh7kkZJq17tVCVGP6V0alBvXxBQ "Python 3 ‚Äì Try It Online")
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 60 bytes
```
n->{int m=2,r=0,t=1;for(;n>=t;t*=10)r+=n%m++*t;return r==n;}
```
[Try it online!](https://tio.run/##bVBNa9tAEL37VwwBgxQpYld2Uoi6gR566CGh4GPIYS2v03WtkZgdpRij3@6OPoJC2oWd2Z2PN@/Nwb7Zm7pxeNj9vjTt9uhLKI82BHi0HuG8AJiigS2Le6v9DirJRRsmj6/PL2DpNcRDKcBB8LKW/THbt1iyrzH7gfyT3M6Xlh00YC5483D2yFCZPCWjUja62NcUFfhguOBro1VMicFllSTXXJDjlhDIGCy6CwynWAzTBEXmCzNPpQ3uqa22jgIYQPdnTJ51ClqlkMvVWvU/nQ92pcWtxtha5X3RavLru1ypvuN2PRV8yacGnauhqCsGAkIbol4L3v9D430lAJtTYFdldctZIzvjfXS11CrcwzIs8SoFTKHJ2AWOMI5H4O4TvKwIEL6Klv7IO0lmfL@HaF78NyJ7CtnWo6XTxlkqf0WfucnMWNDUjDGizDQ@JP4r4DtRTaJAdIwaJuIz@Xff227RXf4C "Java (OpenJDK 8) ‚Äì Try It Online")
A non-string version.
[Answer]
## Java 8, 156 149 bytes
```
interface B{static void main(String[]s){String f="";for(int i=1;i<=s[0].length();)f=new Long(s[0])%++i+f;System.out.print(f.equals(s[0]));}}
```
Ungolfed :
```
interface B {
    static void main(String[] s) {
        String f = "";
        for (int i = 1; i <= s[0].length();)
            f = new Long(s[0]) % ++i + f;
        System.out.print(f.equals(s[0]));
    }
}
```
[Try it Online !](https://tio.run/##LYyxDoIwFEV/pSExaUNsrA4OtYubMyNhaOAVi9Bi@8AYwrdXjG4nueeeTs9670dwXfNIyTqEYHQN5LpE1GhrMnvbkEFbRwsM1rVlFdnyQ2JUlknjA91@xCoh7UXF8lDxHlyLd8okM4o6eJHbFm4h0O/K2I7muWW5kcU7IgzcT8jHrYi9o4bDc9J9/KtyXVNK56MQJyE@)
**UPDATE :**  
*-7 bytes* : removed useless `{}` and replaced `Integer.parseInt(...)` by `new Integer(...)`  
*-9 bytes* : thanks to Kevin Cruijssen, removed a bunch of useless `()`, used `Long` instead of `Integer` and `print` instead of `println`. Thanks K√©vin !
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~20~~ 15 bytes
```
‚åäÔº•Œ∏‚ÅºŒπÔº©Ôπ™Ôº©Œ∏‚Åª‚Å∫¬πÔº¨Œ∏Œ∫
```
[Try it online!](https://tio.run/##JcrBDkAwEATQX@lxJZVocHIUNxK/sEForFZV/f7aMIfJJG@mDa/JIzGPl3U3DNbZIx0w4AlBqy4kpAhWqxajqJ8Tefh2yLSSd4owkpTRql/cem8CInv2p2Guq9KYwnD@cB7pBQ "Charcoal ‚Äì Try It Online") Outputs `-` for a staircase number, nothing otherwise. Link is to verbose version of code.
[Answer]
# [Haskell](https://www.haskell.org/), 53 bytes
```
f n=foldr(\(k,_)a->10*a+mod n k)0(zip[2..]$show n)==n
```
[Try it online!](https://tio.run/##HcHBCoMwDADQX8nBQ7vNorvt0P2IkxHUzNKYllYY@PFmsPdWrHFhViUQT4nnYl4m3t4W22ffXfC6pRkEou3MEfJwd25s6pq@INZ70Q2DgIdcguzQAAXelwIEQ@/c42/UcyLGT9V2yvkH "Haskell ‚Äì Try It Online")
[Answer]
## Python 2, 61 bytes
```
lambda x:[`x%(n+2)`for n in range(len(`x`))][::-1]==list(`x`)
```
[Answer]
# q/kdb+, 34 bytes
**Solution:**
```
{s~raze($)x mod'2+(|)(!)(#)s:($)x}
```
**Example:**
```
q){s~raze($)x mod'2+(|)(!)(#)s:($)x}7211311 / this is a staircase number (true)
1b
q){s~raze($)x mod'2+(|)(!)(#)s:($)x}7211312 / this is not (false)
0b
q)t(&){s~raze($)x mod'2+(|)(!)(#)s:($)x}each t:1 + til 1000000 / up to a million
1 10 20 1101 1121 11311 31101 40210 340210
```
**Explanation:**
Cast the input number to a string, count from 0..length of string, add 2 to all, reverse it and feed each number into `mod` along with the original input. Cast the result of the mod to a string and reduce the list, check if it is equal to the string of the input number:
```
{s~raze string x mod'2 + reverse til count s:string x} / ungolfed solution
{                                                    } / lambda function
                                           s:string x  / convert input to string, save as s
                                     count             / return length of this string
                                 til                   / like python's range() function
                         reverse                       / reverses the list
                     2 +                               / adds two to each element in the list
               x mod'                                  / ' is each both, so feeds x, and each element of the list to modulo function
        string                                         / converts output list to string list ("7";"2";"1"..etc)
   raze                                                / reduce list ("721...")
 s~                                                    / is s equal to this reduced list, returns boolean
```
**Notes:**
Most of the solution is for generating the `2,3,4..` list, I have another solution that does less stuff, but winds up being 37 bytes after golfing:
```
{s~x mod'reverse 2 + til count s:("J"$) each string x} / ungolfed
{s~x mod'(|)2+til(#)s:("J"$)each($)x}                  / golfed
```
[Answer]
## Clojure, 75 bytes
```
#(=(sort %)(sort(map(fn[i c](char(+(mod(Integer. %)(+ i 2))48)))(range)%)))
```
Input is a string, using `map` and the trailing `%` ended up being shorter than `for[i(range(count %))]` approach.
[Answer]
# Haskell, 62 bytes
`f x=and$zipWith(==)(reverse$show x)$map(head.show.mod x)[2..]`
Instead of reversing the (infinite) list of moduli, it truncates the list by zipping it with the reversed string-respresentation of the integral x, which it then ensures is equal element-wise.
[Answer]
# [Perl 5](https://www.perl.org/), 41 bytes
39 bytes of code + 2 flags `-pa`
```
map{$\||=$_!=$F[0]%++$n}0,reverse/./g}{
```
[Try it online!](https://tio.run/##K0gtyjH9/z83saBaJaamxlYlXtFWxS3aIFZVW1slr9ZApyi1LLWoOFVfTz@9tvr/f3MjQ0NjQ8N/@QUlmfl5xf91fU31DAwN/usWJAIA "Perl 5 ‚Äì Try It Online")
Outputs nothing (undef) for staircase numbers, 1 for anything else
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt#L332), 7 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
m√¶k√Æ)%√ë
```
Input as a string.
[Try it online.](https://tio.run/##y00syUjPz0n7/z/38LLsw@s0VQ9P/P9fyVCJS8nQAEgYgQhDQwOwgKERhDI2BNHGUGETAyOwUmMYw8TMyMAArNHUBKbI3AimzdDIAKbQCKQEREOsM4CQYCMMDeG0IdgZED0A)
**Explanation:**
```
m        # Map over each character of the (implicit) input-string,
 √¶       # using the following four characters as inner code-block:
         #  (implicitly push the current character of the map)
  k      #  Push the input as an integer
   √Æ     #  Push the 1-based map-index
    )    #  Increase it by 1
     %   #  Take the input-integer modulo (1-based) index+1
         # After the map, the digits are implicitly joined together to a string
      √ë  # Check that this string is a palindrome
         # (after which the entire stack joined together is output implicitly as result)
```
[Answer]
# [Arturo](https://arturo-lang.io), 42 bytes
```
$[n][1every? reverse digits n'x->x=n%<=1+]
```
[Try it](http://arturo-lang.io/playground?Ng8O9j)
]