Skip to content

Instantly share code, notes, and snippets.

@thehenster thehenster/colours.rb
Last active Aug 29, 2015

What would you like to do?
A ruby version of the Haskell colour problem in seven languages in seven weeks
def colour_combinations(colours=[])
colours.flat_map{|x| colours.flat_map{|y| x <= y ? [[x, y]] : [] } }
require 'minitest/autorun'
require 'minitest/unit'
class TestColours < MiniTest::Unit::TestCase
def test_colour_combinations
colours = ["black", "white", "blue", "yellow", "red"]
combinations = colour_combinations(colours)
assert combinations.include?(["black", "black"])
assert combinations.include?(["black", "blue"])
refute combinations.include?(["blue", "black"])
assert_equal 15, combinations.size
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.