Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Created March 16, 2017 17:17
Show Gist options
  • Save SteveGilham/ca75810bb7b588905c80e4d1dfc26931 to your computer and use it in GitHub Desktop.
Save SteveGilham/ca75810bb7b588905c80e4d1dfc26931 to your computer and use it in GitHub Desktop.
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