Quantcast
Channel: All your base palindromic belong to us - Code Golf Stack Exchange
Browsing latest articles
Browse All 18 View Live

Answer by l4m2 for All your base palindromic belong to us

JavaScript (Node.js), 80 bytesn=>(h=(a,g=n=>n?[n%a,...g(n/a|0)]:[])=>--a<2||(g(n).reverse()+''==g(n))+h(a))(n)Try it online!Add 1 at last manually

View Article



Answer by Xcali for All your base palindromic belong to us

Perl 5-Minteger -pa, 81 bytesmap{@n=($t="@F")%$_;push@n,$t%$_ while$t/=$_;$\+="@n"eq"@{[reverse@n]}"}2..$_+1}{Try it online!

View Article

Answer by Razetime for All your base palindromic belong to us

Husk, 13 bytesmλṁoS=↔`B¹ḣ)ḣTry it online!not sure if I can avoid using a lambda here.

View Article

Answer by Triggernometry for All your base palindromic belong to us

Python 2, 85 bytesdef f(a):b,c=2,0;exec'd,m=[],a\nwhile m:d+=[m%b];m/=b\nc+=d[::-1]==d;b+=1;'*a;print cTry it online!Expects an integer as an argument.Explanation:# named functiondef f(a): # initialize...

View Article

Answer by Shaggy for All your base palindromic belong to us

Japt, 10 bytesõ_õ!ìZ èêSTry itExplanationõ :Range [1,input] _ :Map each Zõ : Range [1,Z] (let's call each X) !ìZ : Convert Z to a base X digit arrayè : CountêS : Palindromes

View Article


Answer by Sasha for All your base palindromic belong to us

><>, 197+2 Bytes+2 for -v flag:1+0v ;n\1\ \$:@2(?/:<~$/?)}:{:*}}@:{{\ \~0${:}>$:@1(?\::4[:&r&r]:$&@@&%:&@&$@-$,5[1+{]$~{{:@}}$@,$~~1 \...

View Article

Answer by Titus for All your base palindromic belong to us

Python 2, 97 bytesc=1;n=int(input())for b in range(2,n): a=[];z=n while z:a+=[z%b];z//=b c+=a[::-1]==aprint cMy first Python post, actually my first Python code at allprobably has some golfing...

View Article

Answer by Titus for All your base palindromic belong to us

PHP, 92+1 bytes:for($b=$c=1;$b++<$n=$argn;$c+=$a==array_reverse($a))for($a=[];~~$n;$n/=$b)$a[]=$n%$b;echo$c;works for all bases. Run as pipe with -nR or try it online.

View Article


Answer by Titus for All your base palindromic belong to us

PHP, 73+1 byteswhile(++$i<$argn)$c+=strrev($n=base_convert($argn,10,$i+1))==$n;echo$c+1;works for bases 1 to 36. Run as pipe with -nR or try it online.

View Article


Answer by Erik the Outgolfer for All your base palindromic belong to us

Jelly, 8 bytesbRfU$Lµ€Try it online!Alternatively:bRŒḂ€Sµ€Try it online!

View Article

Answer by Neil for All your base palindromic belong to us

ES6, 149 bytesn=>[...Array(n)].map((_,i)=>[...Array(i)].reduce((c,_,j)=>c+(''+(a=q(i+1,j+2,[]))==''+a.reverse()),1),q=(n,b,d)=>n<b?[n,...d]:q(n/b|0,b,[n%b,...d]))Works for bases > 36...

View Article

Answer by Damien for All your base palindromic belong to us

Haskell, 88 bytesa!b|a<b=[a]|1>0=mod a b:(div a b)!bf n=[1+sum[1|x<-[2..y],y!x==reverse(y!x)]|y<-[1..n]]

View Article

Answer by user81655 for All your base palindromic belong to us

JavaScript (ES6), 105 95 bytesf=(n,b)=>b?b<2?1:f(n,b-1)+([...s=n.toString(b)].reverse().join``==s):n<2?[1]:[...f(n-1),f(n,n)]ExplanationTakes a number from 1 to 36 (the limitation of base...

View Article


Answer by Martin Ender for All your base palindromic belong to us

CJam, 20 bytesri{)_,f{)b_W%=}1bp}/Test it here.

View Article

Answer by Dennis for All your base palindromic belong to us

Jelly, 12 bytesbRµ=UP€SRÇ€Try it online!An old 14-byte version (The Jelly interpreter had a bug that made converting to unary impossible)bR‘$µ=UP€SRÇ€Try it online!How it worksbR‘$µ=UP€S Helper link....

View Article


Answer by lirtosiast for All your base palindromic belong to us

Pyth, 13 bytesmlf_ITjLdSdSQThe brevity of this is mostly due to the Invaluable "Invariant" command.msf_ITjLdSdSQ implicit: Q=inputm d map lambda d over SQ Inclusive range 1 to Q jLdSd Convert d to all...

View Article

Answer by Luis Mendo for All your base palindromic belong to us

MATL, 19 20 bytes:"0@XK:Q"K@:YAtP=A+Uses current release (10.1.0), which is earlier than thischallenge.Try it online!Explanation: % vector [1,2,...,N], where "N" is implicit input" % for each number in...

View Article


All your base palindromic belong to us

Generate the sequence number of bases in which n is a palindrome (OEIS A126071).Specifically, the sequence is defined as follows: given a number n, express it in base a for a = 1,2, ..., n, and count...

View Article
Browsing latest articles
Browse All 18 View Live




Latest Images