Sha256: 73fc3c07c851b2ada224a6622e2c4d181dbc68b0f1d71610d281753fff280a1e

Contents?: true

Size: 481 Bytes

Versions: 165

Compression:

Stored size: 481 Bytes

Contents

use "collections"
use "itertools"

primitive PascalsTriangle
  fun rows(count: USize): Array[Array[USize]] =>
    Iter[USize](Range(0, count))
      .map[Array[USize]]({(n: USize): Array[USize] => PascalsTriangle.row(n) })
      .collect(Array[Array[USize]](count))

  fun row(n: USize): Array[USize] =>
    let r = Array[USize](n) .> push(1)
    for i in Range(1, n + 1) do
      try
        let last = r(i - 1)?
        r.push((last * ((n + 1) - i)) / i)
      end
    end
    r

Version data entries

165 entries across 165 versions & 1 rubygems

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