File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed
Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ const input = + require ( 'fs' )
2+ . readFileSync ( process . platform === 'linux' ? '/dev/stdin' : './input.txt' )
3+ . toString ( )
4+ . trim ( ) ;
5+
6+ function solution ( input ) {
7+ const N = 1 + ( input - 1 ) * 4 ;
8+ const map = Array . from ( Array ( N ) , ( ) => Array ( N ) . fill ( ' ' ) ) ;
9+
10+ function 재귀 ( n , x , y ) {
11+ if ( n === 1 ) {
12+ map [ x ] [ y ] = '*' ;
13+ return ;
14+ }
15+ const len = 1 + ( n - 1 ) * 4 ;
16+ for ( let i = 0 ; i < len ; i ++ ) {
17+ map [ x ] [ y + i ] = '*' ;
18+ map [ x + len - 1 ] [ y + i ] = '*' ;
19+ map [ x + i ] [ y ] = '*' ;
20+ map [ x + i ] [ y + len - 1 ] = '*' ;
21+ }
22+ 재귀 ( n - 1 , x + 2 , y + 2 ) ;
23+ return ;
24+ }
25+
26+ 재귀 ( input , 0 , 0 ) ;
27+
28+ return map . map ( ( el ) => el . join ( '' ) ) . join ( '\n' ) ;
29+ }
30+
31+ console . log ( solution ( input ) ) ;
Original file line number Diff line number Diff line change 1+ const input = require ( 'fs' )
2+ . readFileSync ( process . platform === 'linux' ? '/dev/stdin' : './input.txt' )
3+ . toString ( )
4+ . trim ( )
5+ . split ( '\n' )
6+ . map ( Number ) ;
7+
8+ function 재귀 ( field , start , end ) {
9+ const length = end - start ;
10+ if ( length === 1 ) {
11+ return ;
12+ }
13+
14+ const size = length / 3 ;
15+
16+ for ( let i = start + size ; i < start + size * 2 ; i ++ ) {
17+ field [ i ] = ' ' ;
18+ }
19+
20+ 재귀 ( field , start , start + size ) ;
21+ 재귀 ( field , start + size * 2 , end ) ;
22+ }
23+
24+ function solution ( input ) {
25+ const result = [ ] ;
26+ for ( let i = 0 ; i < input . length ; i ++ ) {
27+ const N = input [ i ] ;
28+ if ( N === 0 ) {
29+ result . push ( '-' ) ;
30+ continue ;
31+ }
32+ if ( N === 1 ) {
33+ result . push ( '- -' ) ;
34+ continue ;
35+ }
36+ const M = 3 ** N ;
37+ const field = Array ( M ) . fill ( '-' ) ;
38+ 재귀 ( field , 0 , M ) ;
39+ result . push ( field . join ( '' ) ) ;
40+ }
41+ return result . join ( '\n' ) ;
42+ }
43+
44+ console . log ( solution ( input ) ) ;
You can’t perform that action at this time.
0 commit comments