in reply to Re: How to get this not the usual round robin looping
in thread How to get this not the usual round robin looping

chapeau for your solutions, but while i was reading them to appreciate how bad i was to not studied math (quite at all), i realized that your two push lines work only for 0 to 3. has your math solution the possibility to abstract this and using the index of a variable @K?

thanks
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: How to get this not the usual round robin looping
by hdb (Monsignor) on Oct 14, 2015 at 08:47 UTC

    Well spotted! Right now I cannot think of something as terse as this for the general solution. The $i&4 basically tells the ups and downs and would need to be replaced by something like int($i/@K)&1 (not tested). The line based on sin will not work for large arrays @K as sin is not linear enough for that...

    Update: This should work:

    push @{ $hash{ $K[ int(++$i/@K)&1 ? @K-1-$i%@K : $i%@K ] } }, $_ for @ +V;