Re:Divisible by 7 (2016)
by holistio on Thursday May 20, 2021 @01:19PM
(#27224050)
Clever and all, but I still actually divide faster than using this mechanism.
[ Parent
| on HN ]
You divide faster thanks to your language interpreters and compilers implementing thousands of algorithms like this which convert between arithmetic operations so you can have that speed. For example sometimes when you divide by specific numbers in C it gets compiled to equivalent multiplication and addition.
Your comment reminds me of this other thread, where people were bragging they could implement curl in a few lines of Python code, by first including a CURL-like module...
I'm fairly sure holistio means doing a long division using pen and paper, or even off the top of their head.
Here’s a cool video that shows how compilers optimize exponentiation[1].
It seems like a really simple problem on the surface (x^3? Just do xxx), but lots of smart people have thought hard about the best way to do it for any arbitrary exponent.
For example, x^15 only needs 5 multiplication instructions.