Ejemplo n.º 1
0
 private static int perimeterUpTo1000WithMaximisedNumberOfSolutions() {
   return SOLUTIONS_FOR_PERIMETERS_UP_TO_1000
       .map((perimeter, listOfSolutions) -> Tuple.of(perimeter, listOfSolutions.length()))
       .maxBy(Tuple2::_2)
       .get()
       ._1;
 }
Ejemplo n.º 2
0
  /**
   * <strong>Problem 39 Integer right triangles</strong>
   *
   * <p>If <i>p</i> is the perimeter of a right angle triangle with integral length sides,
   * {<i>a,b,c</i>}, there are exactly three solutions for <i>p</i> = 120.
   *
   * <p>{20,48,52}, {24,45,51}, {30,40,50}
   *
   * <p>For which value of <i>p</i> ≤ 1000, is the number of solutions maximised?
   *
   * <p>See also <a href="https://projecteuler.net/problem=39">projecteuler.net problem 39</a>.
   */
  @Test
  public void shouldSolveProblem39() {
    assertThat(SOLUTIONS_FOR_PERIMETERS_UP_TO_1000.get(120))
        .isEqualTo(some(List.of(Tuple.of(20, 48, 52), Tuple.of(24, 45, 51), Tuple.of(30, 40, 50))));

    assertThat(perimeterUpTo1000WithMaximisedNumberOfSolutions()).isEqualTo(840);
  }