Stop the Zombie Apocalypse!
Description:
Introduction
You are a number. But that's good for you since you live in the beautiful world, where the only living creatures are numbers. Unfortunately, a nasty zombie virus is spreading out in the digital cities. You work at the digital CDC and your job is to look over the city maps and tell which areas are contaminated by the zombie virus so the digital army would know where to drop the bombs. They are the new kind of digital zombies which can travel only in vertical and horizontal directions and infect only numbers same as them, but don't let it fool you, they're still very dangerous. Time is running out...
Task
You'll be given two-dimensional array with numbers in it. For some mysterious reason patient zero is always found in north west area of the city (element [0][0]
of the matrix) and the plague spreads from there to other cells by moving left, right, up or down. You must create a function that returns a map (2-dimensional array) with all the contaminated areas marked as 1
and virus-free marked as 0
.
In other words: find all the matrix elements with the same value as [0][0]
that you can go to by moving only down, up, right or left from [0][0]
- without going into a field storing any other value.
Examples
city1 = [
[7, 2, 3],
[7, 2, 3],
[1, 2, 7]
];
contaminatedInCity1 = [
[1, 0, 0],
[1, 0, 0],
[0, 0, 0]
]; // number 7 is a zombie, but the 7 in bottom right corner is not a zombie yet - the virus didn't get there.
city2 = [
[9, 1, 2],
[9, 9, 9],
[7, 4, 9],
[7, 9, 7]
];
contaminatedInCity2 = [
[1, 0, 0],
[1, 1, 1],
[0, 0, 1],
[0, 0, 0]
]; // infection inflicted the 9s, but the virus didn't get to the one in the south of the city yet.
Similar Kata:
Stats:
Created | Nov 13, 2014 |
Published | Nov 13, 2014 |
Warriors Trained | 1308 |
Total Skips | 125 |
Total Code Submissions | 4780 |
Total Times Completed | 358 |
JavaScript Completions | 339 |
CoffeeScript Completions | 4 |
Python Completions | 24 |
Total Stars | 90 |
% of votes with a positive feedback rating | 96% of 78 |
Total "Very Satisfied" Votes | 72 |
Total "Somewhat Satisfied" Votes | 6 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 10 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 6 kyu |