digitalmars.D.learn - Print a triangle
- Joel (12/12) Apr 29 2016 What is a quick way to print a triangle? I'm thinking without
- rikki cattermole (6/18) Apr 29 2016 Not entirely the goal I'm guessing output wise, but this works.
- Joel (3/8) Apr 29 2016 That is shorter than my foreach version, but I want one that
- Michael Coulombe (3/13) Apr 29 2016 Try this:
- Joel (4/6) Apr 29 2016 Yes, this is what I was looking for!
- H. S. Teoh via Digitalmars-d-learn (19/29) Apr 29 2016 Try this:
- H. S. Teoh via Digitalmars-d-learn (7/10) Apr 29 2016 [...]
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)) { } These don't work: iota(1, 10 + 1). string result; iota(1, 10 + 1). writeln(result);
Apr 29 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)) { } These don't work: iota(1, 10 + 1). string result; iota(1, 10 + 1). writeln(result);Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { }
Apr 29 2016
On Friday, 29 April 2016 at 11:31:51 UTC, rikki cattermole wrote:Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { }That is shorter than my foreach version, but I want one that doesn't use foreach in it at all.
Apr 29 2016
On Friday, 29 April 2016 at 12:01:19 UTC, Joel wrote:On Friday, 29 April 2016 at 11:31:51 UTC, rikki cattermole wrote:Try this:Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { }That is shorter than my foreach version, but I want one that doesn't use foreach in it at all.
Apr 29 2016
[snip] On Friday, 29 April 2016 at 13:20:47 UTC, Michael Coulombe wrote:Try this:Yes, this is what I was looking for! It's my birthday today.
Apr 29 2016
On Fri, Apr 29, 2016 at 12:01:19PM +0000, Joel via Digitalmars-d-learn wrote:On Friday, 29 April 2016 at 11:31:51 UTC, rikki cattermole wrote:Try this: auto triangle(int i) { import std.algorithm.iteration : map, joiner; import std.range : iota, repeat; import std.utf : byCodeUnit; // this is a hack .joiner("\n".byCodeUnit); } void main() { import std.stdio : writeln; writeln(triangle(10)); } Unfortunately, due to some silly autodecoding issues in Phobos, byCodeUnit is a necessary hack to make this work. I'll file a bug for this. T -- Today's society is one of specialization: as you grow, you learn more and more about less and less. Eventually, you know everything about nothing.Not entirely the goal I'm guessing output wise, but this works. import std.range : repeat; foreach(line; 1 .. 11) { }That is shorter than my foreach version, but I want one that doesn't use foreach in it at all.
Apr 29 2016
On Fri, Apr 29, 2016 at 11:45:39AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...]Unfortunately, due to some silly autodecoding issues in Phobos, byCodeUnit is a necessary hack to make this work. I'll file a bug for this.[...] https://issues.dlang.org/show_bug.cgi?id=15972 T -- Skill without imagination is craftsmanship and gives us many useful objects such as wickerwork picnic baskets. Imagination without skill gives us modern art. -- Tom Stoppard
Apr 29 2016