Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
open System.Linq
type Cell = North | East | Root
let rows = 10
let cols = 10
let rand = System.Random()
let row () = (Seq.singleton Root)
|> Seq.append (Enumerable.Repeat(East, cols - 1))
let maingrid() = Enumerable.Repeat(row(), rows - 1)
let grid = (row() |> Seq.toList) ::
(maingrid ()
|> Seq.map (fun r -> r |> Seq.map (fun cell -> match cell with
| Root -> North
| East when rand.Next(2) = 1 -> North
| _ -> East)
|> Seq.toList) // row
|> Seq.toList) // grid
grid |> List.iter (fun r -> printf "+"
Seq.iter (fun cell -> match cell with
| North -> printf " "
| _ -> printf "---"
printf "+") r
printfn ""
printf "|"
Seq.iter (fun cell -> match cell with
| East -> printf " "
| _ -> printf " |") r
printfn "")
grid |> List.head |> (fun r -> printf "+"
Seq.iter (fun cell -> printf "---+") r
printfn "" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment