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.2.1.180 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.179 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.178 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.177 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.176 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.175 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.174 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.173 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.172 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.171 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.170 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.169 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.167 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.166 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.165 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.164 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.163 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.162 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.161 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.160 tracks/purescript/exercises/diamond/examples/src/Diamond.purs