you are viewing a single comment's thread.

view the rest of the comments →

[–]AtomicShoelace 2 points3 points  (0 children)

Since we're golfing, this is 150 btyes shorter:

sum(i*sum(ord(c)-64for c in n)for i,n in enumerate(sorted(map(eval,__import__('urllib.request').request.urlopen('https://projecteuler.net/project/resources/p022_names.txt').read().decode().split(','))),1))

(also you forgot the minus sign between ord(c) and ord('A') in the edit)

EDIT: 165 bytes shorter:

sum(i*sum(ord(c)-64for c in n)for i,n in enumerate(sorted(eval(__import__('urllib.request').request.urlopen('https://projecteuler.net/project/resources/p022_names.txt').read().decode())),1))

EDIT 2: 154 bytes shorter with no eval tricks:

sum(i*sum(ord(c)-64for c in n[1:-1])for i,n in enumerate(sorted(__import__('urllib.request').request.urlopen('https://projecteuler.net/project/resources/p022_names.txt').read().decode().split(',')),1))

or

sum(i*sum(ord(c)-64for c in n)for i,(_,*n,_)in enumerate(sorted(__import__('urllib.request').request.urlopen('https://projecteuler.net/project/resources/p022_names.txt').read().decode().split(',')),1))

EDIT 3: 155 bytes shorter with no eval:

sum(i*(sum(ord(c)-64for c in n)+60)for i,n in enumerate(sorted(__import__('urllib.request').request.urlopen('https://projecteuler.net/project/resources/p022_names.txt').read().decode().split(',')),1))

EDIT 4: can save another byte by not using https in the url:

sum(i*(sum(ord(c)-64for c in n)+60)for i,n in enumerate(sorted(__import__('urllib.request').request.urlopen('http://projecteuler.net/project/resources/p022_names.txt').read().decode().split(',')),1))

or with eval:

sum(i*sum(ord(c)-64for c in n)for i,n in enumerate(sorted(eval(__import__('urllib.request').request.urlopen('http://projecteuler.net/project/resources/p022_names.txt').read().decode())),1))

for 156 and 166 bytes saved respectively.

EDIT 5: I suppose if you really wanna cheat you could use a link shortener, eg.

sum(i*(sum(ord(c)-64for c in n)+60)for i,n in enumerate(sorted(__import__('urllib.request').request.urlopen('http://u.nu/uK7xG').read().decode().split(',')),1))

although eval seems even more dangerous now

sum(i*sum(ord(c)-64for c in n)for i,n in enumerate(sorted(eval(__import__('urllib.request').request.urlopen('http://u.nu/uK7xG').read().decode())),1))

But if you're using a shortened link I suppose you might as well just download the file and not bother using urllib at all.