Skip to content

Instantly share code, notes, and snippets.

@matthewford
Created September 26, 2013 23:15
Show Gist options
  • Save matthewford/6721936 to your computer and use it in GitHub Desktop.
Save matthewford/6721936 to your computer and use it in GitHub Desktop.
######################################################
# Copyright (c) 2006 Matthew Ford #
# This software is licenced under the CC-GNU GPL #
# http://creativecommons.org/licenses/GPL/2.0/ #
######################################################
class ColoursAlt
pcolours = ["red","blue","green"]
while true #infinite loop
puts "Please enter two primary colours (red, blue or green). To quit press return."
print "First colour: "; STDOUT.flush;
colourA=gets.chop
break if colourA.empty? #exit loop
print "Second colour: "; STDOUT.flush;
colourB=gets.chop
break if colourB.empty? #exit loop
colourA = colourA.downcase #make lowercase
colourB = colourB.downcase
if pcolours.member?(colourA) & pcolours.member?(colourB)
if colourA == colourB
puts "#{colourA} and #{colourB} = #{colourA}."
end
colourmix = colourA + "," + colourB
case colourmix
when /red,blue|blue,red/
puts "#{colourA} and #{colourB} = magenta."
when /red,green|green,red/
puts "#{colourA} and #{colourB} = yellow."
when /blue,green|green,blue/
puts "#{colourA} and #{colourB} = cyan."
end
end
end #end loop
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment