Skip to content

Instantly share code, notes, and snippets.

@JRiggles
Last active September 14, 2021 17:51
Show Gist options
  • Save JRiggles/4814961a48f70613a6205c9c45ea42a1 to your computer and use it in GitHub Desktop.
Save JRiggles/4814961a48f70613a6205c9c45ea42a1 to your computer and use it in GitHub Desktop.
Takes an input array and pairs each element with another from the array. Elements cannot be paired with themselves.
a = %w[A B C D E F G H]
a.shuffle!.zip(a.rotate).sort.each { |k,v| puts "#{k}=>#{v}" }
# example return value:
# A=>E
# B=>D
# C=>A
# D=>H
# E=>B
# F=>C
# G=>F
# H=>G
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment