Day 4 solution.

This commit is contained in:
Dan Chadwick
2024-11-24 19:29:04 -05:00
parent 674175c5ea
commit d17bf4218b
2 changed files with 23 additions and 0 deletions

21
2015/days/day4.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
function day4(int $part = 1) {
$key = 'bgvyzdsv';
$stop_value = 0;
for ($i = 0; $i < 10000000; $i++) {
$stop_value = $key . $i;
$md5 = md5($stop_value);
if ($part == 1) {
$identifier = '00000';
}
elseif ($part == 2) {
$identifier = '000000';
}
if (str_starts_with($md5, $identifier)) {
break;
}
}
return str_replace($key, '', $stop_value);
}