org.shapelogic.euler
Class ProjectEuler1Test

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.shapelogic.euler.ProjectEuler1Test
All Implemented Interfaces:
junit.framework.Test

public class ProjectEuler1Test
extends junit.framework.TestCase

First part of implementation of Project Euler.
See: http://projecteuler.net.

Author:
Sami Badawi

Constructor Summary
ProjectEuler1Test()
           
 
Method Summary
static boolean palindrome(int input)
           
static long productWithPower(java.util.Map<java.lang.Integer,java.lang.Integer> factorsWithPower)
          Calculated the product of factors uplifted to a power.
static int rankOfDivisor(int input, int divisor)
          Number of this the divisor is dividable into the input.
 void testPalindrome()
           
 void testProblem1()
          Problem 1.
 void testProblem10()
          Problem 10.
 void testProblem2()
          Problem 2.
 void testProblem3()
          Problem 3.
 void testProblem4()
          Problem 4.
 void testProblem5()
          Problem 5.
 void testProblem6()
          Problem 6.
 void testProblem7()
          Problem 7.
 void testProblem8()
          Problem 8.
 void testProblem9()
          Problem 9.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProjectEuler1Test

public ProjectEuler1Test()
Method Detail

testProblem1

public void testProblem1()
Problem 1. Add all the natural numbers below 1000 that are multiples of 3 or 5.


testProblem2

public void testProblem2()
Problem 2. Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed one million.


testProblem3

public void testProblem3()
Problem 3. Find the largest prime factor of 317584931803.


testProblem4

public void testProblem4()
Problem 4. Find the largest palindrome made from the product of two 3-digit numbers.


palindrome

public static boolean palindrome(int input)

testPalindrome

public void testPalindrome()

productWithPower

public static long productWithPower(java.util.Map<java.lang.Integer,java.lang.Integer> factorsWithPower)
Calculated the product of factors uplifted to a power.

Parameters:
factorsWithPower - the key is the factor and the value is the power.

rankOfDivisor

public static int rankOfDivisor(int input,
                                int divisor)
Number of this the divisor is dividable into the input.

Parameters:
input - number to test
divisor -
Returns:
number of this the divisor is dividable into the input.

testProblem5

public void testProblem5()
Problem 5. What is the smallest number divisible by each of the numbers 1 to 20? Decompose each number from 2 to 20 into prime factors with rank. Multiply them to get the number.


testProblem6

public void testProblem6()
Problem 6. What is the difference between the sum of the squares and the square of the sums?


testProblem7

public void testProblem7()
Problem 7. Find the 10001st prime.


testProblem8

public void testProblem8()
Problem 8. Discover the largest product of five consecutive digits in the 1000-digit number. This is simple generate a stream of Integer. Accumulate through it looking 5 number back.


testProblem9

public void testProblem9()
Problem 9. Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000. So create a sequence for B from 1 to 500. For each A you could use a sequence from 1 to b. But this is just doing the full Cartesian product. Contraints: a < b c = 1000 - a - b c*c = a*a + b*b


testProblem10

public void testProblem10()
Problem 10. Calculate the sum of all the primes below one million. This takes minutes to run.



Copyright © 2009. All Rights Reserved.