TOPIC

Runtime error - Dúvida

lucas fernandes asked 1 year ago

Estou enfrentando problema de runtime error. Creio eu que deve ser pela versão do ruby utilizada pelo site. Alguém sabe me dizer qual versão o site usa para compilar? Sabendo isso eu consigo "codar" com a versão do site e evitar esses problemas.

Segue cod.

# Exercise
# https://www.urionlinejudge.com.br/judge/pt/problems/view/1249

def ask_for_message
  puts "Hello hunny bunny! Type the message you wanna to be coded:"
  secret_message = gets(nil).strip
end

def print_result(result)
  result.each { |r| print r }
  puts
end

def code_letter(letter)
  has_letter_downcase = @alphabet_upsidedown.key?(letter)
  has_letter_upcase = @alphabet_upsidedown.key?(letter.downcase)
  if has_letter_downcase
    @alphabet_upsidedown[letter]
  elsif has_letter_upcase
    @alphabet_upsidedown[letter.downcase].upcase
  else
    letter
  end
end

def code_message(message)
  coded_message = []
  message.chars.each { |letter_message| coded_message << code_letter(letter_message) }
  coded_message
end

@alphabet = Array("a".."z")
@alphabet_upsidedown = @alphabet.zip(@alphabet.rotate(13)).to_h

secret_message = ask_for_message
result = code_message secret_message
print_result result

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.