Skip to content

Instantly share code, notes, and snippets.

@modos
Created October 5, 2022 03:30
Show Gist options
  • Save modos/9a93a4541d72c235b6fba9c68ee13265 to your computer and use it in GitHub Desktop.
Save modos/9a93a4541d72c235b6fba9c68ee13265 to your computer and use it in GitHub Desktop.
بمب بازی
<?php
list($m, $n) = explode(' ', readline());
$k = readline();
$i = 0;
$data = [];
while ($i < $k) {
$data[] = readline();
$i++;
}
$row_str = [];
for ($i = 1; $i <= $m; $i++) {
$row = [];
for ($j = 1; $j <= $n; $j++) {
$around_points_array = [
[$i - 1, $j],
[$i + 1, $j],
[$i, $j + 1],
[$i, $j - 1],
[$i + 1, $j + 1],
[$i - 1, $j - 1],
[$i + 1, $j - 1],
[$i - 1, $j + 1],
];
$around_points_string = [];
foreach ($around_points_array as $p) {
$around_points_string[] = implode(' ', $p);
}
$diff = array_diff(["$i $j"], $data);
if (count($diff) == 0) {
$row[] = "*";
} else {
$row[] = 8 - count(array_diff($around_points_string, $data));
}
}
$row_str[] = implode(' ', $row);
}
$result = implode("\n", $row_str);
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment