Day 4 solution.
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user