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.20 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.19 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.18 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.17 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.16 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.15 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.14 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.13 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.12 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.11 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.10 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.9 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.8 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.7 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.6 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.5 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.4 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.3 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.2 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.1.0.1 tracks/purescript/exercises/diamond/examples/src/Diamond.purs