Problem 42: The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1);
Using this word list, convert each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.
How many are triangle words?
import java.util.Vector;
class runner
{
private static boolean isTriangle(int sum, Vector triangle){
int last = triangle.lastElement();
while(last < sum){
last = triangle.size()*(triangle.size()+1)/2;
triangle.add(last);
}
for(int x : triangle){
if(sum == x) return true;
if(sum < x) return false;
}
return true;
}
public static void main (String[] args) throws java.lang.Exception
{
long time = System.currentTimeMillis();
Vector triangle = new Vector(); triangle.add(1);
String[] in = {"Found @ http://archiver.joshho.com/display.php?full=1&q=http://projecteuler.net/project/words.txt"};
int count = 0;
for(String x : in){
int sum = 0;
for(int i=0; i