Sha256: df0999578dd099e6fde05ce92726aa82b7250ffdfe96443de54711813595338b

Contents?: true

Size: 411 Bytes

Versions: 119

Compression:

Stored size: 411 Bytes

Contents

use "collections"
use "itertools"

primitive Squares
  fun square_of_sums(n: USize): USize =>
    let sum = (n * (n + 1)) / 2
    sum * sum

  fun sum_of_squares(n: USize): USize =>
    Iter[USize](Range(0, n + 1))
      .map[USize]({(x: USize): USize => x * x })
      .fold[USize](0, {(acc: USize, x: USize): USize => acc + x })

  fun difference(n: USize): USize =>
    square_of_sums(n) - sum_of_squares(n)

Version data entries

119 entries across 119 versions & 1 rubygems

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