in reply to What am I missing?
This part:
foreach $i (@f) { @e = grep {$_ % $i != 0} @n; @n = (); @n = @e; }
could be shortened as:
foreach $i (@f) { @n = grep {$_ % $i != 0} @n; }
without making it less readable.
The problem in your implementation is that you take off @n every multiple of $i, including $i! Try:
foreach $i (@f) { @n = grep {$_ % $i != 0 || $_ == $i} @n; }
Updated: jwkrahn is right, this @n = grep {$_ % $i != 0} @n foreach $i (@f); would not work.
Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: What am I missing?
by jwkrahn (Abbot) on Aug 11, 2009 at 06:17 UTC |