Skip to content

Instantly share code, notes, and snippets.

@vjo
Created November 21, 2013 15:22
Show Gist options
  • Select an option

  • Save vjo/7583447 to your computer and use it in GitHub Desktop.

Select an option

Save vjo/7583447 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup 2013 Qualification Round - Beautiful strings - [https://www.facebook.com/hackercup/problems.php?pid=475986555798659&round=185564241586420]
import re
import operator
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
d = {}
pound = 1
score = 0
str = 'Good luck in the Facebook Hacker Cup this year!'
str = str.lower()
string = re.sub('[^a-z]','',str)
for c in ALPHA:
d[c] = string.count(c)
sorted_d = sorted(d.iteritems(), key=operator.itemgetter(1))
for t in sorted_d:
score = score + t[1] * pound
pound = pound + 1
print score
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment