-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascript.js
47 lines (47 loc) · 1.26 KB
/
Javascript.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
46
47
var inputs = readline().split(" ");
const width = parseInt(inputs[0]);
const height = parseInt(inputs[1]);
const count = parseInt(readline());
let grid = [];
for (let i = 0; i < height; i++) {
const raster = readline();
grid.push(raster);
}
for (let z = 0; z < count; z++) {
let g = [];
for (let i = 0; i < grid[0].length; i++) {
//Create the array that will receive the rotation
g.push([]);
for (let j = 0; j < grid.length; j++) {
g[i].push(0);
}
}
for (let i = 0; i < grid.length; i++) {
//Return the array in the new array
for (let j = 0; j < grid[0].length; j++) {
g[j][i] = grid[i][j];
}
}
grid = g;
for (let i = g.length - 1; i >= 0; i--) {
//Step through rows from bottom
for (let j = 0; j < g[0].length; j++) {
//Iterate through each column of a row
if (grid[i][j] == ".") {
//If the current box of the table is '.'
for (let k = i - 1; k >= 0; k--) {
//Cycle through the cells above this one
if (grid[k][j] == "#") {
//If we find a cell with '#' swap them
grid[i][j] = "#";
grid[k][j] = ".";
break;
}
}
}
}
}
}
for (let i = 0; i < grid.length; i++) {
console.log(grid[i].join(""));
}