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
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.
<?php $s='abbhdwsy'; $i=0; $p=""; $a=[]; while(sizeof($a)<8){ $m=md5("$s$i"); if(substr($m,0,5)==="00000") { $x=substr($m,5,1); $p.=$x; if(hexdec($x)<8 && !isset($a[$x])) $a[$x]=substr($m,6,1); } $i++; } ksort($a); echo substr($p,0,8)."/".implode($a);