Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2016 03:33
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 anonymous/362f51312f48ff9b8f3496d5f04fde92 to your computer and use it in GitHub Desktop.
Save anonymous/362f51312f48ff9b8f3496d5f04fde92 to your computer and use it in GitHub Desktop.
def repeated_permutations(n, set)
set_chars = set.chars
(n - 1).times.reduce(set_chars) { |acc, n|
set_chars.flat_map { |c|
acc.map { |k| k + c }
}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment