Skip to content

Instantly share code, notes, and snippets.

@Rodel30
Created Nov 4, 2016
Embed
What would you like to do?
Ruby solution for CFML Slack Friday Puzzle
require 'open-uri'
require 'json'
data = JSON.load(open("https://gist.githubusercontent.com/ryanguill/036a35ad8cc07bf600b25212eacc3ced/raw/4c5f67ecc4993c09f5776c8b0144020beda798e6/karma.json"))
counts_by_user = data.each_with_object(Hash.new(0)){|k,counts| counts[k['user']] += 1 }
users_by_score = counts_by_user.group_by{|k,v| v }
top_scores = users_by_score.keys.sort.reverse.first(10)
top_scores.each_with_index do |k, place|
puts "[ ##{place + 1} @ #{k}k ]: #{users_by_score[k].map{|u| u[0] }.join(', ')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment