Sha256: 9046fa19e6b61f1cee3594429aa811e0990d92e87c5e911ddd4069c789cad4e8

Contents?: true

Size: 617 Bytes

Versions: 142

Compression:

Stored size: 617 Bytes

Contents

case class PalindromeProducts(minFactor: Int, maxFactor: Int) {

  lazy val (smallest: Option[(Int, Set[(Int, Int)])],
            largest: Option[(Int, Set[(Int, Int)])]) = {
    val palindromes = for (a <- Range(minFactor, maxFactor + 1);
                           b <- Range(a, maxFactor + 1) if isPalindrome(a * b)) yield (a * b, (a, b))
    val mapped = palindromes.groupBy(_._1).map{case(k, v) => (k, v.map(_._2).toSet)}
    if (mapped.isEmpty)
      (None, None)
    else
      (Some(mapped.minBy(_._1)), Some(mapped.maxBy(_._1)))
  }

  private def isPalindrome(i: Int) = i.toString == i.toString.reverse
}

Version data entries

142 entries across 142 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.179 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.178 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.177 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.176 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.175 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.174 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.173 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.172 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.171 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.170 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.169 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.167 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.166 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.165 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.164 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.163 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.162 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.161 tracks/scala/exercises/palindrome-products/example.scala
trackler-2.2.1.160 tracks/scala/exercises/palindrome-products/example.scala