Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Peano style solution in Scary category for Multiply (Intro) by PythonWithPI
# This is one of the least efficient ways I can think of to multiply two numbers
# I can use Peano arithmatic style recursion to define addition and then multiplication
def suc(n):
'successor function'
return n + 1
def add(a, b):
if b == 0:
return a
else:
return suc(add(a, b - 1))
def mul(a, b):
if b == 0:
return 0
else:
return add(a, mul(a, b - 1))
mult_two = mul
# I think this supports products about up to the recurison limit, but after that
# it causes a stack overflow
May 6, 2019
Comments: