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.139 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.138 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.137 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.136 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.135 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.134 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.133 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.132 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.131 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.130 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.129 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.128 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.127 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.126 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.125 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.124 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.123 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.122 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.121 tracks/purescript/exercises/diamond/examples/src/Diamond.purs
trackler-2.2.1.120 tracks/purescript/exercises/diamond/examples/src/Diamond.purs