r/adventofcode • • Dec 05 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 5 Solutions -๐ŸŽ„-

--- Day 5: A Maze of Twisty Trampolines, All Alike ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

22 Upvotes

403 comments sorted by

View all comments

Show parent comment

2

u/the4ner Dec 05 '17 edited Dec 05 '17

trivial c# solution takes ~150ms for part 2 on an 8 year old i7

2

u/ka-splam Dec 05 '17

PowerShell is a .Net language, same int and array datatypes, I'm amazed the loop is that much slower. I ported mine to Python to try it on my user-specific input and it was (handwavingly) under 20 seconds.

Guess I know what language I should aim for tomorrow :)

2

u/artemis_from_space Dec 05 '17

Weird, using your code in Measure-Command I get 11 seconds 670 ms. 2.3ghz i7

1

u/ka-splam Dec 05 '17

Intresting - I tried it on a 2.3Ghz i7 and a 2.6Ghz Xeon, and I do see the speedup using Python. Because the input to the puzzle is different for each user - would you mind running against my input, please? https://gist.github.com/anonymous/fb9b57bed3bfe74ef9d6db8bede519a6 - it should do about 28 million steps for part 2, I think.

1

u/ka-splam Dec 06 '17

Found why - making it a script or function causes it to be JIT compiled, but just running the code in ISE is like typing it in and that gets interpreted ( source: Don Jones )

2

u/KeinZantezuken Dec 05 '17

What CPU? Getting ~300ms here on Core i7 3770k

1

u/the4ner Dec 05 '17

i7 920 with a hefty overclock (3.7ghz) that is probably be helping

1

u/the4ner Dec 05 '17

/u/KeinZantezuken went back and checked - yours should definitely be faster as your stock clocks are higher than my overclock. are you iterating a list or an array? the latter will be faster.

1

u/KeinZantezuken Dec 05 '17
        var input = File.ReadAllLines(@"N:\input.txt").Select(x => Convert.ToInt16(x)).ToArray();
        var steps = 0; var pos = 0;
        var watch = new Stopwatch();
        watch.Start();
        while (pos < input.Length && pos >= 0)
        {
            steps++;
            pos = input[pos] >= 3 ? pos + input[pos]-- : pos + input[pos]++;
        }
        //Console.WriteLine(steps);
        watch.Stop();
        Console.WriteLine(watch.Elapsed);
        Console.ReadKey();

I can store input.Length but gain will be superficial