Skip to content

Instantly share code, notes, and snippets.

@koffeinfrei
Last active December 11, 2015 11:48
Show Gist options
  • Save koffeinfrei/4596183 to your computer and use it in GitHub Desktop.
Save koffeinfrei/4596183 to your computer and use it in GitHub Desktop.
3 char combinations (of my name)
# try pairs of 2
def pairs_of_2(names)
slices = names.join.scan(/.{2}/)
combinations(slices)
end
# try each chars
def pairs_of_chars(names)
chars = names.join.chars.to_a.uniq
combinations(combinations(chars))
end
def combinations(slices)
slices.product(slices).map {|x| x.join[0..2]}.uniq
end
names = %w(alexis reigel)
#puts pairs_of_2 names
puts pairs_of_chars names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment