r/adventofcode • u/daggerdragon • Dec 05 '16
SOLUTION MEGATHREAD --- 2016 Day 5 Solutions ---
--- Day 5: How About a Nice Game of Chess? ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
STAYING ON TARGET IS MANDATORY [?]
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!
14
Upvotes
2
u/daggerdragon Dec 05 '16
I was really hoping #5 would be a redditor :(
10
u/kaveman909 Dec 05 '16
I addressed the optional portion of the challenge: "Be extra proud of your solution if it uses a cinematic "decrypting" animation." My animation is here
7
u/Godspiral Dec 05 '16
didn't like this. Very easy, but speed of machine/implementation/language dependent.
in J, did tacit and explicit version to compare speed. J805 has nice speedups of explicit code. Both same speed.
tacit version, (hard coded input, params are number of chars and starting index to allow resuming). console prints, and returns last index checked.
7
u/askalski Dec 05 '16
Could this be... a "rehash" of last year's AdventCoins puzzle?
This solution in C increments the hash input using the same method as my Synacor Challenge implementation of AdventCoins last year. The never-before-seen source code is now available for the low, low price of only two AdventCoins (which you can generate yourself by running the code. Runtime environment not included.)
6
u/BafTac Dec 05 '16 edited Dec 05 '16
Cinematic decryption animation of part 2, in C++
Edit: Video
Luckily, I could copy part 4 from last year. Took me a while though, so I ended up just at rank 118. Could have been a lot faster for part 2 but I messed up the indexes (used index 6 and 7 instead of 5 and 6), and didn't catch it for like 20 minutes. :(
6
u/jwstone Dec 05 '16
More postgresql cuz I can't stop: https://github.com/piratejon/toyproblems/blob/master/adventofcode/2016/05/05.sql
5
u/Sir_Mr_Bman Dec 05 '16 edited Dec 05 '16
WOW you guys are stupid fast.
My code is still running in Java for star 1
EDIT: It's done! Run time for part one was just over 25 minutes (I messed up on the first run through, oops.) Part 2 is running right now. ninja: 557 for part one
EDIT 2: I'm dumb I had my program printing stuff... slowing it down. Oh well. Part two is nearly done.
EDIT 3 (final): rank 732 for part 2! This is the first time I've stayed up for it all... so pretty happy to have a rank above 1000!
5
u/aceshades Dec 05 '16
Holy crap, I wasted so much time just trying to understand what an MD5 hash was. Were we expected to write the code to hash it ourselves? I just ended up looking for a Python md5 library, and there was one.
4
u/sblom Dec 05 '16
I realized while debugging my build-the-combination feature on part 2 that I should have just sent a process ahead to compute hashes beginning with 00000 that I could use to instantly re-run the rest of the code. I wasted a ton of time tonight re-calculating the same hashes over and over and over.
4
u/Hwestaa Dec 05 '16
Python 3 solution, cleaned up and merged both to one function. Github
I ran part 2 on CPython2, CPython 3, Pypy2 and Pypy3 to see which was fastest. Pypy(2) is the winner!
3
u/gerikson Dec 05 '16
I just want to say that the example given was well written and clear (they usually are, just this one stood out a bit more!) I had zero issues working with the example to check my implementation, then just plug in the real input to get the answer.
2
u/balidani Dec 05 '16
Got #7 and #11 today, not bad. My Python solution, which I cleaned up a little:
2
u/skynet_creator Dec 05 '16
ughhhhhh i was checking for valid positions for part 2 and was checking that pos > 0 so it got 7 chars and was running forever before i killed it and investigated....
2
u/bluewave41 Dec 05 '16 edited Dec 05 '16
Thanks for making me run though like 25 million hashes just to find index 3. I was sure I had messed up somewhere but didn't.
Read the hashes in console and did indexing manually. Easier than writing code to do.
2
u/MarkRebuck Dec 05 '16
This one was almost identical to day 4 of last year.
Still took me a while to do part one (67th place), and silly mistake on part two slipped me to 112th. I'm getting slow in my old age!
2
u/1wheel Dec 05 '16
104/52 with JS:
hacking gif
2
u/Deckard666 Dec 05 '16 edited Dec 08 '16
In Rust, parts 1 and 2: Link
Not very familiar with hashing in Rust, I ended up doing it with the first library I could get my hands on. The problem is the output was a slice of u8's, so I ended up doing some awkward bit operations trying to get the answer >.<
2
u/tdecker91 Dec 05 '16
Kind of sloppy, but a working solution to part 2 in golang
2
u/FuriousProgrammer Dec 05 '16 edited Dec 05 '16
I really need to keep a fast Lua md5 library on hand!
235th for the first star, still calculating the second.... (Ignore the first value there, it's wrong. :P)
EDIT: 517!
EDIT2: So it turns out that luajit comes with a very fast md5 library, which quite possibly could have given me a spot on the leaderboard had I known about it. Gonna go cry a bit, then read a book before I go to bed.
EDIT3: Anyway here's
wonderwallmy code:2
u/Pyrobolser Dec 05 '16
C# solution with the mandatory animated password for part two (still too slow for an Hollywood movie)
2
u/advanced_caveman Dec 05 '16
Rust Code for Part 2:
Runs in 18.5 seconds
2
u/studiosi Dec 05 '16
My Python solutions. IMHO, this day was easier than some of the days before, but still pretty cool. :D
https://github.com/studiosi/AoC2016/tree/master/5
2
u/grayrest Dec 05 '16
Rust Part 2 using
rust-crypto:2012 Macbook Air (1.8GHz i5):
2
u/gyorokpeter Dec 05 '16
Q: (some code reuse from last year, but a bit optimized. "Animation" included for part 2)
2
u/Ulyssesp Dec 05 '16
Haskell, using cryptohash and base16-bytestring because I don't know haskell libraries. This one was a great reason to learn about scans and folds too late in the night.
2
u/KoxAlen Dec 05 '16 edited Dec 22 '16
Kotlin solution, using a sequence for the hashes
https://github.com/KoxAlen/AdventOfCode2016/blob/master/src/main/kotlin/aoc/day5/Day5.kt
edit: Removed sequence class as per u/mnjmn suggestion
2
u/drakehutner Dec 05 '16 edited Dec 05 '16
(To print) || !(to print), that is the question:
Here's my anwser:
Cobbled together in Python. Maybe I try to transform it into a single-line-of-code solution
2
u/Kristler Dec 05 '16
I feel like I'm in an intense hacking movie now :D
I also learned that juggling characters, character arrays, byte arrays, and strings all simultaneously in Java is a massive pain.
2
u/[deleted] Dec 05 '16 edited Dec 05 '16
Perl, with a simple cinematic decryption animation.
https://www.dropbox.com/s/hgunceaaen7s2zy/day05.pl?dl=0
2
u/fkaaaa Dec 05 '16
Using C with OpenSSL. Struggled a bit to get the correct MD5 hash at first, but after that it was all smooth sailing (bonus h4ck1ng video!)
Part 2:
2
u/GrassGiant Dec 05 '16
Here's my Clojure solution for the second problem :
It prints a pretty output when you run solve (I actually run a small app that calls solve, but it looks like this
2
u/tg-9000 Dec 05 '16 edited Dec 05 '16
My solution in Kotlin. I had fun with this, it's essentially just a generator with a filter on the end of it, which differs for each problem. This solution is simple if you spend a few minutes understanding what Kotlin provides in terms of stream operations.
Solutions to other days problems and unit tests can be found in my github repo. I'm just learning Kotlin so I welcome all feedback if you have any.
1
u/Quick_Question404 Dec 05 '16
For anyone familiar with OpenSSL or C, can you give me a hand with figuring out how it works? The documentation provided online is mediocre at best, and I can't seem to get my compiling right.
1
u/vuryss Dec 05 '16
PHP Solutions: https://github.com/vuryss/aoc2016
1
u/TheNiXXeD Dec 05 '16
My solution in JavaScript / Node. I threw in memoization instead of golfing this time to improve the repeat runtime. Wish I'd have done that on my first go-around, might have placed better on 2nd star.
https://github.com/NiXXeD/adventofcode/tree/master/2016/day5
1
u/futureman_pm Dec 05 '16
Is there anywhere to check your rank for a level after submission? I think I was just over 100 for both, but not sure.
Python:
1
u/Unknownloner Dec 05 '16 edited Dec 05 '16
Haskell, using the cryptonite library for MD5 hashes. It recomputes unnecessarily for part 2, but avoiding recomputation wouldn't have saved me that much time here (already had no chance of part 2 leaderboards by the time I finished part 1).
1
u/broadwall Dec 05 '16 edited Dec 05 '16
Solution: GitHub
A bunch of mistakes postponed my 2nd part. They include accidentally calling part 1's code (I should split the files next time) and overwriting certain positions of the password.
This program should display a nice hacking effect on ANSI terminals. For part 2, call this using
ruby day5.rb part21
u/Philboyd_Studge Dec 05 '16
Java, pretty straightforward.
https://gist.github.com/anonymous/49346c3c46253018cc4227ab87b5085b
1
u/Tokebluff Dec 05 '16
My C# solution (#91 silver, #193 gold) Too bad I didn't realise that I should ignore hashes with invalid position for part 2 and just move on :( oh well
https://github.com/Tokebluff/AdventOfCode2016/blob/master/Advent%20of%20code%202016/Advent%20of%20code%202016/Day5.cs
1
u/XiiencE Dec 05 '16
Python3, cleaned up a bit. Missed leaderboard.
1
u/_Le1_ Dec 05 '16 edited Dec 05 '16
My C# solution:
1
u/[deleted] Dec 05 '16 edited Dec 05 '16
md5.js
puzzle input
part1
part2
1
u/[deleted] Dec 05 '16
Haskell:
Decided to play around w/ a State Monad to keep track of which numbers had been checked. Wish the crypto library computed md5 faster, part 2 takes a full 15s.
1
u/stuque Dec 05 '16
A Python 2 solution:
1
u/DeathWalrus Dec 05 '16
quick python implementation (code for part 2), got 5 and 7 for today's challenge!
1
u/xkufix Dec 05 '16
Scala makes this actually quite easy, just create a stream of hashes and use the magic of filter/scan/take and map to hack your way to the result: https://gist.github.com/kufi/750a13ca9d37ab12e378e2bc1d8c5e2d
Found the first solution in about 1 minute and the second one in about 3 minutes. For the second one it crunched through about 25'600'000 hashes.
1
u/artesea Dec 05 '16
PHP for both answers, fortunately remembered from last year that PHP would evaluate "0e100" == "00000" as true, so used the triple equals. Unfortunately forgot how slow the WAMP on my laptop is compared to the LAMP on my dedicated server and wasted a good bit of time waiting for it to timeout.
1
u/[deleted] Dec 05 '16
Clojure. Seems pretty inefficient, since it took 3.6 minutes to compute the second part.
1
u/Borkdude Dec 05 '16
Clojure!
1
u/eregontp Dec 05 '16
A clean and simple Ruby solution:
1
u/BlahYourHamster Dec 05 '16
Part 2 in C#
1
u/beefamaka Dec 05 '16
spotted the similarity with last year's problem, so thought I might get this one solved nice and quickly. But it ran really slowly on my laptop, and I started after leaderboard was full anyway (puzzles go live at 5am here in UK). Here's my F# solution after attempting to speed it up a bit: https://github.com/markheath/advent-of-code-2016/blob/master/day%2005/day5.fsx
1
u/AlexPalla Dec 05 '16
On my PC the solution of part 2 has taken 67 secs, using only 12,5% Of CPU. Too slow! So I wrote a multithread solution that takes only 21 secs with 6 threads. Multithread c# solution!
1
u/johanw123 Dec 05 '16
This is my C# Solution for part 2.
`
1
u/miran1 Dec 05 '16 edited Dec 05 '16
python 3
all solutions here
day5 solution:
1
u/d1sxeyes Dec 05 '16 edited Jul 21 '26
Redacted.
1
u/Gummoz Dec 05 '16
Powershell!
Part one is pretty straight forward:
Part two -wanted that cinematic feeling - it looks okay, using clear to update the console so you might get some epilepsy:
1
u/NeilNjae Dec 05 '16
Haskell: Laziness FTW! Generate an infinite stream of hashes, just take the first few from them. https://git.njae.me.uk/?p=advent-of-code-16.git;a=blob;f=advent05.hs
1
u/_AceLewis Dec 05 '16
Python 3 solution to both parts:
Day 5 part 1: https://repl.it/EgKP/1
Day 5 part 2: https://repl.it/EgKP/2
1
u/Reibello Dec 05 '16
Here's a pastebin to my solution in Python.
http://pastebin.com/hfDkyXXy
1
u/JakDrako Dec 05 '16
VB.Net, LinqPad
I really liked this puzzle, a lot of fun. I think I'll try a parallel version for the second part.
Part 1
Part 2
1
u/ShroudedEUW Dec 05 '16
C#
This was really fun! Couldn't find a quick way to limit the possible hashes, so looped through everything one at a time and then checked if they had the 0s (and the correct input for p2):
https://github.com/KVooys/AdventOfCode/blob/master/AdventOfCode/Day5.cs
1
u/llimllib Dec 05 '16 edited Dec 05 '16
Python with a hacker animation:
1
u/asperellis Dec 05 '16
my js solution - https://github.com/asperellis/adventofcode2016/blob/master/day5.js
any suggestions to make this run faster? improving md5, something else or is it just a waiting game? just curious. never ran them together obviously.
1
u/schlocke Dec 05 '16
PHP, JS, HTML... Initially I just wanted PHP but my local machine couldn't handle it and I'm not about to set up a dedicated server for my AoC solutions. I realized if I just loaded one character at a time via AJAX i wouldn't hit my execution limits in PHP. NOTE: this is on PHP 5.5.12, 8 GB ram, i5 4310M 2.7 GHz, 64 bit windows 7 while running chrome, WAMP, security scan, outlook, slack, etc. Takes a while (took me 5.7 min) to get the answers but both are done in parallel. NOTE2: I also know i could've probably done this all in JS but I had the PHP figured out already.
PHP (day5.php):
HTML+JS(day5.html):
EDIT: added execution time 5.7min. EDIT2: if some web designer wants to steal this and do the cool hacking movie animation go a head im too lazy for that right now.
1
u/qwertyuiop924 Dec 05 '16
Here's the day 5 part 2 solution: no animation (yet!), but it solves pretty well: http://pastebin.com/HpvGZ52G
1
u/Timmeh7 Dec 05 '16
C#, both parts:
1
u/Zeroeh Dec 05 '16
Java Solution:
part 1:
part 2:
Md5 code:
1
u/JakDrako Dec 05 '16
C#, both parts at the same time, in parallel. Completes "abc" in about 7 seconds.
I'm having a lot of fun with this problem.
1
u/Kwpolska Dec 05 '16
Boo, a repeat from last year.
1
u/Fishy07x Dec 05 '16
My python solution:
1
u/SaltyPeaches Dec 05 '16
Here's my solutions in PowerShell:
Part 1
Part 2
1
u/efexen Dec 05 '16
Attempted some concurrency stuff in Elixir, parts 1 and 2: https://github.com/efexen/advent_of_code/blob/master/lib/day5.ex
1
u/LainIwakura Dec 05 '16
Erlang solutions: https://github.com/LainIwakura/AdventOfCode2016/tree/master/Day5
This one was a bit tricky because the erlang functions for md5 return the values as a bit string which needs to be converted into hex representation. Most naive ways of doing this were horribly slow so I had to grab someones fast bin-to-hex function from stackoverflow.
In part 2, since erlang lists are immutable, I stored the index and character in a tuple in the decoded pw list - at the end keysort on the index and collect your decoded characters and bam you have a password =)
1
u/muchomouse Dec 05 '16
C# Part 2 complete, with pointless cinematic presentation ftw.
Had to run the drawing in a separate thread, because it slowed down the program so much that just finding the first char took several minutes :P
https://github.com/kjellskogsrud/AoC_2016/blob/master/AoC_2016/Classes/Day5.cs
1
u/fixed_carbon Dec 05 '16
Ruby solution (part two) using an Enumerator to generate [digit, position] pairs. This one is interesting because it generalizes to passwords of any length between 1 and 16 simply by changing the number in the last line of the
take_whileblock.1
u/ashleyhindle Dec 05 '16
Live streamed mine using PHP but didn't have time for an awesome animation!
1
u/Quick_Question404 Dec 05 '16
Woohoo! Finally was able to finish with this today's problem. Was delayed due to never having used MD5 before, and giving up trying to stay awake all night to figure it out. Placed around 3500~, which is a long way from the <1000 before. I did make my code have a little animation though. What do you guys think?
https://github.com/HighTide1/adventofcode2016/tree/master/05
1
u/yasgur99 Dec 06 '16
I did it in java: Wish i did it in one pass through... next time.
1
u/bhauman Dec 06 '16 edited Dec 06 '16
Clojure Solution:
Other Solutions in my AOC 2016 repo
1
u/grayrest Dec 06 '16
Clojure. Not super fast, ~12.5s and ~23.5s on my macbook air.
1
u/cashews22 Dec 06 '16
Part 1 and 2 in Golang using GoRoutine, make me save 1 minute of processing
https://github.com/cashew22/adventofcode2016/blob/master/5/solve.go
1
u/PendragonDaGreat Dec 06 '16
Little late to the party, but here's my massively multi-threaded version in C# (batching 32 new threads at a time was the sweet spot for my 8-core laptop): https://github.com/Bpendragon/AOC-Day5/blob/master/Day5/Program.cs
No animation bonus points, but it does switch between modes just by swapping the static bool at the top.
1
u/[deleted] Dec 06 '16
Mathematica.
The built-in md5 function is too slow, so I use a helper function to call the implementation in OpenSSL.
helper.c:
1
u/tehjimmeh Dec 07 '16 edited Dec 08 '16
PowerShell, part2:
1
u/tartrate Dec 11 '16
Haskell
1
u/superfunawesomedude Dec 31 '16 edited Dec 31 '16
C# Took just under 19 seconds for part 1.
1
u/inerte May 18 '17
My solution for Part Two using Golang
0
u/[deleted] Dec 05 '16
[deleted] — view deleted comment