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.119 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.118 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.117 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.116 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.115 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.114 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.113 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.111 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.110 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.109 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.108 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.107 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.106 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.105 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.104 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.103 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.102 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.101 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.100 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.99 tracks/pony/exercises/difference-of-squares/example.pony