Guest User

Untitled

a guest
Nov 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. def everlane(string)
  2. new_string = string.gsub(/[bcdefghij]/, "a").gsub(/[MKP]/, "Q")
  3. test_array = []
  4. array = new_string.split(//)
  5. status = "VALID"
  6.  
  7. array.length.times do
  8. current_letter = array.pop
  9. case current_letter
  10. when "a"
  11. if test_array.length > 1
  12. status = "INVALID"
  13. else
  14. test_array << "a"
  15. end
  16. when "Z"
  17. if test_array.length == 0
  18. status = "INVALID"
  19. else
  20. test_array << "Z" + test_array.pop
  21. end
  22. when "Q"
  23. if test_array.length < 2
  24. status = "INVALID"
  25. else
  26. test_array << "Q" + test_array.pop + test_array.pop
  27. end
  28. else
  29. status = "INVALID"
  30. end
  31. end
  32.  
  33. if test_array.length != 1
  34. status = "INVALID"
  35. end
  36.  
  37. puts "#{string} #{status}"
  38. end
  39.  
  40. everlane("QaZZc")
Add Comment
Please, Sign In to add comment