diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2024-06-19 10:19:37 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2024-06-19 10:19:37 +0800 |
| commit | 8fea6debb2f1582d761fcb3842dc1f8d9bc683ea (patch) | |
| tree | aa8434550ab5ac39df8b5fc66084bbdd6c7ecbf1 /challenge-270/2colours/php/ch-1.php | |
| parent | 2a6cdeb8e1b429bdb337b3e261f83bdd0a5b80d9 (diff) | |
| parent | ffc47a8850ee877978e371d11a01a028862a3f9d (diff) | |
| download | perlweeklychallenge-club-8fea6debb2f1582d761fcb3842dc1f8d9bc683ea.tar.gz perlweeklychallenge-club-8fea6debb2f1582d761fcb3842dc1f8d9bc683ea.tar.bz2 perlweeklychallenge-club-8fea6debb2f1582d761fcb3842dc1f8d9bc683ea.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-270/2colours/php/ch-1.php')
| -rw-r--r-- | challenge-270/2colours/php/ch-1.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-270/2colours/php/ch-1.php b/challenge-270/2colours/php/ch-1.php new file mode 100644 index 0000000000..a648391f0a --- /dev/null +++ b/challenge-270/2colours/php/ch-1.php @@ -0,0 +1,21 @@ +<?php + +$matrix = json_decode(file_get_contents('php://stdin')); +$solutions = $matrix; + +foreach ($matrix as $row => $content) { + $valid_row = array_sum($content) === 1; + foreach ($solutions[$row] as &$value) { + $value *= $valid_row; + } +} +foreach (array_map(null, ...$matrix) as $column => $content) { + $valid_column = array_sum($content) === 1; + foreach (array_keys($solutions) as $row) { + $solutions[$row][$column] *= $valid_column; + } +} + +$result = 0; +array_walk_recursive($solutions, function ($elem) use (&$result) { $result += $elem; }); +echo $result;
\ No newline at end of file |
