Sha256: 80f6bf9e8a5445f385932366ad32d8e1fa5a33f7e9979b2b68d86a05d43814bc

Contents?: true

Size: 818 Bytes

Versions: 246

Compression:

Stored size: 818 Bytes

Contents

module Diamond
   (rows
   ) where

import Prelude
import Data.Array (drop, replicate, reverse)
import Data.Char (toCharCode)
import Data.Enum (enumFromTo)
import Data.String (fromCharArray, singleton)

spaces :: Int -> String
spaces width = fromCharArray $ replicate width ' '

mkRow :: Int -> Char -> String
mkRow width 'A' = spaces width <> "A" <> spaces width
mkRow width ch = spaces side
                 <> singleton ch
                 <> spaces mid
                 <> singleton ch
                 <> spaces side
  where depth = toCharCode ch - toCharCode 'A'
        side = width - depth
        mid = 2 * depth - 1

rows :: Char -> Array String
rows end = map (mkRow width) chars
  where width = toCharCode end - toCharCode 'A'
        top = enumFromTo 'A' end
        chars = top <> (reverse top # drop 1)

Version data entries

246 entries across 246 versions & 1 rubygems

Version Path
trackler-2.1.0.0 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.0.8.55 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.0.8.54 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.0.8.53 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.0.8.52 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.0.8.51 tracks/purescript/exercises/diamond/examples/src/Diamond.purs