dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
2.7 KiB
2.7 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6a22d77ddf034bc4e35b1d56 | Challenge 349: Cell Signal | 29 | challenge-349 |
--description--
Given a grid containing three cell tower readings, determine the location of the phone.
- Each cell in the grid is either
0(no tower) or a positive integer representing the number of cells to the phone, measured in a straight line: horizontal, vertical, or diagonal. - Return the
[row, col]of the cell that is the correct number of cells from all three towers. - There is always exactly one solution.
--hints--
find_signal([[0, 0, 1], [0, 1, 0], [0, 0, 1]]) should return [1, 2].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_signal([[0, 0, 1], [0, 1, 0], [0, 0, 1]]), [1, 2])`)
}})
find_signal([[0, 2, 0], [1, 0, 0], [0, 0, 1]]) should return [2, 1].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_signal([[0, 2, 0], [1, 0, 0], [0, 0, 1]]), [2, 1])`)
}})
find_signal([[0, 0, 2, 0], [0, 0, 0, 0], [2, 0, 0, 0], [0, 0, 0, 1]]) should return [2, 2].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_signal([[0, 0, 2, 0], [0, 0, 0, 0], [2, 0, 0, 0], [0, 0, 0, 1]]), [2, 2])`)
}})
find_signal([[0, 3, 0, 0, 0], [0, 0, 0, 0, 2], [0, 0, 0, 0, 0], [4, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) should return [3, 4].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_signal([[0, 3, 0, 0, 0], [0, 0, 0, 0, 2], [0, 0, 0, 0, 0], [4, 0, 0, 0, 0], [0, 0, 0, 0, 0]]), [3, 4])`)
}})
find_signal([[3, 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, 2, 0, 0, 0, 2]]) should return [3, 3].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_signal([[3, 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, 2, 0, 0, 0, 2]]), [3, 3])`)
}})
--seed--
--seed-contents--
def find_signal(grid):
return grid
--solutions--
def find_signal(grid):
rows = len(grid)
cols = len(grid[0])
towers = []
for r in range(rows):
for c in range(cols):
if grid[r][c] != 0:
towers.append((r, c, grid[r][c]))
def is_valid(r, c, tr, tc, dist):
dr = abs(r - tr)
dc = abs(c - tc)
return (dr == dist or dc == dist) and (dr == 0 or dc == 0 or dr == dc)
for r in range(rows):
for c in range(cols):
if grid[r][c] != 0:
continue
if all(is_valid(r, c, tr, tc, dist) for tr, tc, dist in towers):
return [r, c]