Sha256: e49d250d0cd6a869e6e3726cbad52a8c286fc22f76e03d7c61dc145b1b4e29f2

Contents?: true

Size: 288 Bytes

Versions: 41

Compression:

Stored size: 288 Bytes

Contents

import scala.math.pow

class Squares {

  def sumOfSquares(n: Int): Int = n * (n + 1) * (2 * n + 1) / 6

  def squareOfSums(n: Int): Int = pow((n * (n + 1) / 2), 2).toInt

  def difference(n: Int): Int = squareOfSums(n) - sumOfSquares(n)
}

object Squares {
  def apply() = new Squares
}

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
trackler-2.0.5.4 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.5.3 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.5.2 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.5.1 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.5.0 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.4.0 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.9 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.8 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.7 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.6 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.5 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.4 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.3 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.2 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.1 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.3.0 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.2.0 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.1.2 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.1.1 tracks/scala/exercises/difference-of-squares/example.scala
trackler-2.0.1.0 tracks/scala/exercises/difference-of-squares/example.scala