As usual the task is mathematically unclean and contradicts the example ¹

from https://theweeklychallenge.org/blog/perl-weekly-challenge-350/#TASK2

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.

update

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.

footnotes

¹) 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.