On Wednesday, 3 November 2021 at 00:50:51 UTC, Siarhei Siamashka wrote:

    !text.join("\n").writeln;

Ahem... You've turned a program that does not allocate to a program that allocates who knows how much memory?

And Ali... associative arrays? For this? What are you trying to teach the good beginner here? :D
```d
import std.stdio, std.algorithm;

void main()
{
  auto numbers = [-3, 14, 47, -49, -30, 15, 4, -82, 99, 26];
  char negativity, even;

write("Would you like in list (n=negatives, p=positives, b=both)? ");
  readf(" %c", &negativity);

  write("Would you like in list (e=evens, o=odds, b=both)? ");
  readf(" %c", &even);

  if ((negativity == 'b') && (even == 'b'))
  {
      // don't do any unnecessary work
      numbers.each!writeln;
  }
  else
  {
      numbers.filter!(x => !((negativity == 'n' && x > 0) ||
                             (negativity == 'p' && x < 0)))
             .filter!(x => !((even == 'e' && (x % 2)) ||
                             (even == 'o' && !(x % 2))))
             .each!writeln;
  }
}
```

Reply via email to