layout: default title: Problems 61–80 parent: Project Euler parenturl: /translations/projecteuler/ summary: Solutions to Project Euler problems 61 to 80. nav_order: 4 ---

Project Euler: Problems 61–80

{: .no_toc }

{% include toc.html %}

Project Euler: Problems 61–80

Problem 61

Cyclic figurate numbers

Triangular, pentagonal, and hexagonal numbers are generated by the following formulae:

It can be verified that t(28) = p(16) = h(14) = 406.

The sum of these four cyclic numbers is 7283.

Find the sum of the only ordered set of six cyclic 4-digit numbers for which each polygonal type (triangular, pentagonal, hexagonal, square, heptagonal, and octagonal) is represented by exactly one number in the set.

object Problem61 {
  def triangulars: Iterator[Int] = Iterator.from(1).map(n => n * (n + 1) / 2)
  def pentagonals: Iterator[Int] = Iterator.from(1).map(n => n * (3 * n - 1) / 2)
  def hexagonals: Iterator[Int] = Iterator.from(1).map(n => n * (2 * n - 1))
  def squareNumbers: Iterator[Int] = Iterator.from(1).map(n => n * n)
  def heptagonals: Iterator[Int] = Iterator.from(1).map(n => n * (5 * n - 3) / 2)
  def octagonals: Iterator[Int] = Iterator.from(1).map(n => n * (3 * n - 2))

  val cyclic4 = (2000 to 9999).filter { n =>
    n.toString.startsWith(n.toString.take(2)) &&
    n.toString.endsWith(n.toString.takeRight(2))
  }
}

Problem 62

Cubic permutations

The cube, 41063625 (345³), can be permuted to produce two other cubes: 56623104 (384³) and 66430125 (405³). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cubes.

Find the smallest cube for which exactly five permutations of its digits are cubes.

object Problem62 {
  import java.util.Collections

  def digitsKey(n: Int): String =
    n.toString.sorted

  def solve: Int = {
    val cubes = Iterator.from(1).map(n => (digitsKey(n * n * n), n * n * n))
    cubes.groupBy(_._1).collectFirst {
      case (_, group) if group.size == 5 => group.map(_._2).min
    }.get
  }
}

Problems 63–80

For problems 63 through 80, see the individual solution files.