in reply to Inverted logic

Or, just count by 4s and 2s:

{ my $x; say for map { $x += $_ } 1,(4,2)x($LIM/6) }
1 5 7 11 13 17 19 . .

(At least 15x faster than your Grandma's best nested loop, too.)

Replies are listed 'Best First'.
Re^2: Inverted logic
by BrowserUk (Patriarch) on Jul 24, 2013 at 17:42 UTC

    Cool 'nall ++, but the real code does somewhat more than just printing a few numbers. (And the numbers aren't constant either.)

    The reason for refactoring is because I now want to do more than just next in that branch of the code.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      What? That was contrived? Next I was going to post say for 1,5,7 and call it a day. :-) I mean... understood. More of a fun reminder to never stop looking for ways to calculate rather than iterate, regardless of the problem.