Skip to content

Instantly share code, notes, and snippets.

@bjartwolf
Created February 7, 2015 22:55
Show Gist options
  • Save bjartwolf/ecb5371df0452cf0d851 to your computer and use it in GitHub Desktop.
Save bjartwolf/ecb5371df0452cf0d851 to your computer and use it in GitHub Desktop.
let R2 n =
let xs = [-n .. n]
seq { for x in xs do for y in xs do yield x,y }
let TaxicabNorm (x, y) = abs x + abs y
let radius = 10
let indexedLetters =
['A' .. 'Z'] |> Seq.mapi (fun i l -> i,l)
let findLetter xcord =
let i,l = Seq.find(fun (i, l) -> i = abs xcord) indexedLetters
l
let diamond = (R2 radius)
|> Seq.filter (fun x -> TaxicabNorm x = radius)
|> Seq.map( fun (x, y) -> (x,y),findLetter x)
let whiteLines n =
let xs = [|-n .. n|]
[| for i in -n .. n -> (Array.map (fun _ -> '.') xs) |]
let drawing = whiteLines radius
for point in diamond do
let (x,y), letter = point
let yindex = Array.findIndex (fun elem -> y = elem) [|-radius .. radius|]
let xindex = Array.findIndex (fun elem -> x = elem) [|-radius .. radius|]
drawing.[xindex].[yindex] <- letter
let printArray (arr: char array) = new string (arr) |> sprintf "%A" |> Dump
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