Last active
August 29, 2015 13:57
-
-
Save thehenster/9374235 to your computer and use it in GitHub Desktop.
A ruby version of the Haskell colour problem in seven languages in seven weeks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def colour_combinations(colours=[]) | |
colours.flat_map{|x| colours.flat_map{|y| x <= y ? [[x, y]] : [] } } | |
end | |
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 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment