Created
November 21, 2013 15:22
-
-
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]
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
| 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