diff options
| author | 2colours <polgar.marton@windowslive.com> | 2024-05-11 04:09:15 +0200 |
|---|---|---|
| committer | 2colours <polgar.marton@windowslive.com> | 2024-05-11 04:09:15 +0200 |
| commit | 84d5b5f1015346320fe9a98faabd9ff8652df13b (patch) | |
| tree | 0299d52b8f036694e649469b6effb38c14f52c82 | |
| parent | eb6fa96130eaa2b93c9b20c7b8938e121889cea4 (diff) | |
| download | perlweeklychallenge-club-84d5b5f1015346320fe9a98faabd9ff8652df13b.tar.gz perlweeklychallenge-club-84d5b5f1015346320fe9a98faabd9ff8652df13b.tar.bz2 perlweeklychallenge-club-84d5b5f1015346320fe9a98faabd9ff8652df13b.zip | |
PHP solutions for week 262
| -rw-r--r-- | challenge-262/2colours/php/ch-1.php | 7 | ||||
| -rw-r--r-- | challenge-262/2colours/php/ch-2.php | 16 |
2 files changed, 23 insertions, 0 deletions
diff --git a/challenge-262/2colours/php/ch-1.php b/challenge-262/2colours/php/ch-1.php new file mode 100644 index 0000000000..c714bc2363 --- /dev/null +++ b/challenge-262/2colours/php/ch-1.php @@ -0,0 +1,7 @@ +<?php + +const PARENS = ['(', ')']; +const SQUARE_BRACKETS = ['[', ']']; +echo '@ints = '; +$ints = json_decode(str_replace(PARENS, SQUARE_BRACKETS, fgets(STDIN))); +echo max(...array_map(fn ($pred) => count(array_filter($ints, $pred)), [fn ($x) => $x > 0, fn ($x) => $x < 0]));
\ No newline at end of file diff --git a/challenge-262/2colours/php/ch-2.php b/challenge-262/2colours/php/ch-2.php new file mode 100644 index 0000000000..bec9137694 --- /dev/null +++ b/challenge-262/2colours/php/ch-2.php @@ -0,0 +1,16 @@ +<?php + +const PARENS = ['(', ')']; +const SQUARE_BRACKETS = ['[', ']']; +echo '@ints = '; +$ints = json_decode(str_replace(PARENS, SQUARE_BRACKETS, fgets(STDIN))); +echo '$k = '; +$k = fgets(STDIN); +$result = 0; +foreach ($ints as $index => $value) { + $needed_factor = intdiv($k, gmp_intval(gmp_gcd($index, $k))); + $next_valid = ceil(($index + 1) / $needed_factor) * $needed_factor; + $values_to_check = array_column(array_chunk(array_slice($ints, $next_valid), $needed_factor), 0); + $result += @array_count_values($values_to_check)[$value]; +} +echo $result;
\ No newline at end of file |
