Sha256: 486753152c101ece0de09152d8ee1d20c281f8cb7dceac9d766c49f745cd80f5

Contents?: true

Size: 448 Bytes

Versions: 158

Compression:

Stored size: 448 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 =>
    try
      Iter[USize](Range(0, n + 1))
        .map[USize]({(x: USize): USize => x * x})
        .fold[USize]({(acc: USize, x: USize): USize => acc + x}, 0)
    else
      0
    end

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

Version data entries

158 entries across 158 versions & 1 rubygems

Version Path
trackler-2.2.1.6 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.5 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.4 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.3 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.2 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.1 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.0 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.0.6 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.0.5 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.0.4 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.0.3 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.0.2 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.0.1 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.0.0 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.1.0.55 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.1.0.54 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.1.0.53 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.1.0.52 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.1.0.51 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.1.0.50 tracks/pony/exercises/difference-of-squares/example.pony