Skip to content

Instantly share code, notes, and snippets.

@budnik
Last active August 29, 2015 14:02
Show Gist options
  • Save budnik/4cb21a83f76cdbc69501 to your computer and use it in GitHub Desktop.
Save budnik/4cb21a83f76cdbc69501 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup 2013 Hackathon – Beautiful Strings
#!/usr/bin/env ruby
# Solution to https://www.codeeval.com/open_challenges/83/
# Worst code ever! One should never use an onliner and perlisms on commercial software.
ARGF.each_line do |l|
w=(1..26).to_a
puts l.downcase.gsub(/[^a-z]+/,'').each_char.group_by(&:to_sym).sort_by{|k,v|-v.size}.map{|f|f.last.size*w.pop}.reduce(:+)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment