Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Last active November 14, 2015 23:37
Show Gist options
  • Save seanhandley/0e90297449598b14e74f to your computer and use it in GitHub Desktop.
Save seanhandley/0e90297449598b14e74f to your computer and use it in GitHub Desktop.
Einstein 1: Ruby's Array#permutation Method
colors = [:white, :yellow, :blue, :red, :green].permutation
# => #<Enumerator: [:white, :yellow, :blue, :red, :green]:permutation>
colors = [:white, :yellow, :blue, :red, :green].permutation.to_a[0]
# => [:white, :yellow, :blue, :red, :green]
colors = [:white, :yellow, :blue, :red, :green].permutation.to_a[1]
# => [:white, :yellow, :blue, :green, :red]
colors = [:white, :yellow, :blue, :red, :green].permutation.to_a[2]
# => [:white, :yellow, :red, :blue, :green]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment