Skip to content

Instantly share code, notes, and snippets.

@d3ep4k
Created January 6, 2015 11:28
Show Gist options
  • Save d3ep4k/73a2917baa13b65ba010 to your computer and use it in GitHub Desktop.
Save d3ep4k/73a2917baa13b65ba010 to your computer and use it in GitHub Desktop.
Paper folding problem - Folding paper n times
x = []
def fold(n) {
if (n == 1)
x.add('V')
else {
fold(n-1)
x.add('V')
reverse(n-1)
}
}
void reverse(int n) {
if (n == 1)
x.add('P')
else {
fold(n-1);
x.add('P')
reverse(n-1);
}
}
fold(12);
println x
Collections.reverse(x);
println x
@d3ep4k
Copy link
Author

d3ep4k commented Jan 6, 2015

P indicates peak and V indicates a valley

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment