Created
October 13, 2017 21:27
-
-
Save cmbrown1598/bb5a06b51be9ae28cc91c8c4e22a97dd to your computer and use it in GitHub Desktop.
The Diamond Kata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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