Created
May 2, 2014 03:14
-
-
Save wrathematics/4a4ac5450681c041a7c0 to your computer and use it in GitHub Desktop.
Printing strings "a" to "zzzzz"
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
# The task: | |
# Print strings from "a" to "zzzzz" without using any loop or conditional statements. Don't just write all 1000 permutations out by hand. The output should look like this: | |
# a | |
# b | |
# c | |
# ... | |
# aa | |
# ab | |
# ac | |
# ... | |
# zzzzx | |
# zzzzy | |
# zzzzz | |
### Full solution --- don't recommend you try running this | |
cat(sapply(letters, function(a) sapply(letters, function(b) sapply(letters, function(c) sapply(letters, function(d) paste(a, b, c, d, letters, "\n", sep="")))))) | |
### A sub-problem that will finish in a reasonable amount of time. It prints "a" to "zzz". | |
cat(sapply(letters, function(a) sapply(letters, function(b) paste(a, b, letters, "\n", sep="")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment