Skip to content

Instantly share code, notes, and snippets.

@aalvesjr
Created August 12, 2011 19:39
Show Gist options
  • Save aalvesjr/1142815 to your computer and use it in GitHub Desktop.
Save aalvesjr/1142815 to your computer and use it in GitHub Desktop.
google-code
numeros = 0
consecutivos = %W(11 22 33 44 55 66 77 88 99 00)
# numeros.txt => http://commondatastorage.googleapis.com/brazil-devrel/numeros.txt
a = File.open 'numeros.txt'
a.each_line do |number|
# Testa para ver se tem consecutivos
boolean_consec = false
consecutivos.each do |n|
boolean_consec = true if number.include? n
end
# Testa se o primeiro e o ultimo são iguais
boolean_pri_ult = false
boolean_pri_ult = true if number[0] == number[5]
# Testa se é par
boolean_par = false
somaTemp = number[0].to_i + number[1].to_i + number[2].to_i + number[3].to_i + number[4].to_i + number[5].to_i
boolean_par = true if somaTemp%2 == 0
# Confere os resultados e incrementa a variavel
numeros += 1 if !boolean_consec and boolean_par and !boolean_pri_ult
end
# Exibe o resultado
puts numeros
# => 54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment