Using loop print the following output on console.
1
121
12321
1234321
123454321
1234321
12321
121
1
hxn xfir 0 Newbie Poster
Recommended Answers
Jump to PostWell I've just done it for fun, was interesting. My code is probably messy but oh well!
Show us what you have done and we can help.
Jump to PostThinking about it, I believe this might be possible in a single statement. Bonus points if you can do it...
Jump to PostOf course we cannot forget to thank the teacher or whomever of hxn xfir for providing us, bored at work, with this now fun little competition.
I need to tidy my code up a bit and rethink my logic clearly!
Jump to PostI cheated slightly...But here's a one liner :)
using System; using System.Linq; namespace OneLineTest { class Program { static void Main(string[] args) { Enumerable.Range(1,5).Select(x => new string('1', x)).Concat(Enumerable.Range(1,4).Reverse().Select(x => new string('1', x))).Select(int.Parse).ToList().ForEach(y => Console.WriteLine("{0,9}", y*y)); Console.ReadKey(); } } }
It could probably be optimised and I …
Jump to PostOkay, so the
Enumerable.Range(start, count)
generates a sequence of numbers. When you do the select on this it will perform the lambda of the select for each number in the sequence. I'm not really that interested in the number that the Enumerable outputs, that's a means to an end. …
All 33 Replies
JOSheaIV 119 C# Addict
Mike Askew 131 Veteran Poster Featured Poster
ddanbe commented: naughty! ;) +15
JOSheaIV 119 C# Addict
castajiz_2 35 Posting Whiz
Ketsuekiame 860 Master Poster Featured Poster
castajiz_2 35 Posting Whiz
Ketsuekiame 860 Master Poster Featured Poster
castajiz_2 35 Posting Whiz
Ketsuekiame 860 Master Poster Featured Poster
JOSheaIV 119 C# Addict
Ketsuekiame 860 Master Poster Featured Poster
Mike Askew commented: Please deliver, we await. +7
Mike Askew 131 Veteran Poster Featured Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
castajiz_2 commented: you are always neat with your code (reffering to the const) +3
castajiz_2 35 Posting Whiz
JOSheaIV 119 C# Addict
Mike Askew 131 Veteran Poster Featured Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
castajiz_2 commented: definitly agree +0
JOSheaIV 119 C# Addict
ddanbe commented: Congrats! +15
Ketsuekiame 860 Master Poster Featured Poster
castajiz_2 commented: i can t wait to see your code, though i don t want to put any pressure, just post it when you r done with it +3
Fenrir() 52 Newbie Poster
ddanbe commented: NIce addition to this collection! +15
Ketsuekiame 860 Master Poster Featured Poster
ddanbe commented: Knowledge of LINQ too limited? :) +15
JOSheaIV 119 C# Addict
ddanbe 2,724 Professional Procrastinator Featured Poster
Ketsuekiame 860 Master Poster Featured Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
Venjense 2 Light Poster
ddanbe 2,724 Professional Procrastinator Featured Poster
kplcjl 17 Junior Poster
kplcjl 17 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.