How to best translate this C++ algorithm into D?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 7 06:25:06 PDT 2014


On 06/07/2014 03:04 PM, logicchains wrote:
> ...
>
>   return map!(a => [forest_t(-1, -1, +1)+a, forest_t(-1, +1, -1)+a,
> forest_t(+1, -1, -1)+a])(forests)
>    .join
>    .partition!(forest_invalid)
>    .sort.uniq.array;


What about (untested)?:

static forest_t[] possible_meals = [{-1, -1, +1}, {-1, +1, -1}, {+1, -1, 
-1}];
return forests.map!(a=>possible_meals.map!(b=>b+a))
     .join.partition!forest_invalid.sort.uniq.array;

(Of course, this still allocates two arrays.)


More information about the Digitalmars-d mailing list