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.119 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.118 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.117 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.116 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.115 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.114 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.113 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.111 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.110 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.109 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.108 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.107 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.106 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.105 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.104 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.103 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.102 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.101 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.100 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs
trackler-2.2.1.99 tracks/purescript/exercises/pascals-triangle/examples/src/PascalsTriangle.purs