Created
December 3, 2012 21:38
-
-
Save jonasabreu/4198327 to your computer and use it in GitHub Desktop.
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
# Certo... -1 nao compila. Precisa ser - 1 | |
# J => 10, Q => 11, K => 12, A => 13 | |
class Resultado | |
attr_reader :v, :n | |
def initialize(n, v) | |
@v = v | |
@n = n | |
end | |
def >(outro) | |
return true if @n > outro.n | |
return true if @n == outro.n && @v > outro.v | |
false | |
end | |
end | |
class Array | |
def melhor(outra) | |
sort! | |
outra.sort! | |
types = [ lambda { |mao| Resultado.new(0, mao.last) } ] | |
jogos = types.flat_map{ |e| e[self] }.compact.reverse | |
jogosOutra = types.flat_map{ |e| e[outra]}.compact.reverse | |
jogos.zip(jogosOutra).each do |e| | |
return 1 if e[0] > e[1] | |
return 2 if e[1] > e[0] | |
end | |
return "Empate!" | |
end | |
end | |
puts "Vencedor(1): #{["2", "3", "4", "5", "7"].melhor ["2", "3", "4", "5", "6"]}" | |
puts "Vencedor(2): #{["2", "3", "4", "5", "6"].melhor ["2", "3", "4", "5", "7"]}" | |
puts "Vencedor(E): #{["2", "3", "4", "5", "6"].melhor ["2", "3", "4", "5", "6"]}" | |
puts "Vencedor(1): #{["2", "2", "4", "5", "6"].melhor ["2", "3", "4", "5", "6"]}" | |
puts "Vencedor(2): #{["2", "3", "4", "5", "6"].melhor ["2", "2", "4", "5", "6"]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment