Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
3
Indexable
Never
# program using gumatj arithmetic
# xabiso spencer 
# 18 april 2022

def decimal_to_gumatj(dec):
    num = []
    gumatj = ""
    while(dec // 5 > 0):        #append array by divider
        num.append(dec % 5)
        dec = dec // 5
    num.append(dec)
    for i in num[::-1]:         #convert array to string
        gumatj += str(i)
    return int(gumatj)

def gumatj_to_decimal(gumatj):
    gumatj = str(gumatj)
    gumatj = gumatj[::-1]       #reverses string
    dec = []
    decimal_num = 0
    for i in range(len(gumatj)):    #converts by raising 5 to the power i
        dec.append((5**i)*int(gumatj[i]))

    for j in dec:
        decimal_num += int(j)
    return decimal_num

def gumatj_add(num1, num2):
    num1 = gumatj_to_decimal(num1)  
    num2 = gumatj_to_decimal(num2)  
    answer = num1 + num2
    return decimal_to_gumatj(answer)   #returns converted number

def gumatj_multiply(num1, num2):
    num1 = gumatj_to_decimal(num1)  
    num2 = gumatj_to_decimal(num2)  
    answer = num1*num2
    return decimal_to_gumatj(answer) #returns converted number