this post was submitted on 22 Nov 2024
8 points (90.0% liked)
math
828 readers
1 users here now
General community for all things mathematics on @lemmy.world
Submit link and text posts about anything at all related to mathematics.
Questions about mathematical topics are allowed, but NO HOMEWORK HELP. Communities for general math and homework help should be firmly delineated just as they were on reddit.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I wrote some terrible python code to search divisibility rules for a given number and it tests example product divisibility
Edit2: https://pastebin.com/Dkbq2chV Yet another revision, I got caught up in this project but I think it has enough features now. I added few command line options and details you can edit in the script.
I need to stop before I add more features. Here's example output:
I bet I could make your code 40,832,277,770% faster.
Funnily enough, I just sped up my own solution by 25000% without compromising anything.
https://pastebin.com/Dkbq2chV
I realized that multiplying the divisor P by its non-zero reciprocal digits, gets you near 10^n which are ideal numbers for the divisibility rules. Which should have been obvious since
n * (1/n) = 1
, and cutting off the reciprocal results in approximation of 1, which can be scaled by 10^b.e.g. finding divisibility rules for 7
The first script was very naive brute force approach.
So instead of searching every combination of a, b and c, I can just check the near multiples of
P*reciprocal
.The variables can be solved by
P*N = a*10^b + c
when b is given and a is 1 to 97*1429=10003
would expand toP*N=1*10^4+3
It appears to always run in ~30 milliseconds regardless of the tested number, so this might be O(1) until some bottleneck kicks in. Though I have yet to verify the complexity as the quality of division rule depends on a,b and c ranges.
Edit: after some testing it's some logarithmic complexity when P is bigger than 10^2000
Plotting these gave about O(log(P)^2.5)
The bRange, math.gcd() and reciprocal scale with P digit count but rest of the calculations are O(1).
I have no idea why you would need 10^8000 divisibility rule designed hand calculations, but you can get one under a minute and this isn't even multithreaded!