On Sunday, 26 January 2014 at 13:05:55 UTC, Stanislav Blinov wrote:
On Sunday, 26 January 2014 at 12:50:05 UTC, matovitch wrote:
Hello !

I got a problem which I'm sure can be solved by a smart one liner. I would like to obtain the term by term product of a given range by the infinite cyclic range cycle([1,-1]). How can I do that ?

dpaste seems to be somewhat slow.

import std.range;
import std.algorithm;
import std.stdio;

void main() {

        auto myRange = iota(0,10);

        foreach(e; myRange.zip(cycle([1,-1])).map!(a => a[0]*a[1]))
                writeln(e);

}

Like this?

Exactly ! I just found this solution too. Thanks.

Reply via email to