Skip to content

Instantly share code, notes, and snippets.

@vralex
Created July 20, 2013 17:53
Show Gist options
  • Save vralex/6045864 to your computer and use it in GitHub Desktop.
Save vralex/6045864 to your computer and use it in GitHub Desktop.
Скрипт для сортировки строк в файле по последнему значению.
res = []
File.open('/Users/VladimirDel/Projects/Ruby/results.txt').each_line do |line|
words = line.split(' ')
res << [line, words[-1].to_i]
end
res.sort_by! { |elem| elem[1]}.reverse!
current = 1
res.each do |elem|
puts "#{current} " + elem[0]
current += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment