A company wants to put a cell tower to the north of a city but is unsure of where buildings will cause interference.
You will be given a 2D array comprised of numbers representing the interference of a building. This value will be a decimal number less than 1 that represents the percentage impact it has on the signal strength.
You may assume that the signal is uniform across the entire northern front of the city.
The first row
will have the strength of the initial signal strength.
You are tasked with producing a 2D array that shows where the cell signal reaches comprised of numbers that represent the strength of the cell signal at each location.
With each unobstructed row
the signal passes through, it will lose a constant 1 strength.
Should the signal drop below 1, it will be considered 0.
Each calculation should be rounded to 2 decimal points.
As an example, you may be given an input resembling the following (formatted to ease of reading):
building_map = [
[0.20, 0.00, 0.00, 0.00, 0.00],
[0.00, 0.00, 0.25, 0.00, 0.00],
[0.00, 0.50, 0.00, 0.00, 0.00],
[0.00, 0.00, 0.50, 0.00, 0.00],
[0.15, 0.00, 0.00, 0.10, 0.00]
],
signal_strength = 4
You should return the following array:
signal_map = [
[3.20, 4.00, 4.00, 4.00, 4.00],
[2.20, 3.00, 3.00, 3.00, 3.00],
[1.20, 1.50, 2.00, 2.00, 2.00],
[0.00, 0.00, 1.00, 1.00, 1.00],
[0.00, 0.00, 0.00, 0.00, 0.00]
]
# Enter solution here
def get_signal_pattern(building_map, signal_strength):
return []
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
building_map_1 = [
[0.05, 0.10, 0.00],
[0.00, 0.20, 0.00],
[0.00, 0.00, 0.30]
]
signal_strength_1 = 5
signal_map_1 = [
[4.75, 4.50, 5.00],
[3.75, 3.60, 4.00],
[2.75, 2.60, 2.80]
]
building_map_2 = [
[0.50, 0.50, 0.50],
[0.50, 0.50, 0.50],
[0.50, 0.50, 0.50]
]
signal_strength_2 = 5
signal_map_2 = [
[2.50, 2.50, 2.50],
[1.25, 1.25, 1.25],
[0.00, 0.00, 0.00]
]
building_map_3 = [
[0.00, 0.00, 0.00],
[0.00, 0.00, 0.00],
[0.00, 0.00, 0.00]
]
signal_strength_3 = 10
signal_map_3 = [
[10.00, 10.00, 10.00],
[9.00, 9.00, 9.00],
[8.00, 8.00, 8.00]
]
building_map_4 = [
[0.20, 0.00, 0.00, 0.00, 0.00],
[0.00, 0.00, 0.25, 0.00, 0.00],
[0.00, 0.50, 0.00, 0.00, 0.00],
[0.00, 0.00, 0.50, 0.00, 0.00],
[0.15, 0.00, 0.00, 0.10, 0.00]
]
signal_strength_4 = 4
signal_map_4 = [
[3.20, 4.00, 4.00, 4.00, 4.00],
[2.20, 3.00, 3.00, 3.00, 3.00],
[1.20, 1.50, 2.00, 2.00, 2.00],
[0.00, 0.00, 1.00, 1.00, 1.00],
[0.00, 0.00, 0.00, 0.00, 0.00]
]
building_map_5 = [
[0.10, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.10],
[0.00, 0.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.20, 0.00],
[0.00, 0.00, 0.30, 0.00, 0.00, 0.00, 0.30, 0.00, 0.00],
[0.00, 0.00, 0.00, 0.40, 0.00, 0.40, 0.00, 0.00, 0.00],
[0.00, 0.00, 0.00, 0.00, 0.50, 0.00, 0.00, 0.00, 0.00],
[0.00, 0.00, 0.00, 0.60, 0.00, 0.60, 0.00, 0.00, 0.00],
[0.00, 0.00, 0.70, 0.00, 0.00, 0.00, 0.70, 0.00, 0.00],
[0.00, 0.80, 0.00, 0.00, 0.00, 0.00, 0.00, 0.80, 0.00],
[0.90, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.90]
]
signal_strength_5 = 50
signal_map_5 = [
[45.00, 50.00, 50.00, 50.00, 50.00, 50.00, 50.00, 50.00, 45.00],
[44.00, 40.00, 49.00, 49.00, 49.00, 49.00, 49.00, 40.00, 44.00],
[43.00, 39.00, 34.30, 48.00, 48.00, 48.00, 34.30, 39.00, 43.00],
[42.00, 38.00, 33.30, 28.80, 47.00, 28.80, 33.30, 38.00, 42.00],
[41.00, 37.00, 32.30, 27.80, 23.50, 27.80, 32.30, 37.00, 41.00],
[40.00, 36.00, 31.30, 11.12, 22.50, 11.12, 31.3, 36.00, 40.00],
[39.00, 35.00, 9.39, 10.12, 21.50, 10.12, 9.39, 35.00, 39.00],
[38.00, 7.00, 8.39, 9.12, 20.50, 9.12, 8.39, 7.00, 38.00],
[3.80, 6.00, 7.39, 8.12, 19.50, 8.12, 7.39, 6.00, 3.80]
]
@test.it("Map #1")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_1, signal_strength_1), signal_map_1, "Test #1 Failed")
@test.it("Map #2")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_2, signal_strength_2), signal_map_2, "Test #2 Failed")
@test.it("Map #3")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_3, signal_strength_3), signal_map_3, "Test #3 Failed")
@test.it("Map #4")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_4, signal_strength_4), signal_map_4, "Test #4 Failed")
@test.it("Map #5")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_5, signal_strength_5), signal_map_5, "Test #5 Failed")
A company wants to put a cell tower to the north of a city but is unsure of where buildings will cause interference.
You will be given a 2D array comprised of 0s and 1s representing no buildings and buildings respectively.
You may assume that the signal is uniform across the entire northern front of the city.
You are tasked with producing a 2D array that shows where the cell signal reaches comprised of 0s and 1s where 0 is no signal and 1 has signal.
For this first iteration, assume that one building stops a signal and the locations of builds also do not have signal.
You may also assume that the signal is otherwise strong enough to reach the southern edge of the city.
As an example, you may be given an input resembling the following:
building_map = [
[1, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[1, 0, 0, 1, 0]
]
You should return the following array:
signal_map = [
[0, 1, 1, 1, 1],
[0, 1, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 1]
]
# Enter solution here
def get_signal_pattern(building_map):
return []
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
building_map_1 = [
[1, 1, 0],
[0, 1, 0],
[0, 0, 1]
]
signal_map_1 = [
[0, 0, 1],
[0, 0, 1],
[0, 0, 0]
]
building_map_2 = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]
signal_map_2 = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
building_map_3 = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
signal_map_3 = [
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]
]
building_map_4 = [
[1, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[1, 0, 0, 1, 0]
]
signal_map_4 = [
[0, 1, 1, 1, 1],
[0, 1, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 1]
]
building_map_5 = [
[1, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 0, 0, 0, 1]
]
signal_map_5 = [
[0, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]
]
@test.it("Map #1")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_1), signal_map_1, "Test #1 Failed")
@test.it("Map #2")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_2), signal_map_2, "Test #2 Failed")
@test.it("Map #3")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_3), signal_map_3, "Test #3 Failed")
@test.it("Map #4")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_4), signal_map_4, "Test #4 Failed")
@test.it("Map #5")
def test_case():
test.assert_equals(solution.get_signal_pattern(building_map_5), signal_map_5, "Test #5 Failed")