in reply to Odometer pattern iterator (in C). (Updated.)
sub increment_odometer { my @odometer = @_; my $wheel = $#odometer; # start at rightmost wheel until ($odometer[$wheel] < 9 || $wheel < 0) { $odometer[$wheel] = 0; $wheel--; # next wheel to the left } if ($wheel < 0) { return; # fell off the left end; no more sequences } else { $odometer[$wheel]++; # this wheel now turns one notch return @odometer; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Odometer pattern iterator (in C).
by BrowserUk (Patriarch) on May 29, 2015 at 11:55 UTC |