Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def everlane(string)
- new_string = string.gsub(/[bcdefghij]/, "a").gsub(/[MKP]/, "Q")
- test_array = []
- array = new_string.split(//)
- status = "VALID"
- array.length.times do
- current_letter = array.pop
- case current_letter
- when "a"
- if test_array.length > 1
- status = "INVALID"
- else
- test_array << "a"
- end
- when "Z"
- if test_array.length == 0
- status = "INVALID"
- else
- test_array << "Z" + test_array.pop
- end
- when "Q"
- if test_array.length < 2
- status = "INVALID"
- else
- test_array << "Q" + test_array.pop + test_array.pop
- end
- else
- status = "INVALID"
- end
- end
- if test_array.length != 1
- status = "INVALID"
- end
- puts "#{string} #{status}"
- end
- everlane("QaZZc")
Add Comment
Please, Sign In to add comment