Quantcast
Channel: Staircase numbers - Code Golf Stack Exchange
Browsing index pages (33 articles)

Staircase numbers

A staircase number is a positive integer x such that its nth 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....

View Article


Answer by Erik the Outgolfer for Staircase numbers

Jelly, 7 bytesDJ‘⁸%⁼ṚTry it online!

View Article


Answer by Adnan for Staircase numbers

05AB1E, 6 bytesCode:ā>%JRQUses the 05AB1E encoding. Try it online!Explanation:ā # Get the range [1 .. len(input)]> # Increment by 1 % # Vectorized modulo J # Join the array into a single number...

View Article

Answer by alephalpha for Staircase numbers

Pari/GP, 42 bytesn->Vecrev(s=digits(n))==[n%d|d<-[2..#s+1]]Try it online!

View Article

Answer by Shaggy for Staircase numbers

Japt, 97 6 bytesTakes input as a string.Ô¶¡%´J2 bytes saved with help from ETHproductions.Try itÔ¶¡%´J :Implicit input of string UÔ :Reverse¶ :Test for equality with ¡ :Map U % : Modulo´J : J...

View Article


Answer by ZaMoC for Staircase numbers

Mathematica, 60 bytesFromDigits@Reverse@Mod[#,Range@Length@IntegerDigits@#+1]==#&Try it online!@alephalpha golfed it to 48Mathematica, 48...

View Article

Answer by 0xffcourse for Staircase numbers

Python 2, 66 60 58 57 bytesThanks to @Leaky nun for 6 bytes: remove unneeded x and (shouldnot check for 0)Thanks to @Einkorn Enchanter for 1 byte: use of enumeratelambda x:all(a==`x%(i+2)`for i,a in...

View Article

Answer by Daniel for Staircase numbers

Python 2, 61 byteslambda x:[`x%(n+2)`for n in range(len(`x`))][::-1]==list(`x`)

View Article


Answer by Erik the Outgolfer for Staircase numbers

Brachylog, 252116 14 bytes{it+₂;?↔%}ᶠ↔c?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...

View Article


Answer by Okx for Staircase numbers

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 equalityTry it online!

View Article

Answer by Endenite for Staircase numbers

Javascript, 424139 38 bytes-4 bytes thanks to @Shaggy and @ETHProductionss=>[...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...

View Article

Answer by Jim for Staircase numbers

Pyth, 13 bytes-1 bytes thanks to Okx.qsjk_m%QhdSl`Try it online!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,...

View Article

Answer by Artyer for Staircase numbers

Python 2, 56 byteslambda x:all(`x%(i+2)`==`x`[~i]for i in range(len(`x`)))Try it online!

View Article


Answer by ovs for Staircase numbers

Python 2, 54 bytesf=lambda n,x=0:10**x>n or(`n%(x+2)`==`n`[~x])*f(n,x+1)Try it online!

View Article

Answer by Jörg Hülsermann for Staircase numbers

PHP, 43 bytesfor(;$r<$a=$argn;)$r=$a%~++$i.$r;echo$r>$a;Try it online!PHP, 44 bytesprints 1 for true and nothing for falsefor(;$r<$a=$argn;)$r=$a%~++$i.$r;echo$r==$a;Try it online!

View Article


Answer by qfwfq for Staircase numbers

Haskell, 60 bytesTakes the number as an intx n|s<-show n=reverse s==(rem n.(+1)<$>[1..length s]>>=show)

View Article

Answer by Sean for Staircase numbers

Perl 6, 32 bytes{$_ eq[~] $_ «%«(1+.comb...2)}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...

View Article


Answer by Neil for Staircase numbers

Charcoal, 20 15 bytes⌊Eθ⁼ιI﹪Iθ⁻⁺¹LθκTry it online! Outputs - for a staircase number, nothing otherwise. Link is to verbose version of code.

View Article

Answer by Silvio Mayolo for Staircase numbers

Haskell, 55 57 bytesf m|let n#x=n==0||n`mod`10==m`mod`x&&div n 10#(x+1)=m#2A different approach than the other Haskell solution.Thanks xnor for saving 2 bytes.

View Article

Answer by mkst for Staircase numbers

q/kdb+, 34 bytesSolution:{s~raze($)x mod'2+(|)(!)(#)s:($)x}Example:q){s~raze($)x mod'2+(|)(!)(#)s:($)x}7211311 / this is a staircase number (true)1bq){s~raze($)x mod'2+(|)(!)(#)s:($)x}7211312 / this is...

View Article
Browsing index pages (33 articles)


Latest Images