Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Algoritmo para Resolver uma Charada por Força Bruta em Ruby
(100..999).each do |x|
(100..999).each do |y|
(100..999).each do |z|
soma = x + y + z
condicao1 = soma.digits.size == 3
condicao2 = soma.digits.uniq.size == 1
n = soma.digits.uniq.first
condicao3 = n == x.digits.first && n == y.digits.first && n == z.digits.first
condicao4 = x.digits.last == y.digits.last && y.digits.last == z.digits.last
condicao5 = x.digits[1] == y.digits[1] && y.digits[1] == z.digits[1]
if condicao1 && condicao2 && condicao3 && condicao4 && condicao5
puts "#{x} + #{y} + #{z} = #{soma}"
end
end
end
end
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.