Alternate signs in a range

matovitch camille.brugel at laposte.net
Sun Jan 26 05:08:39 PST 2014


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.


More information about the Digitalmars-d-learn mailing list