Day 4 solution.
This commit is contained in:
parent
674175c5ea
commit
d17bf4218b
21
2015/days/day4.php
Normal file
21
2015/days/day4.php
Normal 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);
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user