Project Euler – Problem 22

Problem 22: Using names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.

What is the total of all the name scores in the file?

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class runner
{
	public static void main (String[] args) throws java.lang.Exception
	{
		long time = System.currentTimeMillis();
		String[] names = {"list of names from http://archiver.joshho.com/display.php?full=1&q=https://projecteuler.net/project/names.txt"};
		
		int sum = 0;
		List list = new ArrayList();
		for(String name: names){
			list.add(name);
		}
		Collections.sort(list);
		for(int i = 0; i< list.size(); i++){
			String name = list.get(i);
			int score = 0;
			for(int j = 0; j < name.length(); j++){
				score += (name.charAt(j)-64);
			}
			sum += score * (i+1);
		}
		
		System.out.println(sum);
		
		System.out.println("time: "+(System.currentTimeMillis() - time));
	}
}