Created
October 21, 2014 21:04
-
-
Save danielbonnell/25d96b54a8a2b2c0c1dc to your computer and use it in GitHub Desktop.
Mini Golf Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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