in reply to Faster (but uglier) PWC 350-2 solutions
and tries to limit the ops executed in the loop body. To take advantage of other witness elimination, you'd unwrap the outer loop and have special code for e.g multiples of 3, but that if a lot of duplication. You'd get a much better speed bump using Inline for at least the "does it have the same digits" check. My go solution is much much faster. But all the conversions from numbers to strings to runes make it a lot longer.for my $witness (2..int((10**length($i) - 1) / $i)) { if ($i_sorted eq join '', sort split //, $i * $witness) { if (++$pairs == $count) { ++$qualifying_integers; next I; } } } # maximum witness can't be more than i's first digit for my $witness (2..substr $i, 0, 1) { if (!( $i % $witness ) && $i_sorted eq join '', sort split + //, $i / $witness) { if (++$pairs == $count) { ++$qualifying_integers; next I; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Faster (but uglier) PWC 350-2 solutions
by Anonymous Monk on Dec 10, 2025 at 16:01 UTC | |
|
Re^2: Faster (but uglier) PWC 350-2 solutions
by LanX (Saint) on Dec 10, 2025 at 00:09 UTC | |
by ysth (Canon) on Dec 10, 2025 at 00:46 UTC | |
by LanX (Saint) on Dec 10, 2025 at 02:05 UTC | |
|
Re^2: Faster (but uglier) PWC 350-2 solutions
by Anonymous Monk on Dec 10, 2025 at 18:19 UTC | |
|
Re^2: Faster (but uglier) PWC 350-2 solutions
by Anonymous Monk on Dec 09, 2025 at 23:12 UTC | |
by ysth (Canon) on Dec 09, 2025 at 23:42 UTC | |
by Anonymous Monk on Dec 10, 2025 at 10:11 UTC |