Created
August 13, 2011 04:36
-
-
Save aaronfeng/1143485 to your computer and use it in GitHub Desktop.
project euler #22
This file contains 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
# http://projecteuler.net/index.php?section=problems&id=22 | |
BEGIN {RS=",";} | |
{ | |
gsub(/"/, "", $1); | |
names[NR] = $1 | |
} | |
END { | |
table="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
asort(names); | |
for(i = 1; i <= length(names); i += 1) { | |
worth = 0; | |
for(j = 1; j <= length(names[i]); j += 1) { | |
worth = worth + index(table, substr(names[i],j,1)); | |
} | |
total += worth * i; | |
} | |
print total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment