Click here to Skip to main content
15,890,438 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
JokeRe: If it's not one thing, it's another... Pin
phil.o25-May-16 22:17
professionalphil.o25-May-16 22:17 
GeneralRe: If it's not one thing, it's another... Pin
Brisingr Aerowing26-May-16 6:47
professionalBrisingr Aerowing26-May-16 6:47 
GeneralRe: If it's not one thing, it's another... Pin
#realJSOP26-May-16 1:23
mve#realJSOP26-May-16 1:23 
QuestionCoding puzzle Pin
virang_2125-May-16 13:32
virang_2125-May-16 13:32 
GeneralRe: Coding puzzle Pin
PIEBALDconsult25-May-16 13:56
mvePIEBALDconsult25-May-16 13:56 
AnswerRe: Coding puzzle Pin
ImHere2Learn25-May-16 18:49
professionalImHere2Learn25-May-16 18:49 
AnswerRe: Coding puzzle Pin
Staffan Bruun25-May-16 19:48
professionalStaffan Bruun25-May-16 19:48 
AnswerRe: Coding puzzle Pin
Staffan Bruun25-May-16 20:31
professionalStaffan Bruun25-May-16 20:31 
OK here is my improved solution, using Linq:

C#
using System;
using System.Collections.Generic;
using System.Linq;
					
public class Program
{
    public static void Main()
    {
        List<int> lstInput = new List<int>(){1,2,3,4,5,6,7,9,10,11,22};
		
        var aggResult = lstInput
	    .Aggregate(new 
            { 
                last = lstInput.First()-1, 
                result = new List<List<int>>(), 
                current = new List<int>()
            }, 
            (agg, n)=>
            {
                List<int> current = agg.current;

		if(n != agg.last + 1)
		{
		    agg.result.Add(current);
		    current = new List<int>();
		}

		current.Add(n);
				
                return new {last = n, result = agg.result, current};
	    });

        if(aggResult.current.Count > 0)
        {
            aggResult.result.Add(aggResult.current);
        }

        Console.Out.WriteLine(
            "{{{0}}}",
            string.Join(
                "},{", 
                aggResult.result.Select(o=>string.Join(",", o.Select(e=>e.ToString())))
            )
        );
    }
}


Not sure it's any more elegant, though... Sigh | :sigh:
GeneralRe: Coding puzzle Pin
Mycroft Holmes25-May-16 22:11
professionalMycroft Holmes25-May-16 22:11 
GeneralRe: Coding puzzle Pin
Staffan Bruun25-May-16 22:33
professionalStaffan Bruun25-May-16 22:33 
AnswerRe: Coding puzzle Pin
Kenneth Haugland25-May-16 21:45
mvaKenneth Haugland25-May-16 21:45 
AnswerRe: Coding puzzle Pin
Anthony Mushrow25-May-16 23:14
professionalAnthony Mushrow25-May-16 23:14 
GeneralRe: Coding puzzle Pin
virang_2126-May-16 13:01
virang_2126-May-16 13:01 
AnswerRe: Coding puzzle Pin
BillWoodruff25-May-16 23:48
professionalBillWoodruff25-May-16 23:48 
GeneralRe: Coding puzzle Pin
virang_2126-May-16 12:59
virang_2126-May-16 12:59 
AnswerRe: Coding puzzle Pin
Eytukan26-May-16 0:23
Eytukan26-May-16 0:23 
JokeRe: Coding puzzle Pin
Staffan Bruun26-May-16 3:10
professionalStaffan Bruun26-May-16 3:10 
AnswerRe: Coding puzzle Pin
PIEBALDconsult26-May-16 17:29
mvePIEBALDconsult26-May-16 17:29 
GeneralSalesForce Pin
Marc Clifton25-May-16 12:56
mvaMarc Clifton25-May-16 12:56 
GeneralRe: SalesForce Pin
Mark_Wallace25-May-16 13:16
Mark_Wallace25-May-16 13:16 
GeneralRe: SalesForce Pin
Marc Clifton25-May-16 13:23
mvaMarc Clifton25-May-16 13:23 
GeneralRe: SalesForce Pin
Mycroft Holmes25-May-16 14:25
professionalMycroft Holmes25-May-16 14:25 
GeneralRe: SalesForce Pin
Slacker00726-May-16 2:08
professionalSlacker00726-May-16 2:08 
GeneralAny ideas which app is free and best for running youtube and list in the background continuously Pin
indian14325-May-16 11:39
indian14325-May-16 11:39 
GeneralRe: Any ideas which app is free and best for running youtube and list in the background continuously Pin
Mark_Wallace25-May-16 12:06
Mark_Wallace25-May-16 12:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.