Sha256: 1a1845abdf7540bf7c025fdad1d93296e41a0c056187ad54cc858e88e69991a4

Contents?: true

Size: 540 Bytes

Versions: 236

Compression:

Stored size: 540 Bytes

Contents

module PascalsTriangle
  (rows
  ) where

import Prelude
import Data.Array (drop, zip, (:))
import Data.Maybe (Maybe(..))
import Data.Tuple (uncurry)

type Row = Array Int
type Mat = Array (Array Int)

rows' :: Row -> Int -> Mat
rows' row 1 = [row]
rows' row n = row : rows' next (n - 1)
  where next = pairSum $ [0] <> row <> [0]
        pairSum r = map (uncurry (+)) (zip r (drop 1 r))

rows :: Maybe Int -> Maybe Mat
rows Nothing = Nothing
rows (Just n)
  | n < 0     = Nothing
  | n == 0    = Just []
  | otherwise = Just $ rows' [1] n

Version data entries

236 entries across 236 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.97 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.96 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.95 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.94 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.93 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.92 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.91 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.90 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.89 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.88 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.87 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.86 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.85 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.84 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.83 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.82 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.81 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.80 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.79 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs