✨ Finit le 2eme jour
This commit is contained in:
parent
44837f9672
commit
fa2132ad25
21
day_2/part_1.php
Normal file
21
day_2/part_1.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
$passwords = explode("\n", file_get_contents('input.txt'));
|
||||
|
||||
$number_of_good_passwords = 0;
|
||||
|
||||
foreach ($passwords as $password) {
|
||||
$parts = explode(' ', $password);
|
||||
if (count($parts) === 3) {
|
||||
[$min, $max] = explode('-', $parts[0]);
|
||||
$letter = $parts[1][0];
|
||||
$word = $parts[2];
|
||||
$chars = count_chars($word, 1);
|
||||
if ($min <= $chars[ord($letter)] && $max >= $chars[ord($letter)]) {
|
||||
$number_of_good_passwords++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $number_of_good_passwords;
|
||||
exit(0);
|
20
day_2/part_2.php
Normal file
20
day_2/part_2.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
$passwords = explode("\n", file_get_contents('input.txt'));
|
||||
|
||||
$number_of_good_passwords = 0;
|
||||
|
||||
foreach ($passwords as $password) {
|
||||
$parts = explode(' ', $password);
|
||||
if (count($parts) === 3) {
|
||||
[$min, $max] = explode('-', $parts[0]);
|
||||
$letter = $parts[1][0];
|
||||
$word = $parts[2];
|
||||
if ($word[$min-1] === $letter xor $word[$max-1] === $letter) {
|
||||
$number_of_good_passwords++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $number_of_good_passwords;
|
||||
exit(0);
|
Loading…
Reference in New Issue
Block a user