Skip to content

Instantly share code, notes, and snippets.

@yaauie yaauie/README.md
Last active Feb 9, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.