Divisible by 7 (2016)
wiki.tcl-lang.org
wiki.tcl-lang.org
- Divisibility by 7, 11, 13: https://www.johndcook.com/blog/2020/11/10/test-for-divisibil...
- Divisibility by any prime using determinants: https://www.johndcook.com/blog/2021/02/17/divisibility-by-an...
> How does it work? Here's a hint: the white arrows correspond to 10x mod 7.
(which of course is the same as 3x mod 7), it seems that the author intentionally wants to leave it as a slight puzzle. But blacksqr's suggestion (https://news.ycombinator.com/item?id=27222819) to write it yourself is even better!
Oh and if you are copy pasting into notebook, then x %7 == 0 probably is a reasonable substitute...
Sort of silly, but it passes the time.
But a python notebook could definitely beat me in a race.
abcabc = 1001 × abc = 7 × 11 × 13 × abc
so abcabc also is divisible by 11 and 13.That also means that, to check divisibility of abcdef by 7, 11, or 13, compute |def-abc| and check whether that is divisible by 7, 11, or 13 since
abcdef = abcabc + (def - abc) = defdef + 1000 × (abc-def)
Similarly, since 10001 = 73 × 137, abcdabcd always is divisible by 73 and 137.A number in base $n$ is just $a*n^2+b*n^1+c$.
Because $n mod n-1 = 1$, you can replace every $n$ with $1$.
So $a*n^2+b*n^1+c mod n-1$ becomes $a+b+c mod n-1$
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...
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.
Impressive and novel, but not that easy to remember.