forked from charlesfranciscodev/codingame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
there-is-no-spoon1.js
45 lines (39 loc) · 1.11 KB
/
there-is-no-spoon1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const EMPTY = ".";
const NODE = "0";
let grid = [];
const WIDTH = parseInt(readline()); // the number of cells on the X axis
const HEIGHT = parseInt(readline()); // the number of cells on the Y axis
for (let y = 0; y < HEIGHT; y++) {
grid.push(readline());
}
for (let y = 0; y < HEIGHT; y++) {
for (let x = 0; x < WIDTH; x++) {
if (grid[y].charAt(x) === NODE) {
// node
let output = x + " " + y + " ";
// right neighbor
let neighbor = EMPTY;
for (let neighborX = x + 1; neighborX < WIDTH; neighborX++) {
neighbor = grid[y].charAt(neighborX);
if (neighbor === NODE) {
output += neighborX + " " + y + " ";
break;
}
}
if (neighbor === EMPTY)
output += "-1 -1 ";
// bottom neighbor
neighbor = EMPTY
for (let neighborY = y + 1; neighborY < HEIGHT; neighborY++) {
neighbor = grid[neighborY].charAt(x);
if (neighbor === NODE) {
output += x + " " + neighborY + " ";
break;
}
}
if (neighbor === EMPTY)
output += "-1 -1 ";
print(output);
}
}
}