
# change a given number to base 10 (returns int)
def denary(value, base):
    result = 0
    for i, digit in enumerate(reversed(value)):
        result = result + int(digit)*(base**i)
    return result

# change a given number to base 3 (returns str)
def ternary(value, base):
    if base != 10:
        value = denary(str(value), base)

    result = ""
    while value:
        result = str(value % 3) + result
        value = value // 3

    return result

# pads a gene string with leading zeros
def pad(value, length):
    while len(value) < length:
        value = "0" + value
    return value


# change a given number to base 10 (returns int)
def denary(value, base):
    result = 0
    for i, digit in enumerate(reversed(value)):
        result = result + int(digit)*(base**i)
    return result

# change a given number to base 3 (returns str)
def ternary(value, base):
    if base != 10:
        value = denary(str(value), base)

    result = ""
    while value:
        result = str(value % 3) + result
        value = value // 3

    return result

# pads a gene string with leading zeros
def pad(value, length):
    while len(value) < length:
        value = "0" + value
    return value

# change a given number to base 10 (returns int) # change a given number to base 3 (returns str) # pads a gene string with leading zeros