r/adventofcode • • Dec 14 '16
Help How long does Day 14 take to run?
Mine has been running for so long...
4
Upvotes
r/adventofcode • • Dec 14 '16
Mine has been running for so long...
6
u/Unbelievr Dec 14 '16
Part 1 should be relatively quick, as MD5 is a fast hashing algorithm. Part 2 will be about 2016 times slower.
5
u/olivervscreeper Dec 14 '16
Interestingly, I was able to write my code in such a way that it was actually faster without an MD5 cache than with it, and noticeably so.
I basically loop through all indexes only once, and move hashes from potential hashes to resolved hashes as and when they meet the final condition later on. It runs in 50 seconds on my MacBook Pro 13" 2015, whereas with a cache takes upwards of four minutes as searching the cache increases the loop time.
You can see the code here if you're interested: https://github.com/oliverdunk/AdventOfCode/blob/master/src/main/java/com/oliverdunk/adventofcode/challenges/_2016/_2016Fourteen.java
3
u/askalski Dec 15 '16
Between 6-7 seconds in Perl, using
Inline::Cfor the Part 2 hash. The code.2
u/aurele Dec 14 '16
Here, in rust:
2
u/brantyr Dec 14 '16
Hint: If you find a triple 6 when you hash 'abc10', but no 66666 in the next 1000 hashes, then you find another triple at 'abc53', then one at 'abc321', how many times did you calculate hashes up to 'abc1010' looking for five-in-a-row to check those three potential keys?
Solution: spoiler, hover to read alt-text
2
u/__Abigail__ Dec 14 '16
Mine took about 40 seconds (doing both part1 and part2). I'm caching the hashes, and once I have the hashes, I'm extracting which characters are repeated 5 times, so I don't have to repeatedly search the string either. And I'm using a ring buffer -- no need to cache more than 1000 hashes.
2
u/SikhGamer Dec 15 '16
C# with a cache.
1
u/conscious_machine Dec 14 '16
Mine very inefficient JS solution took around 1-2 minutes for the second part on an old laptop. Maybe you are stuck in an infinite loop? Try printing out your progress every time you find a key.
1
u/[deleted] Dec 14 '16
Part 2 takes 42s in python with an animated spinner slowing it down.
1
u/lmbrj4ck Dec 14 '16
My Python solution takes about 100s on my Macbook Air (2013, Core i7 1.7ghz) and 30s on my regular computer (i7 4790k, 4.0ghz). Guess my implementation sucks.
Edit: These numbers are for part 2
1
u/Reibello Dec 14 '16
If you cache your hashes - it can be run in 30 seconds. My code runs in about 2-3 minutes with prints (I'm not as good as topaz). Do you have a github/pastebin for us to look at?
1
u/capJavert Dec 14 '16
~ 40 sec with caching of every md5x2017 hash
1
u/BadHorsemonkey Dec 14 '16
Too long!
I created a lookup table, stored every hash I made, wrote the if Hashs.containsKey(index) code in my hasher and forgot to put the create hash part in an else statement. So I looked it up and then re-calculated.
1
u/cashews22 Dec 14 '16
Part 1: 300ms Part 2: 13s
Golang https://github.com/cashew22/adventofcode2016/tree/master/14
1
u/doublehyphen Dec 14 '16
My Ruby implementations took 0.5 seconds for part 1 and 50 seconds for part 2 on a decent laptop.
1
u/razornfs Dec 14 '16
0.5s for part 1, about 30 seconds for part 2, in Java
1
u/blinky__ Dec 14 '16
<10s for both parts... after some fine-tuning :-)
1
u/desrtfx Dec 14 '16
Java on a Core i7, 16GB RAM, Lenovo ThinkPad W540
Code is not very optimized - no caching of the 2016 hashes between - only caching the final hashes - single threaded.
1
u/RodDylan Dec 14 '16
I'm new here :)
Interesting that many people are caching hashes.
My approach for part 1 was to store lists of potential keys, using potential[md[start]].append(index) (start being matched by the next two characters), and then checking for actual keys inside for hexdigit in hexdigits: if hexdigit * 5 in m.hexdigest(): (in the last 1000 potentials, obviously).
The outer loop terminates when I have 64 or more keys, which I then sort. For part 2, I never store more than two hexdigests, one im the form of a python hashlib.md5(), the other as the string that updates it. 53 seconds execution time, on my laptop (technically i7 hahahaha).
1
u/wzkx Dec 14 '16
CPU i7-6600U:
44.7s Python 3
6.03s GNU C
1
u/JakDrako Dec 15 '16
CPU: i7-5820K
C#, Part 1: 11ms; Part 2: ~10 seconds.
Multithreaded with custom managed MD5 implementation. Posted in the main solution thread.
1
u/SneakyB4stardSword Dec 15 '16
My attempts have been taking around 3720 seconds (an hour and 2 minutes) each, running on the repl.it python 3 interpreter (it's faster then running it in python 3.5 natively on my linuxed-out chromebook).
1
u/jwoLondon Dec 15 '16 edited Dec 15 '16
In Java it would appear the main bottleneck is converting the MD5 hash byte array to a hex string. Using String.format() is very slow (takes over a minute with caching). Using the fast hex conversion below, reduces time to about 12 seconds in total. Using this fast byte[] to hex, other factors such as caching or dictionary lookup of matched triplets etc. only makes a difference of a couple of seconds.
1
u/thomastc Dec 15 '16
Part 2 in under a second using OpenCL on a GeForce GTX 960, using MD5 code allegedly from the John The Ripper password cracker (source). My first time using OpenCL, so this can probably be improved.
1
u/BOT-Brad Dec 15 '16
JavaScript
P1: 521ms
P2: ~80 seconds
Using a cache. Part 2 is a lot quicker than I expected.
1
u/perfunction Dec 15 '16
I was able to get my part 2 time in Swift down to 27 seconds.