laziness, impatience, and hubris PerlMonks

### comment on

 Need Help??
If the solution in my earlier node doesn't return what you want, this surely will:
use Math::BigInt (); *gcd = \&Math::BigInt::bgcd; sub embiggen { local \$_ = @_ ? \$_[0] : \$_; return Math::BigInt->new(\$_); } my @a = ( 10, 20, 33, 45, 60 ); my @b = ( 2, 5, 10, 12, 16, 23, 45 ); # my %a = map { \$_ => 1 } @a; # my %b = map { \$_ => 1 } @b; # # my @c = map embiggen, # grep { !\$b{\$_} } # @a; # # my @d = map embiggen, # map { Math::BigInt->new(\$_) } # grep { !\$a{\$_} } # @b; my @c = @a; my @d = @b; foreach my \$c (@c) { foreach my \$d (@d) { my \$gcd = gcd(\$c, \$d); \$c /= \$gcd; \$d /= \$gcd; } } @c = grep { \$_ != 1 } @c; @d = grep { \$_ != 1 } @d;
or this messier but potentially faster alternative:
use Math::BigInt (); use Math::Big::Factors (); *gcd = \&Math::BigInt::bgcd; *factor = \&Math::Big::Factors::factors_wheel; sub embiggen { local \$_ = @_ ? \$_[0] : \$_; return Math::BigInt->new(\$_); } my @a = ( 10, 20, 33, 45, 60 ); my @b = ( 2, 5, 10, 12, 16, 23, 45 ); # my %a = map { \$_ => 1 } @a; # my %b = map { \$_ => 1 } @b; # # my @c = map embiggen, # grep { !\$b{\$_} } # @a; # # my @d = map embiggen, # grep { !\$a{\$_} } # @b; my @c = @a; my @d = @b; my %c_factors; foreach my \$c_idx (0..\$#c) { my @c_factors = factor(\$c[\$c_idx]); foreach my \$c_factor (@c_factors) { push(@{\$c_factors{\$c_factor}}, \$c_idx); } } foreach my \$d (@d) { my @d_factors = factor(\$d); foreach my \$d_factor (@d_factors) { next unless \$c_factors{\$d}; next unless @{\$c_factors{\$d}}; my \$c_idx = shift(@{\$c_factors{\$d}}); \$c[\$c_idx] /= \$d_factor; \$d /= \$d_factor; } } @c = grep { \$_ != 1 } @c; @d = grep { \$_ != 1 } @d;
Both untested.
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.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, 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: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-02-27 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What numbers are you going to focus on primarily in 2020?

Results (120 votes). Check out past polls.

Notices?