Following on the previous challenge, I thought of doing a similar challenge but for multiplication.
Can you multiply 2 numbers without using the following operators and keywords?
Rules:
- Multiply a and b
- Don't use operators: +-*/
- Don't use keywords: for/while
Pseudocode:
a = 2
b = 32
multiply(a, b) => 64
Test:
multiply(a, b) == a * b
You can use any language you want, additionally you can add a note indicating which language it is, so people not familiar with the language can know!
That's all, have fun!!
My solution:
Top comments (8)
Nice! My version only works for positive integers. I'm not sure how to do it for floating point:
OK, this seems very silly, but worth a try. I think this works for floating point numbers:
Wow, how ugly xD I love it!!!! This is why I love putting this quirky little challenges out there!!
Nice solution, did not think of this one!!!! I also don't know how to make this solution work with floating points, seems nontrivial...
One liner 😉
Nice solution, this one wont work for floating point numbers right?
Sure, and it would be better not trying multiply(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER) :D
Basically a repost of my dangerous add 😋