Skip to content

Instantly share code, notes, and snippets.

@yaauie
Last active February 9, 2017 20:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaauie/fdee844834a8510e9c8890b1444fceb8 to your computer and use it in GitHub Desktop.
Save yaauie/fdee844834a8510e9c8890b1444fceb8 to your computer and use it in GitHub Desktop.
A simple command-line tool for creating randomised pairings, written in Ruby.

Rando-Pair

It creates randomised pairings from the given inputs.

Examples:

Simple:

╭─{ yaauie@durin:~ }
╰─● rando-pair Alice Bob Charlie Donald Evelyn Frank Gertrude
Donald + Charlie
Alice + Evelyn
Bob + Frank
Gertrude
[success]

If your first-names aren't unique, simply quote or escape the names that have whitespace:

╭─{ yaauie@durin:~ }
╰─● rando-pair Alice "Bob A" "Bob B" Charlie Donald Evelyn Frank Gertrude
Alice + Bob A
Evelyn + Frank
Bob B + Charlie
Gertrude + Donald
[success]
╭─{ yaauie@durin:~ }
╰─● rando-pair Alice Bob\ A Bob\ B Charlie Donald Evelyn Frank Gertrude
Evelyn + Frank
Donald + Charlie
Bob B + Alice
Bob A + Gertrude
[success]
#!/usr/bin/env ruby
# rando-pair: create randomised pairings.
#
# USAGE:
# - list the participants as arguments to the command line:
# ~~~
# $ rando-pair name...
# ~~~
#
# - rando-pair will read a list of participants from stdin if you give it a
# single `-`:
# ~~~
# $ pbpaste | rando-pair -
# ~~~
items = (ARGV == ['-'] ? $stdin.read.lines.map(&:chomp) : ARGV).to_a
$stdout.puts items.shuffle
.each_slice(2)
.map { |pair| pair.join(' + ') }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment