<p>The string <code>&quot;PAYPALISHIRING&quot;</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>

<pre>
P   A   H   N
A P L S I I G
Y   I   R
</pre>

<p>And then read line by line: <code>&quot;PAHNAPLSIIGYIR&quot;</code></p>

<p>Write the code that will take a string and make this conversion given a number of rows:</p>

<pre>
string convert(string s, int numRows);
</pre>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;PAYPALISHIRING&quot;, numRows = 3
<strong>Output:</strong> &quot;PAHNAPLSIIGYIR&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;PAYPALISHIRING&quot;, numRows = 4
<strong>Output:</strong> &quot;PINALSIGYAHRPI&quot;
<strong>Explanation:</strong>
P     I    N
A   L S  I G
Y A   H R
P     I
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;A&quot;, numRows = 1
<strong>Output:</strong> &quot;A&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 1000</code></li>
	<li><code>s</code> consists of English letters (lower-case and upper-case), <code>&#39;,&#39;</code> and <code>&#39;.&#39;</code>.</li>
	<li><code>1 &lt;= numRows &lt;= 1000</code></li>
</ul>

from math import ceil
class Solution:
    def convert(self, s: str, numRows: int) -> str:
        rows = numRows
        colpart = rows + max(0, rows - 2)
        cols = max(1,(rows - 1)) * len(s) // colpart
        cols += ceil((len(s) % colpart  / rows))
        #print(colpart)
        #print(cols)
        #print(rows)
        #s.pop(1)
        arr = [['' for i in range(cols)] for j in range(rows)]
        def colf(n):
            if n == 0:
                return 0
            else:
                m = n - 1
                if m % max(1,(2*(rows - 1))) <= rows - 2:
                   # print(f'n is {n}')
                    return colf(n-1)
                else:
                    return colf(n-1) + 1
        def rowf(n):
            ob = [i for i in range(rows)]
            oc = ob[1:len(ob)-1]
            oc.reverse()
            ob = ob + oc
            return ob[n % len(ob)]

        def coord(n):
            return (rowf(n), colf(n))
        for i in enumerate(s):
            #print(i[0])
            rindex, cindex = coord(i[0])
            #print(f'we added {i[1]} to row {rindex}, col {cindex}')
            arr[rindex][cindex] = i[1]

        #print(colf(8))
#        for i in enumerate(s):
        #print(colf(9))
        out = ''
        for i in arr:
            for j in i:
                out += j
        #print(arr)

        return out
    
21000