Skip to content

Instantly share code, notes, and snippets.

@willshepp28
Created December 10, 2020 17:55
Show Gist options
  • Save willshepp28/7dda16d1adca2091362e88606f16b3d5 to your computer and use it in GitHub Desktop.
Save willshepp28/7dda16d1adca2091362e88606f16b3d5 to your computer and use it in GitHub Desktop.
# @param {String} command
# @return {String}
def interpret(command)
output = ""
command.split('').each_with_index { |character, idx|
if character == "G"
output += "G"
elsif character == "("
if command[idx + 1] == ")"
output += "o"
elsif command[idx + 1] == "a" && command[idx + 2] = "l" && command[idx + 3] = ")"
output += "al"
end
end
}
return output
end
interpret("G()()()()(al)G")
interpret("(al)G(al)()()G")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment