-
-
Save einarwh/8f4a8fa32852aa89bc09 to your computer and use it in GitHub Desktop.
Tweaks just because.
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 | |
// We can not work with radius of the diamond outside 0 to 25 | |
let createRadius i = | |
match i with | |
| i when i >= 0 && i < 26 -> Some i | |
| _ -> None | |
let radius = createRadius 20 |> Option.get | |
let axis = [|-radius .. radius|] | |
let TaxicabNorm (x, y) = | |
abs x + abs y | |
let indexedLetters = | |
['A' .. 'Z'] |> Seq.mapi (fun i l -> i,l) | |
let findLetter y = | |
indexedLetters |> Seq.find(fun (i, _) -> i = y) |> snd | |
let createAllPoints vector = | |
seq { for x in vector do for y in vector do yield (x, y) } | |
let diamond = createAllPoints axis |> Seq.filter (fun p -> TaxicabNorm p = radius) | |
let axisTo2D axis = | |
[| for _ in axis -> (Array.map (fun _ -> '.') axis) |] | |
let drawing = axisTo2D axis | |
let findIndexInAxis elem axis = | |
Array.findIndex (fun x -> x = elem) axis | |
for (x, y) in diamond do | |
let yindex = findIndexInAxis y axis | |
let xindex = findIndexInAxis x axis | |
drawing.[xindex].[yindex] <- abs y |> findLetter | |
let printArray (arr: char array) = new string (arr) |> sprintf "%A" |> Console.WriteLine | |
for line in drawing do | |
printArray line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment