Skip to content

Instantly share code, notes, and snippets.

@vtno
Created January 26, 2024 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtno/75cb9cd99e0de42290f6e8a5ead91bc7 to your computer and use it in GitHub Desktop.
Save vtno/75cb9cd99e0de42290f6e8a5ead91bc7 to your computer and use it in GitHub Desktop.
cities = ['BANGKOK', 'ALGIERS', 'ISTANBUL', 'NASSAU', 'JEDDAH', 'WINNIPEG', 'GUATEMALA CITY', 'YASUJ', 'EDMONTON', 'FECAMP', 'ROME', 'PLOVDIV', 'OSAKA', 'UTRECHT', 'DAR ES SALAAM', 'KUALA LUMPUR',
'MAZAR E SHARIF', 'SHANGHAI', 'TOKYO', 'LUCKNOW', 'HYDERABAD']
current = cities.shift
until cities.empty?
cities.each_with_index do |city, index|
if city[0] == current[-1]
current = city
cities.delete_at(index)
end
end
end
p cities.first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment