Skip to content

Instantly share code, notes, and snippets.

@oyvindkinsey
Created January 26, 2013 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oyvindkinsey/4640228 to your computer and use it in GitHub Desktop.
Save oyvindkinsey/4640228 to your computer and use it in GitHub Desktop.
var input = 'ABbCcc\n\
Good luck in the Facebook Hacker Cup this year!\n\
Ignore punctuation, please :\n)\
Sometimes test cases are hard to make up\n.\
So I just go consult Professor Dalves';
input.split('\n').forEach(function(line) {
console.log(
line,
line
.toLowerCase()
.replace(/[^a-z]/g, '')
.split('')
.reduce(function(p, c) {
p[c.charCodeAt(0)] = (p[c.charCodeAt(0)] || 0) + 1;
return p;
}, [])
.filter(function(v) {
return v;
})
.sort()
.reverse()
.reduce(function(p, c, i) {
return p + (26 - i) * c;
}, 0)
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment