Skip to content

Commit cadf830

Browse files
committed
Gold5: 재귀함수
1 parent fbbc54d commit cadf830

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require("fs");
2+
const filePath =
3+
process.platform === "linux" ? "/dev/stdin" : "./Z_Test/input.txt";
4+
let input = fs.readFileSync(filePath).toString().trim().split("\n");
5+
6+
const n = +input;
7+
const arr = new Array(n).fill().map((item) => new Array(n).fill(" "));
8+
9+
const solution = (n, arr) => {
10+
const recursive = (x, y, size) => {
11+
if (size === 1) {
12+
console.log(x, y, size);
13+
arr[x][y] = "*";
14+
return;
15+
}
16+
17+
const newSize = size / 3;
18+
for (let i = 0; i < 3; i++) {
19+
for (let j = 0; j < 3; j++) {
20+
if (i === 1 && j === 1) {
21+
continue;
22+
}
23+
recursive(x + newSize * i, y + newSize * j, newSize);
24+
}
25+
}
26+
};
27+
28+
recursive(0, 0, n);
29+
};
30+
31+
solution(n, arr);
32+
33+
arr.map((item) => console.log(item.join("")));
34+
35+
console.log(n, arr);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9

0 commit comments

Comments
 (0)