Simple Fun #155: Pac-Man
Description:
Task
Pac-Man got lucky today! Due to minor performance issue all his enemies have frozen. Too bad Pac-Man is not brave enough to face them right now, so he doesn't want any enemy to see him.
Given a gamefield of size N
x N
, Pac-Man's position(PM
) and his enemies' positions(enemies
), your task is to count the number of coins he can collect without being seen.
An enemy can see a Pac-Man if they are standing on the same row or column.
It is guaranteed that no enemy can see Pac-Man on the starting position. There is a coin on each empty square (i.e. where there is no Pac-Man or enemy).
Example
For N = 4, PM = [3, 0], enemies = [[1, 2]]
, the result should be 3
.
Let O represent coins, P - Pac-Man and E - enemy.
OOOO
OOEO
OOOO
POOO
Pac-Man cannot cross row 1 and column 2.
He can only collect coins from points (2, 0), (2, 1) and (3, 1)
, like this:
x is the points that Pac-Man can collect the coins.
OOOO
OOEO
xxOO
PxOO
Input/Output
[input]
integerN
The field size.
[input]
integer arrayPM
Pac-Man's position (pair of integers)
[input]
2D integer arrayenemies
Enemies' positions (array of pairs)
[output]
an integer
Number of coins Pac-Man can collect.
More PacMan Katas
Similar Kata:
Stats:
Created | Feb 22, 2017 |
Published | Feb 22, 2017 |
Warriors Trained | 695 |
Total Skips | 86 |
Total Code Submissions | 1218 |
Total Times Completed | 270 |
JavaScript Completions | 69 |
C# Completions | 68 |
Python Completions | 126 |
Ruby Completions | 29 |
Total Stars | 25 |
% of votes with a positive feedback rating | 94% of 79 |
Total "Very Satisfied" Votes | 71 |
Total "Somewhat Satisfied" Votes | 6 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |