def fence_pattern():
    pass


def encode():
    pass


def decode():
    pass

@@ -1,80 +1,1166 @@
+import math%0A%0A%0A
 def 
-f
 enc
-e_pattern(
+ode(s, n):%0A    _n = 2 * n - 2%0A    chunks = %5Bs%5Bi::_n%5D + %22 %22 for i in range(_n)%5D%0A    lines = %5B%5D%0A    for i in range(n
 ):%0A    
+ 
-pass
+   if i == 0 or i == n-1:%0A            lines.append(chunks%5Bi%5D)%0A        else:%0A            lines.append(%22%22.join(x + y for x, y in zip(chunks%5Bi%5D, chunks%5B-i%5D)))%0A    return %22%22.join(map(str.strip, lines))
 %0A%0A%0Adef 
+d
 e
-n
 code(
+s, n
 ):%0A    
-pass%0A%0A%0Adef decode()
+_n = 2 * n - 2%0A    diff = len(s) %25 _n%0A    if diff == 0:  diff = _n%0A    base_chunk_len = math.ceil(len(s) / _n)%0A    _chunk_lens = %5Bbase_chunk_len - 1 if i %3E= diff else base_chunk_len%0A                       for i in range(_n)%5D%0A%0A    chunk_lens = %5B_chunk_lens%5Bi%5D if i in %7B0, n-1%7D%0A                  else _chunk_lens%5Bi%5D + _chunk_lens%5B-i%5D for i in range(n)%5D%0A%0A    start = 0%0A    chunks = %5B%5D%0A    for i in range(n):%0A        chunks.append(s%5Bstart:start+chunk_lens%5Bi%5D%5D)%0A        start += chunk_lens%5Bi%5D%0A%0A    _chunks = %5B%5D%0A    for i in range(_n):%0A        if i == 0 or i == n-1:%0A            _chunks.append(chunks%5Bi%5D + %22 %22)%0A        elif i %3C n:%0A            _chunks.append(chunks%5Bi%5D%5B0::2%5D + %22 %22)%0A        else
 :%0A    
+ 
-pass
+       _chunks.append(chunks%5B_n - i%5D%5B1::2%5D + %22 %22)%0A%0A    return %22%22.join(map(%22%22.join, zip(*_chunks))).strip()
 %0A

Add initial solution