Skip to content

Instantly share code, notes, and snippets.

@Gankra Gankra/gist:7089195
Last active Dec 26, 2015

Embed
What would you like to do?
How to code like a second year
Pseudocode iterative implementation of the recursive algorithm:
G(n) =
if(n>4)
doPair(n-1, n)
G(n-1)
doPair(n-1, n)
else
doBaseCase()
void function(n){
int cond = n - ((2n - 4) - n) //yes, this evaluates to "4".
int x = 0;
int m = n;
while(n>cond){
if(n==4){
doBaseCase()
}
doPair(n-1, n)
n--
x++
}
if(n==4){
doBaseCase()
}
while(x>0){
doPair(m-x, m-x-1)
x--
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.