xs = [' ', '│', '─', '┌', '┐', '┘', '└']
lt = {0:0,1:2,2:1,3:4,4:5,5:6,6:3}
rt = {0:0,1:2,2:1,3:6,4:3,5:4,6:5}

def rotate_left(xs):
    n, m = len(xs), len(xs[0])
    return [[lt[xs[n - 1 - i][j]] for i in range(n)] for j in range(m)]

def rotate_right(xs):
    n, m = len(xs), len(xs[0])
    return [[rt[xs[i][m - 1 - j]] for i in range(n)] for j in range(m)]
    
def ins(xs):
    n, m = len(xs), len(xs[0])
    ans = []
    for i in range(n):
        r = [xs[i][0]]
        for j in range(1, m):
            val = 2 if (xs[i][j - 1], xs[i][j]) in ((2,5),(3,5),(6,5),(2,4),(3,4),(6,4),(2,2),(3,2),(6,2)) else 0
            r.extend([val, xs[i][j]])
        ans.append(r)
    return ans
            

def solve(n):
    if n == 1:
        return [[3, 2, 4], [1, 0, 1]]
    r = solve(n - 1)
    m, k = len(r), len(r[0])
    ans = []
    for i in range(m):
        ans.append(r[i][:] + [0 if i < m - 1 else 2] + r[i][:])
    s, t = rotate_left([x[::2] for x in r]), rotate_right([x[::2] for x in r])
    # print(ans)
    # print(s)
    # print(t)
    ss, tt = ins(s), ins(t)
    # print("ss :", ss)
    # print("tt :", tt)
    for i in range(m):
        ans.append(ss[i] + [0] + tt[i])
    if ans[m - 2][k - 1] == 4:
        ans[m - 1][k - 1] = 6
    if ans[m - 2][k + 1] == 3:
        ans[m - 1][k + 1] = 5
    # 1
    # 62
    if ans[m - 1][0] == 1 and ans[m][1] == 2:
        ans[m][0] = 6
    # 32
    # 1
    if ans[m - 1][1] == 2 and ans[m][0] == 1:
        ans[m - 1][0] = 3
    #  1
    # 25
    if ans[m - 1][-1] == 1 and ans[m][-2] == 2:
        ans[m][-1] = 5
    # 24
    #  1
    if ans[m - 1][-2] == 2 and ans[m][-1] == 1:
        ans[m - 1][-1] = 4
    return ans

def hilbert_string(n):
    cs = solve(n)
    return '\n'.join(''.join(map(str, [xs[e] for e in r])) for r in cs)
n = 5
a = hilbert_string(n)
print(a)
    

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: