Skip to content

Instantly share code, notes, and snippets.

@cmbrown1598
Created October 13, 2017 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbrown1598/bb5a06b51be9ae28cc91c8c4e22a97dd to your computer and use it in GitHub Desktop.
Save cmbrown1598/bb5a06b51be9ae28cc91c8c4e22a97dd to your computer and use it in GitHub Desktop.
The Diamond Kata
open System
let diamond char =
let chars = [ 'A' .. char ]
let numberOfChars = List.length chars
let padCount i = numberOfChars - (i + 1)
let gridWidth = numberOfChars * 2 - 1
let pad i = new string (' ', i)
let init = chars |> List.mapi (fun i c -> (string c), (padCount i))
let all = init @ (List.tail (List.rev init))
let makeLine (str,padCount) =
match gridWidth - (padCount * 2 + 1) with
| 0 -> pad padCount + str + pad padCount
| a -> pad padCount + str + pad (a - 1) + str + pad padCount
all |> List.map makeLine
|> List.reduce (fun x y -> sprintf "%s%s%s" x Environment.NewLine y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment