Sha256: 3a1b954932753a9345efed1c849bd15bd9dc5e74ee4a069e5b28b10e4521c61c

Contents?: true

Size: 547 Bytes

Versions: 176

Compression:

Stored size: 547 Bytes

Contents

object Series {
  private def digits(s: String): List[Int] = s.filter(_.isDigit).map(_.asDigit).toList

  private def slices(n: Int, digits: List[Int]): List[List[Int]] =
    digits.tails.filter(xs => xs.length >= n).map(_.take(n)).toList

  def largestProduct(n: Int, s: String): Option[Int] =
    if (n < 0)
      None
    else {
      val ds = digits(s)
      if (ds.length < s.length)
        None
      else {
        slices(n, ds) match {
          case Nil => None
          case xs => Some(xs.map(_.product).max)
        }
      }
    }
}

Version data entries

176 entries across 176 versions & 1 rubygems

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