Commit 6c1fb468 authored by whzecomjm's avatar whzecomjm
Browse files

add SYTs notebook

parent a6b815f9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,4 +20,4 @@ def RSK(p):
        insert(int(p[i]), i+1)
    return (P,Q)

print(RSK('1364752'))
print(RSK('23514'))
+38 −0
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
## cf. MO Implementation of the Robinson-Schensted Correspondence
## https://mathoverflow.net/questions/30910/implementation-of-the-robinson-schensted-correspondence

from bisect import bisect
def RSK(p):
    '''Given a permutation p, spit out a pair of Young tableaux'''
    P = []; Q = []
    def insert(m, n=0):
        '''Insert m into P, then place n in Q at the same place'''
        for r in range(len(P)):
            if m > P[r][-1]:
                P[r].append(m); Q[r].append(n)
                return
            c = bisect(P[r], m)
            P[r][c],m = m,P[r][c]
        P.append([m])
        Q.append([n])

    for i in range(len(p)):
        insert(int(p[i]), i+1)
    return (P,Q)

print(RSK('23514'))
print(RSK('41253'))
```

%% Output

    ([[1, 3, 4], [2, 5]], [[1, 2, 3], [4, 5]])
    ([[1, 2, 3], [4, 5]], [[1, 3, 4], [2, 5]])

%% Cell type:code id: tags:

``` python
```