def multiplyListsReturnList(listA,listB): a = list(listA) b = (listB) s = [] n = len(a) if len(b) > n: n = len(b) helper.prependZeros(a,n) helper.prependZeros(b,n) position = 0 b.reverse() for i in range(n): partial = multiplyOne.multiplyOneListsReturnList(a,[b[i]]) partial.reverse() adjustmentForBase = len(helper.numberToList(helper.listToNumber(partial))) + position helper.prependZeros(partial, adjustmentForBase) partial.reverse() s = addition.addListsReturnList(s,partial) position = position + 1 return s
def addListsReturnList(listA, listB): a = list(listA) b = list(listB) c = [0] s = [] n = len(a) if len(b) > n: n = len(b) helper.prependZeros(a, n + 1) helper.prependZeros(b, n + 1) a.reverse() b.reverse() for i in range(n + 1): nSum = a[i] + b[i] + c[i] nSumList = helper.numberToList(nSum) helper.prependZeros(nSumList, 2) s.append(nSumList[1]) c.append(nSumList[0]) s.reverse() return s
def multiplyOneListsReturnList(listA,listB): a = list(listA) b = list(listB) if len(b)!= 1: return None n = len(a) c = [0] d = [] a.reverse() for i in range(n): cAndDNum = a[i] * b[0] cAndD = helper.numberToList(cAndDNum) helper.prependZeros(cAndD,2) c.append(cAndD[0]) d.append(cAndD[1]) c.reverse() d.reverse() return addition.addListsReturnList(c,d)
def addNumbersReturnNumber(a, b): aList = helper.numberToList(a) bList = helper.numberToList(b) sList = addListsReturnList(aList, bList) return helper.listToNumber(sList)
def addNumbersReturnList(a, b): aList = helper.numberToList(a) bList = helper.numberToList(b) return addListsReturnList(aList, bList)