Here's an implementation of multiplying two numbers using only subtraction in Go:
main.go189 chars12 lines
This function uses the Russian Peasant algorithm to determine the product of a and b. The algorithm reduces the multiplication to a series of additions and subtractions.
To use this function, simply call multiply(a, b), replacing a and b with the numbers you want to multiply.
gistlibby LogSnag