tlienart / tlienart.github.io

Code for my website, powered by Franklin.jl
https://tlienart.github.io
9 stars 5 forks source link

Future things to write on #31

Open tlienart opened 5 years ago

tlienart commented 5 years ago

optim

stats/ml

tlienart commented 2 years ago

interview question perm:

def perm(l: list):
    m = len(l)
    if m == 2:
        return [[l[0], l[1]], [l[1], l[0]]]
    else:
        r = []
        for i in range(m):
            p = perm(l[:i] + l[i+1:])
            for j in range(len(p)):
                r += [[l[i]] + p[j]]
        return r

might be improvable (if anything it should be possible just to write the numbers and have basically no memory requirement, another thing is that we end up calling perm for a list of size (m) multiple times as opposed to using the permutation multiple times which would be more efficient maybe.