Sha256: e8069e2fd68afdb55cc93af79f4a3a233fdbc65da16613da090529a44e6d19b9

Contents?: true

Size: 451 Bytes

Versions: 46

Compression:

Stored size: 451 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

46 entries across 46 versions & 1 rubygems

Version Path
trackler-2.2.1.59 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.58 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.57 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.56 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.55 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.54 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.53 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.52 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.51 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.50 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.49 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.48 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.47 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.46 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.45 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.44 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.43 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.42 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.41 tracks/pony/exercises/difference-of-squares/example.pony
trackler-2.2.1.40 tracks/pony/exercises/difference-of-squares/example.pony