Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Handicapped Multiplication
- # This is a drill, just to cultivate creativity in programming practices, particularly algorithmic design.
- # There are more efficient ways to do multiplication in any language, so this function is not designed to be used elsewhere.
- # Objective: create a method for multiplying two integers using only the operators / and +
- function hm(x::Int64, y::Int64)
- s = 0
- while x > 0
- if isodd(x); s += y; end
- x = div(x, 2)
- y += y
- end
- return s
- end
- # Alternatively, the challenge could be modified so that the operators /n and *n are used, where n is an integer greater than 1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement