Skip to content

Instantly share code, notes, and snippets.

@danielbonnell
Created October 21, 2014 21:04
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 danielbonnell/25d96b54a8a2b2c0c1dc to your computer and use it in GitHub Desktop.
Save danielbonnell/25d96b54a8a2b2c0c1dc to your computer and use it in GitHub Desktop.
Mini Golf Challenge
def display_scores(file)
num = 1
rankings = Hash.new
File.open(file).each_line do |line|
total = 0
line = line.split(',')
name = line.shift
line.each do |strokes|
total += strokes.to_i
end
rankings[name] = total
end
rankings = rankings.sort { |a, b| b[1] <=> a[1] }
puts "Mini Golf Scores\n\n"
rankings.reverse.each do |k, v|
puts "#{num}. #{k} with #{v} strokes."
num += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment