Problem 45395. Create a matrix map of increasing safety levels
The sole nuclear power plant at Grid City suddenly had a meltdown. Luckily, the plant was designed to be in full automation, so no casualties were ever recorded. However, thanks to radiation, the whole city is inhabitable for close to a century.
You are then given a portion of the map of Grid City which, for the purpose of this problem, is rendered as an N x N matrix. As the name suggests, Grid City is made of a grid of cells. Your task is to assign a safety level to each cell in this matrix, according to the following rules:
- Assign Safety Level 1 to the cell location of the nuclear power plant, given at row R and column C. This signifies that cell (R,C) is least safe.
- Assign Safety Level 2 to the adjacent cells around the power plant, signifying a safer radiation level in this area.
- Continue assigning an increasing number of Safety Levels at succeeding layers of cells surrounding the power plant until you reach the edge of the map.
Write a function that accepts three inputs, N, R, and C, and outputs a matrix map of Grid City with Safety Levels. Note that you can use any method of populating the matrix as long as it gives the correct answer. You are also ensured that:
- N, R, C are all integers
- 1 <= N <= 10
- 1 <= R <= N and 1 <= C <= N
Here are a few examples:
>> safety_map(5,5,4) % N = 5, R = 5, C = 4 ans =
5 5 5 5 5 4 4 4 4 4 4 3 3 3 3 4 3 2 2 2 4 3 2 1 2 >> safety_map(6,2,3) % N = 6, R = 2, C = 3 ans =
3 2 2 2 3 4 3 2 1 2 3 4 3 2 2 2 3 4 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers69
Suggested Problems
-
Remove the small words from a list of words.
1496 Solvers
-
given 3 sides, find area of this triangle
797 Solvers
-
374 Solvers
-
1225 Solvers
-
9160 Solvers
More from this Author19
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!