Skip to content

Instantly share code, notes, and snippets.

@bcamarda
Created June 30, 2012 23:31
Show Gist options
  • Save bcamarda/3026028 to your computer and use it in GitHub Desktop.
Save bcamarda/3026028 to your computer and use it in GitHub Desktop.
Everlane Problem
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment