5 people like it.
Like the snippet!
Optimal Cloud Coloring & famous 4 color map
Four colors will print a map so adjacent states have different color. F# has clear concise code. Map has a list of pairs sharing a border. Incremental improvements in the code can be less use of key word 'function'. Since syntax is not ambiguous can it be fixed in the compiler? so '=function |' changes to '=|' ? Welcome to improve. Harrop,Mathias,Jack,Art,HR,fwaris,Don Syme, sffs... Thanks! Musa.Jahanghir@Live.com AVCLive1.com
1:
2:
3:
4:
5:
6:
7:
8:
|
let p = ["a","b"; "a","c"; "b","d"]
let rec p2e =function []->[] |(a,b)::ps ->a::b:: p2e ps
let rec rNb i l=function []->false |p::ps -> (l,i)=p ||(i,l)=p || rNb l i ps
let rec cXl i =function []->true |l::ls -> not( rNb i l p) && cXl i ls
let rec xCg i =function []->[[i]] |cl::cls -> if (cXl i cl) then (i::cl)::cls else cl:: xCg i cls
List.fold(fun a i->xCg i a) [] (p2e p |> List.distinct)//[["d";"a"];["c";"b"]]Musa.Jahanghir@Live.com
|
val p : (string * string) list
Full name: Script.p
val p2e : _arg1:('a * 'a) list -> 'a list
Full name: Script.p2e
val a : 'a
val b : 'a
val ps : ('a * 'a) list
val rNb : i:'a -> l:'a -> _arg1:('a * 'a) list -> bool (requires equality)
Full name: Script.rNb
val i : 'a (requires equality)
val l : 'a (requires equality)
val p : 'a * 'a (requires equality)
val ps : ('a * 'a) list (requires equality)
val cXl : i:string -> _arg1:string list -> bool
Full name: Script.cXl
val i : string
val l : string
val ls : string list
val not : value:bool -> bool
Full name: Microsoft.FSharp.Core.Operators.not
val xCg : i:string -> _arg1:string list list -> string list list
Full name: Script.xCg
val cl : string list
val cls : string list list
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val fold : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State
Full name: Microsoft.FSharp.Collections.List.fold
val a : string list list
val distinct : list:'T list -> 'T list (requires equality)
Full name: Microsoft.FSharp.Collections.List.distinct
More information