Print a triangle

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 29 04:31:51 PDT 2016


On 29/04/2016 11:23 PM, Joel wrote:
> What is a quick way to print a triangle? I'm thinking without foreach,
> not like I have here.
>
> foreach(line; iota(1, 10 + 1)) {
>     writeln("#".replicate(line));
> }
>
> These don't work:
>
> iota(1, 10 + 1).
> tee!((a) => { writeln("#".replicate(a)); });
>
> string result;
> iota(1, 10 + 1).
> tee!((a) => result ~= "#".replicate(a) ~ "\n");
> writeln(result);

Not entirely the goal I'm guessing output wise, but this works.

import std.range : repeat;
foreach(line; 1 .. 11) {
	writeln('#'.repeat(line));
}



More information about the Digitalmars-d-learn mailing list