What is shortest in code terms way for given N (int) to output List<strings> out;
containing strings "1", "1 2"... "1 2 ... N"
? For N == 3 out
would contain "1"; "1 2"; "1 2 3"
Asked
Active
Viewed 90 times
-5

DuckQueen
- 772
- 10
- 62
- 134
-
7Show or tell us what have you tried and what problem do you have as SO is not "write me some code" portal. – Konrad Kokosa Dec 18 '13 at 15:12
-
It's very hard to be sure of such a thing as having reached the shortest possible code. – Jonas Elfström Dec 18 '13 at 15:13
-
2I suggest writing a method that does what you want, and naming it `A`. The shortest possible call to get the desired results will then be `A();`. – O. R. Mapper Dec 18 '13 at 15:14
-
Try http://codegolf.stackexchange.com/ – Ian Nelson Dec 18 '13 at 15:14
1 Answers
3
Enumerable.Range(1, n)
.Select(i => String.Join(" ", Enumerable.Range(1, i)))
.ToList();
For n = 3 produces:
[
"1",
"1 2",
"1 2 3"
]

Sergey Berezovskiy
- 232,247
- 41
- 429
- 459
-
5Sorry all, I understand that question is of low-quality, but it was interesting to try – Sergey Berezovskiy Dec 18 '13 at 15:16