Package net.n1da.dev.euler
Class PE0017
- java.lang.Object
-
- net.n1da.dev.euler.core.Problem
-
- net.n1da.dev.euler.PE0017
-
- All Implemented Interfaces:
Solvable
public class PE0017 extends Problem
Solution for problem 17 "Number letter counts" completed on Sat, 16 May 2015, 06:13.- Since:
- 14.05.2015 21:18:29
- Author:
- Nico Danneberg
- See Also:
- Problem @ Project Euler, Solution @ Ni-Da-Net
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Hashtable<java.lang.Integer,java.lang.Integer>
Cache
Local cache for all found lengths.private java.util.Hashtable<java.lang.Integer,java.lang.String>
SpokenNumbers
Stores the words for some basic numbers.
-
Method Summary
Modifier and Type Method Description private int
getLetterCount(int num)
Calculates the number of letters in the written version of the given number.void
prepare()
During preparation of this problem a list of words for number from 1 to 19, 20, 30, 40 ... 90, 100, and 1000 is created.java.lang.String
solve()
Runs a loop from 1 to 1000 to get the number of letters in the written version for every number.-
Methods inherited from class net.n1da.dev.euler.core.Problem
finish, getResult, getRuntime, toString
-
-
-
-
Method Detail
-
prepare
public void prepare()
During preparation of this problem a list of words for number from 1 to 19, 20, 30, 40 ... 90, 100, and 1000 is created.
-
solve
public java.lang.String solve()
Runs a loop from 1 to 1000 to get the number of letters in the written version for every number. The result for a number is stored on the localCache
to make the work a little quicker.- Returns:
- the sum of all letters for every number from 1 to 1000
- See Also:
getLetterCount(int)
-
getLetterCount
private int getLetterCount(int num)
Calculates the number of letters in the written version of the given number. If a number is already stored on the localCache
this count is used.- Parameters:
num
- the number to count the letters- Returns:
- the number of letters
-
-