Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Created December 4, 2015 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninnypants/4d98406808bd234776f4 to your computer and use it in GitHub Desktop.
Save ninnypants/4d98406808bd234776f4 to your computer and use it in GitHub Desktop.
Solves Advent of code puzzle 4 though brute force. May output the solution to the first challenge multiple times.
<?php
$match5 = 0;
$match6 = 0;
$i = 0;
$salt = 'yzbqklnj';
while ( '000000' !== $match6 ) {
$i++;
$hash = md5( $salt . $i );
$match5 = substr( $hash, 0, 5 );
$match6 = substr( $hash, 0, 6 );
if ( '00000' === $match5 ) {
echo 'answer 1: ' . $i . "\n";
}
}
echo 'answer: ' . $i;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment