Created
January 6, 2015 11:28
-
-
Save d3ep4k/73a2917baa13b65ba010 to your computer and use it in GitHub Desktop.
Paper folding problem - Folding paper n times
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
P indicates peak and V indicates a valley