Skip to content

Instantly share code, notes, and snippets.

@wrathematics
Created May 2, 2014 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrathematics/4a4ac5450681c041a7c0 to your computer and use it in GitHub Desktop.
Save wrathematics/4a4ac5450681c041a7c0 to your computer and use it in GitHub Desktop.
Printing strings "a" to "zzzzz"
# 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