Skip to content

Instantly share code, notes, and snippets.

@aaronfeng
Created August 13, 2011 04:36
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 aaronfeng/1143485 to your computer and use it in GitHub Desktop.
Save aaronfeng/1143485 to your computer and use it in GitHub Desktop.
project euler #22
# 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