News for hackers. Stuff that matters.
Re:Divisible by 7 (2016) by meiji163 on Thursday May 20, 2021 @03:01PM (#27225587)
Here's a way I do it in my head: For every block of six digits "fedcba" calculate (a-d)+3(b-e)+2(c-f). The number is divisible by 7 if the sum is divisible by 7. Fun thing is you know any number with digits "abcabc" is divisible by 7.
Re:Divisible by 7 (2016) by Someone on Thursday May 20, 2021 @07:34PM (#27228783)
We have

  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.
Re:Divisible by 7 (2016) by Traster on Thursday May 20, 2021 @03:47PM (#27226173)
I'm kind of more intersted in why you know this. There's lots of weird esoteric stuff that I know that I need as part of my job, but what are you doing that requires you to know this that isn't "copy paste this number into a python notebook"?

Oh and if you are copy pasting into notebook, then x %7 == 0 probably is a reasonable substitute...

Re:Divisible by 7 (2016) by lurquer on Thursday May 20, 2021 @04:30PM (#27226790)
I can’t speak for the poster, but I learned that trick (and many others) to play a game while stuck in traffic. Namely, derive the prime factorization of the license plate number in front of you before you lose sight of it. (Usually a 5 digit number in my area.)

Sort of silly, but it passes the time.

Re:Divisible by 7 (2016) by tashi on Thursday May 20, 2021 @07:44PM (#27228869)
I test numbers for divisibility by 7 in my head almost every time I do a daily KenKen puzzle. There's usually a four or five-digit number in there whose factors I don't know off the top of my head, so I'll give it a quick check for sevens just to get my bearings.

But a python notebook could definitely beat me in a race.

Re:Divisible by 7 (2016) by meiji163 on Thursday May 20, 2021 @07:26PM (#27228728)
It's just the fact that 1, 10, 100, 1000, ... = 1, 3, 2, -1, -3, -2, ... (repeating) mod 7
Re:Divisible by 7 (2016) by jldugger on Thursday May 20, 2021 @05:02PM (#27227208)
I mean, who isn't loading their Anki decks with random mental math party tricks?
Re:Divisible by 7 (2016) by Andy_G11 on Thursday May 20, 2021 @03:26PM (#27225869)
Is this only for numbers where the number of digits is a multiple of 6?
Re:Divisible by 7 (2016) by Robin_Message on Thursday May 20, 2021 @03:39PM (#27226079)
Left pad with zeros