Click here to Skip to main content
15,901,122 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.

 
GeneralRe: Coding Challenge - Morris Sequence Pin
PIEBALDconsult30-Nov-17 13:20
mvePIEBALDconsult30-Nov-17 13:20 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland30-Nov-17 13:33
mvaKenneth Haugland30-Nov-17 13:33 
GeneralRe: Coding Challenge - Morris Sequence Pin
Dave Kreskowiak30-Nov-17 13:36
mveDave Kreskowiak30-Nov-17 13:36 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland30-Nov-17 17:04
mvaKenneth Haugland30-Nov-17 17:04 
JokeRe: Coding Challenge - Morris Sequence Pin
User 274316230-Nov-17 19:58
User 274316230-Nov-17 19:58 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland30-Nov-17 20:33
mvaKenneth Haugland30-Nov-17 20:33 
GeneralRe: Coding Challenge - Morris Sequence Pin
Dave Kreskowiak1-Dec-17 2:25
mveDave Kreskowiak1-Dec-17 2:25 
GeneralRe: Coding Challenge - Morris Sequence Pin
PeejayAdams30-Nov-17 23:58
PeejayAdams30-Nov-17 23:58 
Yes, these strings get huge, don't they? The whole thing really slows down in a very visible way once the lengths start to reach the 100,000s (40th iteration on) and gets ultra slow from there on in.

I'll leave mine running for a while and see exactly where it crashes and burns. Max chars for a StringBuilder are 2,147,483,647, I believe and it's clearly going to hit that at some point so I guess the true answer as you suggest involves hiving off the repeating elements.

My code (spectacularly Q&D C# - written on a whim in "do ... while" loops because someone recently said "for" loops are for dinosaurs) looks like this:
        static void Main(string[] args)
        {
            string result = ("1");

<pre>
        int i = 1;

        do
        {
            Console.WriteLine(i.ToString() + "\t" + result.Length.ToString());

            result = GetNextResult(result);
            i += 1;
        }
        while (i < 101);

        Console.ReadLine();

    }

    static string GetNextResult(string origin)
    {
        char character;
        int occurences;
        StringBuilder result = new StringBuilder();

        do
        {
            if (origin.Length == 0)
                break;

            ProcessNextGroup(origin, out character, out occurences);

            origin = origin.Substring(occurences);

            result.Append(occurences.ToString());
            result.Append(character.ToString());

            GC.Collect();

        }
        while (true);

        return result.ToString();

    }

    static void ProcessNextGroup(string sequence, out char character, out int occurences)
    {
        int index = 0;
        character = sequence[0];
        occurences = 1;

        do
        {
            if (++index > (sequence.Length -1))
                break;

            if (sequence[index] == character)
                occurences += 1;
            else
                break;
        }
        while (true);
    }
}</pre>
98.4% of statistics are made up on the spot.

GeneralRe: Coding Challenge - Morris Sequence Pin
Sascha Lefèvre1-Dec-17 0:37
professionalSascha Lefèvre1-Dec-17 0:37 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland1-Dec-17 0:50
mvaKenneth Haugland1-Dec-17 0:50 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland1-Dec-17 0:54
mvaKenneth Haugland1-Dec-17 0:54 
GeneralRe: Coding Challenge - Morris Sequence Pin
Dave Kreskowiak1-Dec-17 2:30
mveDave Kreskowiak1-Dec-17 2:30 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland1-Dec-17 2:46
mvaKenneth Haugland1-Dec-17 2:46 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland1-Dec-17 3:08
mvaKenneth Haugland1-Dec-17 3:08 
GeneralRe: Coding Challenge - Morris Sequence Pin
Dave Kreskowiak1-Dec-17 4:23
mveDave Kreskowiak1-Dec-17 4:23 
GeneralRe: Coding Challenge - Morris Sequence Pin
GuyThiebaut30-Nov-17 20:55
professionalGuyThiebaut30-Nov-17 20:55 
GeneralRe: Coding Challenge - Morris Sequence Pin
PIEBALDconsult1-Dec-17 2:41
mvePIEBALDconsult1-Dec-17 2:41 
GeneralRe: Coding Challenge - Morris Sequence Pin
Richard Deeming1-Dec-17 3:04
mveRichard Deeming1-Dec-17 3:04 
GeneralRe: Coding Challenge - Morris Sequence Pin
GuyThiebaut1-Dec-17 3:09
professionalGuyThiebaut1-Dec-17 3:09 
GeneralRe: Coding Challenge - Morris Sequence Pin
Richard Deeming1-Dec-17 3:21
mveRichard Deeming1-Dec-17 3:21 
GeneralRe: Coding Challenge - Morris Sequence Pin
GuyThiebaut1-Dec-17 3:29
professionalGuyThiebaut1-Dec-17 3:29 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland1-Dec-17 3:44
mvaKenneth Haugland1-Dec-17 3:44 
GeneralRe: Coding Challenge - Morris Sequence Pin
GuyThiebaut1-Dec-17 3:57
professionalGuyThiebaut1-Dec-17 3:57 
GeneralRe: Coding Challenge - Morris Sequence Pin
Kenneth Haugland1-Dec-17 4:02
mvaKenneth Haugland1-Dec-17 4:02 
GeneralRe: Coding Challenge - Morris Sequence Pin
Dave Kreskowiak1-Dec-17 4:14
mveDave Kreskowiak1-Dec-17 4:14 

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.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   501 votes