[Question]
  [
Generate the sequence *number of bases in which `n` is a palindrome* ([OEIS A126071](https://oeis.org/A126071)).
Specifically, the sequence is defined as follows: given a number `n`, express it in base `a` for `a = 1,2, ..., n`, and count how many of those expressions are palindromic. "Palindromic" is understood in terms of reversing the base-`a` digits of the expression as atomic units (thanks, [@Martin Büttner](https://codegolf.stackexchange.com/users/8478/martin-b%C3%BCttner)). As an example, consider `n = 5`:
* `a=1`: the expression is `11111`: palindromic
* `a=2`: the expression is `101`: palindromic
* `a=3`: the expression is `12`: not palindromic
* `a=4`: the expression is `11`: palindromic
* `a=5`: the expression is `10`: not palindromic
Therefore the result for `n=5` is `3`. Note that OEIS uses bases `2, ..., n+1` instead of `1, ..., n` (thanks, [@beaker](https://codegolf.stackexchange.com/users/42892/beaker)). It's equivalent, because the expressions in base `1` and `n+1` are always palindromic.
The first values of the sequence are
```
 1, 1, 2, 2, 3, 2, 3, 3, 3, 4, 2, 3, 3, 3, 4, 4, 4, 4, 2, 4, 5, ...
```
Input is a positive integer `n`. Output is the first `n` terms of the sequence.
The program should theoretically work (given enough time and memory) for any `n` up to limitations caused by your default data type in any internal computations.
All functions allowed. Lowest number of bytes wins.
  
[Answer]
## Pyth, 13 bytes
```
mlf_ITjLdSdSQ
```
The brevity of this is mostly due to the `I`nvaluable "`I`nvariant" command.
```
msf_ITjLdSdSQ       implicit: Q=input
m         d         map lambda d over
           SQ       Inclusive range 1 to Q
      jLdSd         Convert d to all the bases between 1 and d
  f                  filter lambda T:
   _IT                 is invariant under reverse
 l                  number that are invariant under reverse
```
If `True` is an acceptable output for `1`, `msm_IjdkSdSQ` (12 bytes) works.
Try it [here](http://pyth.herokuapp.com/?code=mlf_ITjLdSdSQ&input=10&debug=1).
[Answer]
# Jelly, 12 bytes
```
bRµ=UP€S
RÇ€
```
[Try it online!](http://jelly.tryitonline.net/#code=YlLCtT1VUOKCrFPCtlLDh-KCrA&input=&args=MTA)
An old 14-byte version (The Jelly interpreter had a bug that made converting to unary impossible)
```
bR‘$µ=UP€S
RÇ€
```
[Try it online!](http://jelly.tryitonline.net/#code=YlLigJgkwrU9VVDigqxTClLDh-KCrA&input=&args=MTA)
### How it works
```
bR‘$µ=UP€S  Helper link. Argument: z
 R‘$        Apply range and increment, i.e., map z to [2, ..., z + 1].
            In the non-competing version R simply maps z to [1, ... z].
b           Convert z to each of the bases to the right.
    µ       Begin a new, monadic chain. Argument: base conversions
     =U     Compare the digits of each base with the reversed digits.
            = has depth 0, so [1,2,3]=[1,3,3] yields [1,0,1].
       P€   Take the product of the innermost arrays.
         S  Sum all resulting Booleans.
RÇ€         Main link. Argument: n
R           Yield [1, ..., n].
 Ç€         Apply the helper link to each.
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 19 ~~20~~ bytes
```
:"0@XK:Q"K@:YAtP=A+
```
Uses [current release (10.1.0)](https://github.com/lmendo/MATL/releases/tag/10.1.0), which is earlier than this
challenge.
[**Try it online**!](http://matl.tryitonline.net/#code=OiIwQFhLOlEiS0A6WUF0UD1BKw&input=MTA)
### Explanation
```
:            % vector [1,2,...,N], where "N" is implicit input
"            % for each number in that vector
  0          % push 0
  @          % push number 1,2,...N corresponding to current iteration, say "n" 
  XK         % copy n to clipboard
  :Q         % vector [2,3,...,n+1]
  "          % for each number "m" in that vector
    K        % push n
    @:       % vector [1,2,...,m]
    YA       % express n in base m with symbols 1,2,...,m
    tP       % duplicate and permute
    =A       % 1 if all entries are equal (palindrome), 0 otherwise
    +        % add that number
             % implicitly close the two loops and display stack contents
```
[Answer]
## ES6, 149 bytes
```
n=>[...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 too.
[Answer]
## CJam, 20 bytes
```
ri{)_,f{)b_W%=}1bp}/
```
[Test it here.](http://cjam.aditsu.net/#code=ri%7B)_%2Cf%7B)b_W%25%3D%7D1bp%7D%2F&input=20)
[Answer]
# Python 2, 97 bytes
```
c=1;n=int(input())
for b in range(2,n):
	a=[];z=n
	while z:a+=[z%b];z//=b
	c+=a[::-1]==a
print c
```
My first Python post, actually my first Python code at all  
probably has some golfing potential.
[Try it online!](https://tio.run/##DcyxCsMgEADQ2fuKWwpKWoIZDfcl4nBK2gjlImII9edt1je88mv7IcsYiewqlKXpLOVs2hh4HxUjZsHK8tn08hTjQDH5sHYSUNeevxt2xxP5/oi3zjNFUGki9s69bCBiKPVOMcEY9g8)
[Answer]
# Haskell, 88 bytes
```
a!b|a<b=[a]|1>0=mod a b:(div a b)!b
f n=[1+sum[1|x<-[2..y],y!x==reverse(y!x)]|y<-[1..n]]
```
[Answer]
# JavaScript (ES6), ~~105~~ 95 bytes
```
f=(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)]
```
## Explanation
Takes a number from 1 to 36 (the limitation of base conversion in JavaScript) and returns an array of the sequence.
Recursive function that checks for palindromes when a base is passed, else returns the sequence if just `n` is passed.
```
f=(n,b)=>
  // Base palindrome checking
  b?
    b<3?1:                 // return 1 for base-1, since toString(2)
    f(n,b-1)+(             // return the sum of all lower bases and check  this
      [...s=n.toString(b)] // s = n in base b
      .reverse().join``==s // add 1 if it is a palindrome
    )
  // Sequence generation
  :
    n<2?[1]:               // return 1 for the first value of the sequence
    [...f(n-1),f(n,n)]     // return the value for n after the previous values
```
## Test
```
var solution = f=(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)]
```
```
<input type="number" oninput="result.textContent=solution(+this.value)" />
<pre id="result"></pre>
```
[Answer]
# PHP, 73+1 bytes
```
while(++$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](http://sandbox.onlinephpfunctions.com/code/85ba61651bf57830f7aa8ff228c0b77b5ec28447).
[Answer]
# 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](http://sandbox.onlinephpfunctions.com/code/0897aa4aa94a4bbad8b7402904ccf2f817d3906a).
[Answer]
# ><>, 197+2 Bytes
+2 for -v flag
```
:1+0v    ;n\
1\  \$:@2(?/
:<~$/?)}:{:*}}@:{{
\   \~0${:}
>$:@1(?\::4[:&r&r]:$&@@&%:&@&$@-$,5[1+{]$~{{:@}}$@,$
~~1 \  \
?\~0>$:@2(?\$1-:@3+[}]4[}1-]=
 \  /@@r/!?/
r@+1/)0:<
  /?/$-1$~<
~$/       \-1
```
tio.run doesn't seem to return any output for n>1, but you can verify it on <https://fishlanguage.com>. Input goes in the "Initial stack" box.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 10 bytes
```
õ_õ!ìZ èêS
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.6&code=9V/1IexaIOjqUw==&input=OA==)
---
## Explanation
```
õ              :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
```
[Answer]
# [Python 2](https://docs.python.org/2/), 85 bytes
```
def 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 c
```
[Try it online!](https://tio.run/##BcFLDsIgFADAtZ6CjSkIRmEJeSehLPhaEnltSBPx9Dhz/M5tRzVnyoUU6pkOIoISL5NHjksSDawTfsXvVj@ZNJ042HYLzrQnhBUjh2S1fkgHkEzgIM1y9@boFU8SZ9k7GaQi6R7fmUqhJNPXS6GDzT8 "Python 2 – Try It Online")
Expects an integer as an argument.
Explanation:
```
# named function
def f(a):
    # initialize variable to track base (b) and to track palindromes (c)
    b,c=2,0
        # construct code
        '
        # initialize variable to store remainders (m) and to track divisor (d)
        m,d=[],a
        # while d is not zero,
        # add the current remainder to the array
        # and divide d by the base and assign the result back to d
        while d:m+=[m%b];d/=b
        # False == 0 and True == 1, so add 1 to total if m == reversed(m)
        c+=m[::-1]==m;
        # increment base
        # terminate with ; so that next statement can be executed separately
        b+=1;
        '
    # execute constructed statement (a) times
    exec'....................................................'*a
    # print result
    print c
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 13 bytes
```
mλṁoS=↔`B¹ḣ)ḣ
```
[Try it online!](https://tio.run/##yygtzv7/P/fc7oc7G/ODbR@1TUlwOrTz4Y7FmkD8//9/UwA "Husk – Try It Online")
not sure if I can avoid using a lambda here.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
bRfU$Lµ€
```
[Try it online!](https://tio.run/##y0rNyan8/z8pKC1UxefQ1kdNa/7//28KAA "Jelly – Try It Online")
Alternatively:
```
bRŒḂ€Sµ€
```
[Try it online!](https://tio.run/##y0rNyan8/z8p6OikhzuaHjWtCT60FUj@///fFAA "Jelly – Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 80 bytes
```
n=>(h=(a,g=n=>n?[n%a,...g(n/a|0)]:[])=>--a<2||(g(n).reverse()+''==g(n))+h(a))(n)
```
[Try it online!](https://tio.run/##FYnLDsIgEAC/xnQ3PKw92m79kKaHTQWqNGDA9MS/I14mk5k3n5y39Pp8VYhPUy3VQDPsBCwdNQ2PJVxYaq0dhCuXHtf7siLNSvE0lAIto07mNCkbQNF1RP@EYgdGbFZtTOA93Ubvp6EfhfAetxhyPIw@omtPCtuIWH8 "JavaScript (Node.js) – Try It Online")
Add 1 at last manually
[Answer]
# [Perl 5](https://www.perl.org/) `-Minteger -pa`, 81 bytes
```
map{@n=($t="@F")%$_;push@n,$t%$_ while$t/=$_;$\+="@n"eq"@{[reverse@n]}"}2..$_+1}{
```
[Try it online!](https://tio.run/##DYpBCsIwEAC/ImEFpTa2SgWRQE7efIFK6WGxgbqNyaqHkK@75jQMMx7D1Ik8B58smRWwUfas1kvoT/4dR0sb4CKL7@gmBN6aEuBWlYsUvpRN14AfDBEt3bPKO62hr9qcRI77w2/27GaKUl863bRNoSPGBwap/fAH "Perl 5 – Try It Online")
]