Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor edit, just moving things around.

  • Loading branch information...
commit bfb94f92643bcaf522d0f05ba3cc41a99850b97b 1 parent 68d070d
@agargiulo authored
Showing with 50 additions and 50 deletions.
  1. +50 −50 src/Problem022.java
View
100 src/Problem022.java
@@ -6,6 +6,7 @@
/**
* **SOLVED**
+ *
* @author Anthony Gargiulo
* @version 1.0
* Euler Project
@@ -25,55 +26,54 @@
public class Problem022
{
- /**
- * @param args
- * @throws FileNotFoundException
- */
- public static void main(String[] args) throws FileNotFoundException
- {
- File names = new File("names.txt");
- Scanner in;
- try
- {
- in = new Scanner(names);
- in.useDelimiter(",");
- } catch (FileNotFoundException e)
- {
- System.err
- .println("Cannot find file \"names.txt\"."
- + "Please make sure that you placed it in the correct directory");
- return;
- }
- ArrayList<String> nameList = new ArrayList<String>(6000);
- while (in.hasNext())
- {
- String name = in.next();
- name = name.substring(1, name.length() - 1);
- if (!name.trim().equals(""))
- {
- nameList.add(name);
- }
- }
- Collections.sort(nameList);
- long sum = 0;
- for (int i = 0; i < nameList.size(); i++)
- {
- long score = calcNameScore(nameList.get(i), i + 1);
- sum += score;
- }
- System.out.println("Sum: " + sum);
- }
+ private static long calcNameScore(String name, int index)
+ {
+ char[] letters = name.toCharArray();
+ long score = 0;
+ for (char c : letters)
+ {
+ // the +1 is to fix the fact that 'A' - 'A' = 0
+ score += c - 'A' + 1;
+ }
+ score *= index;
+ return score;
+ }
- private static long calcNameScore(String name, int index)
- {
- char[] letters = name.toCharArray();
- long score = 0;
- for (char c : letters)
- {
- // the +1 is to fix the fact that 'A' - 'A' = 0
- score += c - 'A' + 1;
- }
- score *= index;
- return score;
- }
+ /**
+ * @param args
+ */
+ public static void main(String[] args)
+ {
+ File names = new File("names.txt");
+ Scanner in;
+ try
+ {
+ in = new Scanner(names);
+ in.useDelimiter(",");
+ } catch (FileNotFoundException e)
+ {
+ System.err
+ .println("Cannot find file \"names.txt\"."
+ + "Please make sure that you placed it in the correct directory");
+ return;
+ }
+ ArrayList<String> nameList = new ArrayList<String>(6000);
+ while (in.hasNext())
+ {
+ String name = in.next();
+ name = name.substring(1, name.length() - 1);
+ if (!name.trim().equals(""))
+ {
+ nameList.add(name);
+ }
+ }
+ Collections.sort(nameList);
+ long sum = 0;
+ for (int i = 0; i < nameList.size(); i++)
+ {
+ long score = calcNameScore(nameList.get(i), i + 1);
+ sum += score;
+ }
+ System.out.println("Sum: " + sum);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.