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);
}

View File

@ -12,6 +12,8 @@ $solutions['day_2']['part_1'] = day2(1);
$solutions['day_2']['part_2'] = day2(2);
$solutions['day_3']['part_1'] = day3(1);
$solutions['day_3']['part_2'] = day3(2);
$solutions['day_4']['part_1'] = day4(1);
$solutions['day_4']['part_2'] = day4(2);
// OUTPUT THE SOLUTIONS WE HAVE.
foreach ($solutions as $day => $parts) {