본문 바로가기

알고리즘

백준 2447 "별 찍기 - 10"

Python

def recursive(depth, k, stars):
    #1. 탈출
    if k ==0 :
        for i in stars:
            for j in i:
                print(j, end="")
            print()
        return  
    #2. 재귀로직
    step = int(k*3)
    for a in range(0, len(stars), step):
        for b in range(0, len(stars), step):
            for i in range(a+k, a+2*k): 
                for j in range(b+k, b+2*k):
                    stars[i][j] = " "  
    recursive(depth+1, k//3, stars)
    
n = int(input())
empty = n//3
stars = [["*"] *n for _ in range(n) ] 
recursive(1,n//3,stars)