Do you know where your variables are? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I'd try a branch and bound, starting with i and trying out values for the digits of the other multiplicand from right to left.
Each digit to the right determines another one to the left. Whenever a digit gets repeated you bound. Taking your decimal case: > abcd = efgh * i
°) obviously you can only use 1 when the last multiplication had a carry digit (denoted in brackets) ²) multiplying an even number with 5 will always lead to 0 and multiplying an even number with 6 will always repeat that number ³) the last multiplication in a system with even numbered digits can't have a carry digit I did this by hand to find some rules to effectively cut down the possibilities of a branch and bound. Rule 2 means you'll can eliminate all n * (n-1) possibilities where the product repeats one of the factors or lead to 0. For instance in a decimal system i can't possibly ever be 5 or 6. (just prepare a multiplication table for an n-system to eliminate these cases) Footnote °) is just a special case of rule 2 Rule 3 means anything i must be < n/2 for n even like the decimal with n=10) and i >= n/2 for n odd. That is in the decimal case i can only be 2, 3 or 4 These are massive reductions of all possibilities, far more efficient than calculating all k-permutations. I'm only wondering if it's more efficient to start trying from right to left starting with h or even from left to right starting with e or even combining both possibilities. for instance these are the only possible combinations of i and e for n=10
And the cases I marked with a # mean that the value for f must lead to a carry digit to alter a. This seems to reduce possible branches very quickly!!! I hope I gave you some good ideas for the case n=10 which can be generalized for bigger n.
Cheers Rolf
In reply to Re: Efficient enumeration of pandigital fractions
by LanX
|
|