# Base reduction

## Input

A positive integer:
```
0 < n < 1000000000
```

## Output

The end result of the base reduction.

If it cannot be fully reduced (reduced down to a single-digit number), return -1.

Assume that if 150 conversions from base 11 take place in a row, the number cannot be fully reduced.

## Description

Base reduction is a process where a number is inputted, repeatedly converted into another base, and then outputted if it cannot be reduced anymore. If it cannot be fully reduced, return -1.

During the base conversions, the number is converted from the lowest base it can be converted from into base 10. For example, 123 would be converted from base 4 to base 10, since base 4 is the lowest base that 123 can be in (123 base 3 is impossible; in base 3, there is no digit 3).

If the lowest possible base the number can be converted into is 10, convert the number from base 11 to base 10. For example, 53109 would be converted from base 11 to base 10, since base 10 is the lowest base it can be in.

In the end, you should get a number that cannot be reduced by this process (a single digit number).

## Example

Starting with 5312:
```
5312 base 6 = 1196 base 10
1196 base 11 = 1557 base 10
1557 base 8 = 879 base 10
879 base 11 = 1054 base 10
1054 base 6 = 250 base 10
250 base 6 = 102 base 10
102 base 3 = 11 base 10
11 base 2 = 3 base 10
```
The output would be 3.

Difficulty: introductory

Starter code:

def basereduct(x):
	

Solutions:
def basereduct(x):
    for _ in range(150):
        x = int(str(x), int(max(str(x))) + 1 + ('9' in str(x)))
        if x < 10: return x
    return -1

def basereduct(x):
    limit = x * 1000000
    while x >= 10 and x <= limit:
        s = str(x)
        base = int(max(s)) + 1
        x = int(s, 11 if base == 10 else base)
    return x if x < 10 else -1

def basereduct(x):
    for _ in range(150):        
        s = str(x)        
        x = int(s, max(int(c) for c in s) + 1 if '9' not in s else 11)
        if x < 10: return x
    return -1


def basereduct(x, f=0):
    s = str(x)
    if len(s) == 1:
        return x
    elif f == 150:
        return -1
    elif "9" in s:
        f += 1
        return basereduct(int(s, 11), f)
    else:
        return basereduct(int(s, int(max(s)) + 1), 0)

def basereduct(n):
    for _ in range(150):
        b = int(max(str(n))) + 1
        n = int(str(n), 11 if b==10 else b)
        if n < 10:
            return n
    return -1

def basereduct(x):
    c=0
    while(len(str(x))>1):
        b=max(map(int,str(x)))+1
        if b==10:
            b=11
        i=0
        n=0
        for d in str(x):
            n=n*b+int(d)
        x=n
        c+=1
        if c>150:
            return -1
    return x

def basereduct(x):
    s = str(x)
    b = 10
    m = max(list(s))
    if m == '9':
        b = 11
    else:
        b = int(m) + 1
    k = 0
    while len(s) > 1:
        t = int(s, b)
        s = str(t)
        m = max(list(s))
        if m == '9':
            b = 11
        else:
            b = int(m) + 1
        k += 1
        if k == 200:
            break
    if k == 200:
        return -1
    return int(s, b)


def basereduct(x):
    count = 0
    while x >= 10:
        if count == 150: return -1
        s = str(x)
        b = max(map(int, s)) + 1
        if b == 10: b, count = 11, count+1
        x = int(s, b)
    return x

def basereduct(n):
    base_numbers = {'0': 1, '1': 2, '2': 3, '3': 4, '4': 5, '5': 6, '6': 7, '7': 8, '8': 9, '9': 11}
    conversion = 0
    while len(str(n)) > 1:
        n = int(str(n), base_numbers[max(str(n))])
        conversion += 1
        if conversion > 150:
            return -1
    return n

def basereduct(x):
    count = 0
    while len(str(x)) > 1:
        base = max(int(i) for i in str(x))
        if base == 9:
            x = int(str(x), 11)
        else:
            x = int(str(x), base + 1)
        count += 1
        if count >= 150:
            return -1
    return x