Quantcast
Channel: Staircase numbers - Code Golf Stack Exchange
Browsing all 33 articles
Browse latest View live

Answer by Peter for Staircase numbers

C (GCC), 65 64 bytes-1 byte thanks to @ceilingcati,j,k;f(n){for(i=j=k=1;++j,i<n;i*=10)k=n/i%10^n%j?0:k;return k;}Try It Online!Explanation:i,j,k;f(n){ // i and k are 1, j is 2 since it's incremented...

View Article



Answer by xigoi for Staircase numbers

Nibbles, 8.5 bytes==.,,;`@~$%_+$~\@Attempt This Online!==.,,;`@~$%_+$~\@== Equal . map , range , length ; A := `@~ decimal digits $ input % mod _ input+ add $ it ~ 1 \ reverse @ A

View Article

Answer by chunes for Staircase numbers

Arturo, 42 bytes$[n][1every? reverse digits n'x->x=n%<=1+]Try it

View Article

Answer by Kevin Cruijssen for Staircase numbers

MathGolf, 7 bytesmækî)%ÑInput as a string.Try it online.Explanation:m # Map over each character of the (implicit) input-string,æ # using the following four characters as inner code-block: # (implicitly...

View Article

Answer by Lynn for Staircase numbers

Haskell, 53 bytesf n=foldr(\(k,_)a->10*a+mod n k)0(zip[2..]$show n)==nTry it online!

View Article


Answer by Razetime for Staircase numbers

APL (Dyalog Extended), 21 19 bytes{⍵=10⊥⌽⍵|⍨1↓⍳1+≢⍕⍵}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...

View Article

Answer by Xcali for Staircase numbers

Perl 5, 41 bytes39 bytes of code + 2 flags -pamap{$\||=$_!=$F[0]%++$n}0,reverse/./g}{Try it online!Outputs nothing (undef) for staircase numbers, 1 for anything else

View Article

Answer by archaephyrryx for Staircase numbers

Haskell, 62 bytesf 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...

View Article


Answer by Olivier Grégoire for Staircase numbers

Java (OpenJDK 8), 60 bytesn->{int m=2,r=0,t=1;for(;n>=t;t*=10)r+=n%m++*t;return r==n;}Try it online!A non-string version.

View Article


Answer by bendl for Staircase numbers

Python 3: 63 Byteslambda 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!

View Article

Answer by NikoNyrh for Staircase numbers

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.

View Article

Answer by koita_pisw_sou for Staircase numbers

C++,104 bytes1) 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 =...

View Article

Answer by Alex Ferretti for Staircase numbers

Java 8, 156149 bytesinterface 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...

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

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 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 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 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 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 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
Browsing all 33 articles
Browse latest View live




Latest Images