Comma quibbling a la Eric and Jafar [A slightly wacky approach to the problem in C#]

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of

See you there!

Comments (3)
  1. says:

    Easy to fix, you always have to loop through it once anyways so…

    input = input.ToArray();

    in the beginning of the method.

  2. David Anson says:


    You’re right – that would be an improvement. However, Jafar and I were both coming at this problem from the direction of specifically NOT forcing the entire list to live in memory at once (as .ToArray will do). The reasons for avoiding this are pretty weak in this specific case because we’re building up a string of each of those array elements anyway, but in general you can see significant memory benefits from NOT realizing an entire array and instead processing the elements as you need them. As I point out, my solution loses because it walks those elements three times – but if I’d managed to come up with a short, elegant way of creating those 3 Enumerators in such a way that the stream was traversed only once, I’d have solved both problems. And while I could write that code pretty easily, it added too much to what was supposed to be a simple solution, so I wimped out and didn’t… 🙂

    Thanks for the feedback!!

  3. Jimmy May says:

    I appreciate your thoughtful optimization, David.  Such efficiencies translate to performant, scalable code.  Well done!

Comments are closed.

Skip to main content