Created
June 22, 2014 02:32
-
-
Save xymor/40fb2e8da90507b01c4c to your computer and use it in GitHub Desktop.
Repenting for my sins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Once upon a time I got an interview with CosmicCart. I had a skype call at 7am but totally forgot about it | |
and went out drinking the previous night. I got home at 4am very drunk, got up at 6:30 with a killing | |
hangover and totally flunked that interview. | |
I finished the 2 element permutation, then he asked me to do the 3 element combination | |
and I couldn't think straight to solve it. | |
This is my repentance. I'll get to the n-element method and cleanse my soul. | |
*/ | |
def lsto = [1,2,3,4] | |
def perm2(out, lst){ | |
if(lst.size() == 1) return out | |
def p1 = lst.pop() | |
lst.each{ | |
out << [p1,it] | |
} | |
return perm2(out, lst) | |
} | |
def perm3(out,pairs,lst){ | |
if(lst.size() == 0) return out; | |
def piv = lst.pop() | |
pairs.each{ | |
if(!(piv in it)){ | |
out << it + piv | |
} | |
} | |
return perm3(out,pairs,lst) | |
} | |
def perm4(groups,lst){ | |
} | |
def permn(n, groups, lst){ | |
} | |
def pairs = perm2([], lsto.clone()) | |
perm3([],pairs,lsto.clone()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment