from https://theweeklychallenge.org/blog/perl-weekly-challenge-350/#TASK2
...
Example 1:
Input: $from = 1, $to = 1000, $count = 1 Output: 0 There are no shuffle pairs with elements less than 1000.
That's wrong since the rules explicitly allow A = B and k = 1.
Hence all integers belong to at least one shuffle pair. ²
> Further, as smarter guys explained, using modulo arithmetic voodoo, a lot of unfriendly numbers (which can't have any pals anyway) should simply be skipped;
Yes there are many possible filters to skip "unfriendly" integers which come to mind after excluding k=1.
But it would have been helpful if you expressed those rules in written words, instead of letting us reverse engineer them from your code.
Which seem to be based on the digit sum rules of integers divisible by 3 and 9.
For instance:
Since shuffling doesn't change the digit sum, B must also be divisible by 3 and 9 iff A is.
Hence all k from {3,6,9} can be excluded for As not divisible by 3, because B=A*k is.
Number theory is a bit strong a name, digit sum rules were already taught in elementary school.
¹) It's also unclear of digits can appear multiple times. All examples seem to indicate no. But those solutions exist, for instance if A and B are pairs, so are A.Õ and B.Õ with Õ being a sequence of 0 of arbitrary length.
²) I was wrong, see correction in choroba's reply.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
In reply to Re: Faster (but uglier) PWC 350-2 solutions
by LanX
in thread Faster (but uglier) PWC 350-2 solutions
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |