[Question]
  [
The objective of this challenge is to write a program to convert an inputed string of what can be assumed as containing *only* letters and numbers from as many bases between 2 and 36 as possible, and find the base 10 sum of the results.
The input string will be converted to all the bases in which the number would be defined according to the standard alphabet for bases up to 36: `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`. For example, the input `2T` would be valid in only bases 30 and up. The program would convert 2T from bases 30 through 36 to decimal and sum the results.
You may assume that the input string contains only letters and numbers. Your program may use uppercase or lowercase; it can, but does not need to, support both.
---
**Test cases**
*Sample input:* `2T`
Chart of possible bases
```
Base   Value
30     89
31     91
32     93
33     95
34     97
35     99
36     101
```
Output: 665
*Sample input:* `1012`
Chart of possible bases: 
```
Base   Value
3      32
4      70
5      132
6      224
7      352
8      522
9      740
10     1012
11     1344
12     1742
13     2212
14     2760
15     3392
16     4114
17     4932
18     5852
19     6880
20     8022
21     9284
22     10672
23     12192
24     13850
25     15652
26     17604
27     19712
28     21982
29     24420
30     27032
31     29824
32     32802
33     35972
34     39340
35     42912
36     46694
```
Output: `444278`
*Sample input:* `HELLOworld`
Chart of possible bases
```
Base   Value
33     809608041709942
34     1058326557132355
35     1372783151310948
36     1767707668033969
```
Output: `5008425418187214`
An input of `0` would be read as `0` in all bases between 2 and 36 inclusive. There is no such thing as base 1.
---
This is code golf. Standard rules apply. Shortest code in bytes wins.
  
[Answer]
# Python 3, ~~72~~ ~~71~~ 69 bytes
Thanks to FryAmTheEggman for saving a byte!
Thanks to DSM for saving 2 bytes!
```
N=x=0
y=input()
while N<36:
 N+=1
 try:x+=int(y,N)
 except:0
print(x)
```
[Answer]
# Pyth, 20 19 11 bytes
```
sm.xizd0S36
```
Blatantly stole Adnan's idea from his Python answer.
[Try it here](https://pyth.herokuapp.com/?code=sm.xizd0S36&input=HELLOworld&debug=0)
[Answer]
# Pure [Bash](https://www.gnu.org/software/bash/), 26
```
((s+={36..2}#$1,))
echo $s
```
[Try it online!](https://tio.run/##S0oszvhfnpGZk6pQlJqYopCZV1BaYq2Qks9VnFqioKuroAIW@a@hUaxtW21spqdnVKusYqijqcmVmpyRr6BS/D8lPy/1vwGXUQiXoYGhEZeHq4@Pf3l@UU4KFwA "Bash – Try It Online")
---
Old answer from 5 years ago:
# Pure Bash (no utilities), 38
Assuming built-in base conversions are allowed:
```
for((b=36;s+=$b#$1;b--));{ :;}
echo $s
```
This will output an error to STDERR. I'm assuming this is OK as per [this meta answer](https://codegolf.meta.stackexchange.com/a/4781/11259).
### Test output:
```
$ for t in 0 2T 1012 HELLOworld; do ./basesum.sh $t; done 2> /dev/null
0
665
444278
5008425418187214
$ 
```
[Answer]
## Seriously, 65 bytes
```
,û;╗rk`"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"íu`MSd:37:@x`╜¿`MΣ.
```
Contains unprintables, hexdump:
```
2c963bbb726b6022303132333435363738394142434445464748494a4b4c4d4e4f505152535455565758595a22a175604d53643a33373a407860bda8604de42e7f
```
Unfortunately I don't have a good way to filter from a list based on types. Note to self: add that.
Takes input like `"2T"`
[Try it online](http://seriouslylang.herokuapp.com/link/code=2c963bbb726b6022303132333435363738394142434445464748494a4b4c4d4e4f505152535455565758595a22a175604d53643a33373a407860bda8604de42e7f&input=) (you will have to manually enter input)
Explanation:
```
,û    get input and convert to uppercase
;╗    make a copy and save to register 0
rk    explode string into list
`"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"íu`M  map the function over the list:
    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"íu    get the character's index in the string and add one to get a value in [1,36]
Sd    get maximum element (maximum base aka max_base) from list by sorting and popping the last element off and pushing it to the stack
:37:@x  push range(max_base,37)
`╜¿`M  map the function over the list:
    ╜¿    convert value in register 0 to an int, interpreting it as a base-n int (n is value from list)
Σ.    sum and print
0x7f  quit
```
[Answer]
# Mathematica, 57 bytes
```
#~Sum~{x,Max@CoefficientList[#,x]+1,36}&@FromDigits[#,x]&
```
[Answer]
# Matlab, 98 bytes
```
function y=f(s)
[~,m]=max(bsxfun(@eq,s,[48:57 65:90]'));y=0;for n=max(m):36
y=y+base2dec(s,n);
end
```
[Answer]
# Octave, ~~75~~ 73 bytes
```
function v=u(a) m([48:57 65:90])=0:35;v=sum(polyval(t=m(a),max(t)+1:36));
```
### Explanation:
```
function v=u(a) 
   m([48:57 65:90])=0:35; %// create a map: '0'-'9' = 0-9
                          %//               'A'-'Z' = 10-35
   t=m(a);                %// convert string to mapped values
   b=max(t)+1;            %// find minimum base
   p=polyval(t,b:36);     %// calculate polynomial for each base (vectorized)
   v=sum(p);              %// and return the sum of the resulting vector
```
`polyval` has an advantage over `base2dec` in that it's vectorized, so no `for` loop is required.
Only '0'..'9' and upper-case 'A'..'Z' are supported as input.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 22 bytes
or **[21 bytes](https://tio.run/##ATUAyv9odXNr///Cp@G5gWBCw7YtMeKApjM24oaS4paybcivJTQ4JTg3Y////yJoZWxsb3dvcmxkIg)** with only lowercase input
```
§ṁ`Bö-1…36→▲mö%48%87c_
```
[Try it online!](https://tio.run/##ATYAyf9odXNr///Cp@G5gWBCw7YtMeKApjM24oaS4paybcO2JTQ4JTg3Y1////8iSEVMTE93b3JsZCI "Husk – Try It Online")
```
§ṁ`Bö-1…36→▲mö%48%87c_
§                       # fork: apply 2 functions to same argument
 ṁ`B                    # function 1: 
 ṁ                      # sum of elements of argument
  `B                    # interpreted as base N, with N given by
    ö-1…36→▲            # function 2:
    ö                   # combine 4 funcitions:
     -1                 # remove elements equal to 1 from 
       …36              # series from 36 to
          →             # one less than
           ▲            # max value of argument
            mö%48%87c_  # fork argument:
            mö          # map 4 functions over input:
                     _  # convert to lowercase  
                    c   # get ASCII value
                 %87    # MOD 87
              %48       # MOD 48
```
[Answer]
# [Haskell](https://www.haskell.org/), 77 bytes
```
f s|d<-[mod(fromEnum c+30)39|c<-s]=sum[foldl1((+).(b*))d|b<-[2..36],all(<b)d]
```
[Try it online!](https://tio.run/##Xc6xCoMwFEDRvV/xCB2SWoNJoFCIY79CHIyvQemLKUbpkn9PXdv1wIU7Den1JCrFQ8po6y5E5H6N4bHsAcbKNMLc82jr1LdpD52PhKQ4r4Tk7iIEZndEWkpz668DEbdOYF/CMC8txhPAe52XDc7ggemN/YJqlP6j6ZiJn7gSsvIF "Haskell – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 44 bytes
```
sum(sapply(2:36,strtoi,x=scan(,"")),na.rm=T)
```
[Try it online!](https://tio.run/##K/r/v7g0V6M4saAgp1LDyMrYTKe4pKgkP1OnwrY4OTFPQ0dJSVNTJy9RryjXNkTzv1HIfwA "R – Try It Online")
R has a builtin, `strtoi`, to convert from a string to an integer in base `2:36` using only digits and capital letters, returning `NA` if it's invalid in that base. We can then `sum` them up, removing the `NA`s with `na.rm=T`.
Luckily, `sapply` is smart enough about named arguments to make this work.
[Answer]
# [Desmos](https://www.desmos.com/calculator), 85 bytes
```
f(x)=x+3.5sign(60-x)-51.5
l=i.length
\sum_{n=f(i).max+1}^{36}\sum_{m=1}^lf(i[m])n^{l-m}
```
[View it on Desmos](https://www.desmos.com/calculator/kxezhs3aon) (includes a bonus version that costs 2 extra bytes)
Explanation:
Input is through an array of integers `i`, as Desmos doesn't support strings. Capital letters are required.
The first function transforms a codepoint to the value in base-36, or any other base that it's valid in. The second function simply stores `i.length`, as it's expensive to call.
The third function can be understood as such:
```
\sum_{n=f(i).max+1}^{36}    Iterate n from 1+the largest codepoint value, which will be the smallest valid base, to 36, the largest valid base
\sum_{m=1}^l                Iterate m over the indices of i (Desmos is 1-indexed)
f(i[m])                     Find the value of the mth character
n^{l-m}                     Multiply by the base to the power of its distance to the right
                            Add everything up (due to using sums earlier)
```
[Answer]
# Scala, 64 bytes
Requires uppercase input
```
s=>(s.map(_%55%48).max+1 to 36).map(b=>(0L/:s)(_*b+_%55%48)).sum
```
[Try it in Scastie](https://scastie.scala-lang.org/LMGf9P2ySS26B42PXIfTDQ)
-7 bytes by using a Long (`0L`) instead of a BigInt (`BigInt(0)`)
This might have been shorter if I'd used `try`/`catch` with `BigInt(number, base)`, but I didn't want to do that. ~~Still wish I could inline `n`, but I need it to determine the first valid base.~~ Apparently, it's one byte shorter by not doing `val n=s.map(_%55%48)` and reusing `n`.
Explanation:
```
s =>                        //Input
  (s.map(_ % 55 % 48)       //Turn the characters into numbers 0-35
    .max+1                  //The maximum of that (minimum base)
      to 36)                //Range of bases up to 36
  .map(b =>                 //For each base b, interpret the input in that base
    (BigInt(0)              //Starting with 0,
              /:s)          //Fold left over the input
    (_ * b +                //Multiply the accumulator by the base
      _ % 55 % 48)          //And add the next digit (put it in the range [0, 35])
  ).sum                     //Take the sum
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
```
ØBiⱮµ’ḅṀr36ƊS
```
[Try it online!](https://tio.run/##ASwA0/9qZWxsef//w5hCaeKxrsK14oCZ4biF4bmAcjM2xopT////SEVMTE9XT1JMRA "Jelly – Try It Online")
Works only for uppercase letters.
## Explanation
```
ØBiⱮµ’ḅṀr36ƊS   Monadic link
   Ɱ            Map over argument:
  i             Find 1-based index in...
ØB              ...base digits: "0123456789ABCD...YZabcd...yz"
    µ           Use as argument to new monadic chain
     ’          Decrement (to get 0-based indices)
      ḅ         Convert to base... (auto-mapped)
           Ɗ    ...treat 3 preceding atoms as a single link:
       Ṁ        Maximum [of argument, which is the 1-based indices]
        r36     Inclusive range to 36
            S   Sum
```
[Answer]
## CJam, ~~28~~ 27 bytes
*Thanks to Reto Koradi for saving 1 byte.*
This is kinda horrible...
```
qA,s'[,65>+f#_:e>)37,>\fb:+
```
Requires upper case letters.
[Test it here.](http://cjam.aditsu.net/#code=qA%2Cs'%5B%2C65%3E%2Bf%23_%3Ae%3E)37%2C%3E%5Cfb%3A%2B&input=2T)
CJam doesn't have built-in base-36 conversion from strings, so we have to letters out the strings ourselves. I've been trying all sorts of divmod shenanigans, but it seems to be shortest to build a string of all 36 digits and just find the index of each character in that string.
[Answer]
# C function, 93 (32 bit integer output only)
Assuming its OK for the output to only go up to INT\_MAX, then we can do this:
```
i,n,x;f(char *s){char *e;for(i=36,x=0;n=strtol(s,&e,i--),!*e&&i;)x+=*e?0:n;printf("%d\n",x);}
```
---
The last testcase implies that this is probably not sufficient. If so, then with 64-bit integers we have:
# C function, 122
```
#include<stdlib.h>
f(char *s){long long i=36,n,x=0;char *e;for(;n=strtoll(s,&e,i--),!*e&&i;)x+=*e?0:n;printf("%lld\n",x);}
```
Unfortunately the `#include <stdlib.h>` is required so the return type of `strtoll()` is correct. We need to use `long long` to handle the `HELLOworld` testcase. Otherwise this could be a fair bit shorter.
### Test driver:
```
#include<stdlib.h>
f(char *s){long long i=36,n,x=0;char *e;for(;n=strtoll(s,&e,i--),!*e&&i;)x+=*e?0:n;printf("%lld\n",x);}
int main (int argc, char **argv)
{
    f("0");
    f("2T");
    f("1012");
    f("HELLOworld");
}
```
### Test output:
```
$ ./basesum
0
665
444278
5008425418187214
$ 
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-x`](https://codegolf.meta.stackexchange.com/a/14339/), ~~17~~ 16 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
36õ2 k@kUnXXÃ£nX
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LXg&code=Mzb1MiBrQGtVblhYw6NuWA&input=IjJUIg)
[Answer]
# [Factor](https://factorcode.org/), 38 bytes
```
[ 37 iota [ base> ] with map sift Σ ]
```
[Try it online!](https://tio.run/##JcwxCsIwFIfx3VP8yQGKrYOgIC6iQtFBnUqHmL7SYE3iyyvF83gfrxQLTt9v@lptxHO6XY6n/QoPYkc9nlq6LGiOxH8PzhrfEAKTyDuwdYJIr4GcoYj1TBVXNVP5PC@mHHZleR49941KFRZLWC8aFe460gY1RivdtA2IthV8P6iTsN0iizA9aU4/ "Factor – Try It Online")
## Explanation:
It's a quotation (anonymous function) that takes a string from the data stack as input and leaves an integer on the data stack as output.
* `37 iota` Create a range from 0 to 36 inclusive.
* `[ base> ] with map` Convert the input to base 10 from each base between 0 and 36. If the input can't be converted from particular base, `base>` returns `f`.
* `sift` Remove all the `f` from a sequence.
* `Σ` Sum.
[Answer]
# [Japt](https://github.com/ETHproductions/Japt), 26 bytes
```
1+U¬r@XwYn36}0)o37 £UnX} x
```
[Try it online!](http://ethproductions.github.io/japt?v=master&code=MStVrHJAWHdZbjM2fTApbzM3IKNVblh9IHg=&input=IkhFTExPd29ybGQi)
### Ungolfed and explanation
```
1+U¬ r@   XwYn36}0)o37 £    UnX} x
1+Uq rXYZ{XwYn36}0)o37 mXYZ{UnX} x
           // Implicit: U = input string
Uq rXYZ{   // Split U into chars, and reduce each item Y and previous value X by:
XwYn36     //  Choosing the larger of X and parseInt(Y,36),
}0         // starting at 0.
1+   )o37  // Add 1 and create a range from this number to 36.
mXYZ{UnX}  // Map each item X in this range to parseInt(U,X)
x          // and sum.
           // Implicit: output last expression
```
[Answer]
# Python 3, 142 bytes
[Adnan](https://codegolf.stackexchange.com/users/34388/adnan) has me soundly beat with their solution, but I did want to add my own attempt.
```
def f(s):
 t=0
 for x in range(37):
  n=0
  for i in s:
   try:m=int(i)
   except:m=ord(i)-55
   if x<=m:n=0;break
   n=n*x+m
  t+=n
 return t
```
This function only handles uppercase inputs. Add `.upper()` to `for i in s`, and it will handle both uppercase and lowercase.
[Answer]
# Pyth, 16 bytes
```
V36 .x=+ZizhN ;Z
```
[Try it online](https://pyth.herokuapp.com/?code=V36%20.x%3D%2BZizhN%20%3BZ&input=1012&debug=0)
Explaination:
```
                 # Implicit: Z = 0, z = input
V36              # For N in range 36
    .x           # Try except
      =+Z        # Z = Z + izhN
         izhN    # Convert z from base N+1 to decimal
              ;  # Infinite ), for closing the for loop
               Z # Print Z
```
[Answer]
# Scala 2.11, 93 bytes
This is run on the scala console.
```
val i=readLine
var s=0
for(j<-2 to 36)try{s=s+Integer.parseInt(i,j)}catch{case _:Exception=>}
```
[Answer]
## Haskell, 97 bytes
```
i c|'_'<c=fromEnum c-87|1<2=read[c]
f s=sum$map((`foldl1`map i s).((+).).(*))[1+i(maximum s)..36]
```
Supports only lowercase characters. Usage example:
```
f "2t"           -> 665
f "helloworld"   -> 5008425418187214
```
It's so massive, because I have to implement both char-to-ASCII and base conversion myself. The corresponding pre-defined functions are in modules which require even more expensive imports.
How it works: `i` converts a character `c` to it's digit value (e.g. `i 't'` -> `29`). `f` calculates the value of the input string for every possible base and sums it. A non-pointfree version of the inner loop is `map (\base -> foldl1 (\value digit -> value*base + digit) (map i s)) [ ...bases... ]`.
[Answer]
# JavaScript (ES6), 86 bytes
```
s=>eval(`p=parseInt;b=2;[...s].map(d=>(v=p(d,36))>b?b=v:0);for(r=0;++b<37;)r+=p(s,b)`)
```
## Explanation
```
s=>
  eval(`                     // use eval to enable for loop without return keyword or {}
    p=parseInt;
    b=2;                     // b = minimum base of s
    [...s].map(d=>           // iterate through each digit d
      (v=p(d,36))            // get it's base-36 value
        >b?b=v:0             // set b to the max value
    );
    for(r=0;++b<37;)         // r = sum of all base values
      r+=p(s,b)              // add each base value from b to 36 to r
  `)                         // implicit: return r
```
## Test
```
<input type="text" id="input" value="HELLOworld" />
<button onclick="result.textContent=(
s=>eval(`p=parseInt;b=2;[...s].map(d=>(v=p(d,36))>b?b=v:0);for(r=0;++b<37;)r+=p(s,b)`)
)(input.value)">Go</button>
<pre id="result"></pre>
```
[Answer]
## [Perl 6](http://perl6.org), 35 bytes
```
{[+] map {+(":$^a"~"<$_>")||0},^37}
```
usage:
```
# store it somewhere
my &code = {[+] map {+(":$^a"~"<$_>")||0},^37}
say code 'HELLOworld' # 5008425418187214
say map &code, <2T 1012>
# (665 444278)
say code 'qwertyuiopasdfghjklzxcvbnm1234567890'
# 79495849566202185148466281109757186006261081372450955140
```
[Answer]
## Ceylon, ~~100~~ 96 bytes
```
Integer b(String s)=>sum(((any(s*.letter)then 11else 2)..36).map((r)=>parseInteger(s,r)else 0));
```
I first had this simpler version taking just 69 bytes:
```
Integer b(String s)=>sum((2..36).map((r)=>parseInteger(s,r)else 0));
```
But this fails with the first test case, returning `2000000000665` instead of `665`. ([The reason is that the `T` in `2T` is parsed as Tera, i.e. multiplies the 2 with 10^12, when the radix is 10.](https://github.com/ceylon/ceylon/issues/5796))
Therefore we need to catch this case separately. Thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil) for suggesting a different way of doing this which saved 4 bytes.
Formatted:
```
// Find sum of all possible base representations.
//
// Question:  https://codegolf.stackexchange.com/q/65748/2338
// My Answer: https://codegolf.stackexchange.com/a/65836/2338
Integer b(String s) =>
// take the sum of ...
        sum(
    // span from 2 to 36. (Though
    // if there are letters in there, we start at 11,
    // because the other ones can't be valid.
    // Also, parseInteger(s, 10) behaves a bit strange in Ceylon.)
    ((any(s*.letter) then 11 else 2) .. 36)
    // map each r of them to ...
        .map((r) =>
            // try parsing s as a number using base r
            parseInteger(s, r)
            // if that didn't succeed, use 0.
                    else 0
    )
);
```
[Answer]
# [K (ngn/k)](https://bitbucket.org/ngn/k), ~~38~~ 35 bytes
```
{+/t{y/x}/:(|/t:x+7*3>x-:55)_1+!36}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/Nqlpbv6S6Ur@iVt9Ko0a/xKpC21zL2K5C18rUVDPeUFvR2Kz2f5q6hpJRiJK1kqGBoRGQ8nD18fEP9w/ycQFyDJQ0/wMA "K (ngn/k) – Try It Online")
Takes capitalized input, e.g. "2T".
* `t:x+7*3>x-:55` map input from characters to 0..35, storing in `t`
* `(|/t...)_1+!36` identify the valid bases (those larger than the largest value in the input)
* `t{y/x}/:` convert `t`, interpreted as each valid base, to decimal
* `+/` take the sum and return
]