-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2447_star10.js
141 lines (104 loc) · 2.64 KB
/
2447_star10.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 2447 별찍기 10
const fs = require("fs");
let origin = Number(fs.readFileSync("input.txt").toString());
let arr = new Array(origin).fill().map((v) => {
let temp = [];
for (let i = 0; i < origin; i++) {
temp.push("*");
}
return temp;
});
function marker(input) {
if (input === 1) return;
let divn = input / 3;
let divn2 = (input / 3) * 2;
let accessible = new Array(origin).fill().map((v) => (v = 1));
if (input > 3) {
for (let a = input / 9; a < origin; a += input / 3) {
for (let b = 0; b < input / 9; b++) {
accessible[a + b] = 0;
}
}
}
for (let i = 0; i < origin; i++) {
for (let j = 0; j < origin; j++) {
if (i % 3 === 1 && j % 3 === 1) {
arr[i][j] = " ";
}
if (divn <= i && i < divn2 && divn <= j && j < divn2) {
arr[i][j] = " ";
}
if (!accessible[i] && !accessible[j]) {
arr[i][j] = " ";
}
}
}
marker(divn);
}
marker(origin);
for (let k = 0; k < origin; k++) {
arr[k] = arr[k].join("");
}
arr = arr.join("\n");
console.log(arr);
// let ans = "*";
// let blank = " ";
// function marker(turn, ans, blank) {
// if (turn === 1) {
// return ans;
// }
// let result = [[], [], []];
// for (let i = 0; i < 3; i++) {
// if (i === 0) {
// result[0].push(ans, ans, ans);
// } else if (i === 1) {
// result[1].push(ans, blank, ans);
// } else {
// result[2].push(ans, ans, ans);
// }
// }
// console.log("turn: ", turn, result);
// let temp = "";
// let tempBlank = "";
// for (let j = 0; j < 3; j++) {
// temp = temp + result[j].join("") + "\n";
// tempBlank = tempBlank + blank.repeat(3) + "\n";
// }
// turn /= 3;
// ans = temp.trim();
// blank = tempBlank;
// // console.log(turn, "!");
// // console.log(ans, "!");
// // console.log(tempBlank, "!");
// return marker(turn, ans, blank);
// }
// marker(9, ans, blank);
/*
*/
// const num = parseInt(input[0]);
// const lines = [];
// printStars(num);
// console.log(lines.join(""));
// function printStars(num) {
// for (let i = 0; i < num; i++) {
// for (let j = 0; j < num; j++) {
// star(i, j, num);
// }
// lines.push("\n");
// }
// }
// function star(i, j, num) {
// if (i % 3 == 1 && j % 3 == 1) {
// // (1,1), (1,4), (1,7)...
// lines.push(" ");
// } else {
// if (num == 1) {
// lines.push("*");
// } else {
// // (3,3) = (1,1)이 되고,
// // (3,4) = (1,1)이 된다.
// // (9,9), (27,27)도 동일한 방식으로 재귀 호출된다.
// star(parseInt(i / 3), parseInt(j / 3), parseInt(num / 3));
// }
// }
// }