src/main/scala/squares.scala

1
2
3
4
5
6
7
8
9
10
object Squares {
  def apply() = new Squares()
}

class Squares {
  private def square(n: Int) = math.pow(n, 2).toInt
  def sumOfSquares(n: Int) = (1 to n).map(square).sum
  def squareOfSums(n: Int) = square((1 to n).sum)
  def difference(n: Int) = squareOfSums(n) - sumOfSquares(n)
}

@abo64 thinks this looks great

Comments


You're not logged in right now. Please login via GitHub to comment