Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created April 18, 2012 13:34
Show Gist options
  • Save shieldsd/2413589 to your computer and use it in GitHub Desktop.
Save shieldsd/2413589 to your computer and use it in GitHub Desktop.
Project Euler #42
from math import sqrt
def istriangle(n):
return (sqrt(8 * n + 1) - 1) / 2 % 1 == 0
words = open('words.txt').readline().replace('"', '').split(',')
print sum(1 for _ in (filter(lambda x: istriangle(x),
(sum(ord(c) - ord('A') + 1 for c in w)
for w in words))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment