www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - ndslice help

reply Zz <Zz nospam.com> writes:
Hi,

I'm trying to generate the following sequences with ndslice.

0 0 0
1 1 1

1 1 1
0 0 0

0 1 2
0 1 2

2 1 0
2 1 0

It's okay with loops but was checking to see if it's possible 
with ndslice.

Zz
Feb 17 2016
parent reply ZombineDev <valid_email he.re> writes:
On Thursday, 18 February 2016 at 00:25:09 UTC, Zz wrote:
 Hi,

 I'm trying to generate the following sequences with ndslice.

 0 0 0
 1 1 1

 1 1 1
 0 0 0

 0 1 2
 0 1 2

 2 1 0
 2 1 0

 It's okay with loops but was checking to see if it's possible 
 with ndslice.

 Zz
Here's my solution: http://dpaste.dzfl.pl/29676608fd88 The best part about ndslice is that you can use the ordinary slice operations with it like: http://dlang.org/spec/arrays.html#array-copying, http://dlang.org/spec/arrays.html#array-setting, http://dlang.org/spec/arrays.html#array-operations, etc. and also leverage the existing ranges, range transformations and algorithms from http://dlang.org/phobos/std_range and http://dlang.org/phobos/std_algorithm. In addition, I used nested array formatting with http://dlang.org/phobos/std_format.
Feb 17 2016
parent Zz <Zz nospam.com> writes:
On Thursday, 18 February 2016 at 02:24:20 UTC, ZombineDev wrote:
 On Thursday, 18 February 2016 at 00:25:09 UTC, Zz wrote:
 Hi,

 I'm trying to generate the following sequences with ndslice.

 0 0 0
 1 1 1

 1 1 1
 0 0 0

 0 1 2
 0 1 2

 2 1 0
 2 1 0

 It's okay with loops but was checking to see if it's possible 
 with ndslice.

 Zz
Here's my solution: http://dpaste.dzfl.pl/29676608fd88 The best part about ndslice is that you can use the ordinary slice operations with it like: http://dlang.org/spec/arrays.html#array-copying, http://dlang.org/spec/arrays.html#array-setting, http://dlang.org/spec/arrays.html#array-operations, etc. and also leverage the existing ranges, range transformations and algorithms from http://dlang.org/phobos/std_range and http://dlang.org/phobos/std_algorithm. In addition, I used nested array formatting with http://dlang.org/phobos/std_format.
Thanks Zz
Feb 18 2016