4 people like it.

Gray-Code

"a binary numeral system where two successive values differ in only one bit" http://en.wikipedia.org/wiki/Gray_code http://FunctionalSoftware.net/starten-mit-f/

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
// Gray-Code
// "a binary numeral system where two successive values differ in only one bit"  http://en.wikipedia.org/wiki/Gray_code
//
// http://FunctionalSoftware.net/starten-mit-f/
let (++) x = List.map((+)x)
let g x = ("0" ++ x) @ ("1" ++ (List.rev x))
printf "%A" ([""] |> g |> g |> g)
// ["000"; "001"; "011"; "010"; "110"; "111"; "101"; "100"]
val x : string
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  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 map : mapping:('T -> 'U) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
val g : x:string list -> string list

Full name: Script.g
val x : string list
val rev : list:'T list -> 'T list

Full name: Microsoft.FSharp.Collections.List.rev
val printf : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf
Raw view New version

More information

Link:http://fssnip.net/m3
Posted:5 years ago
Author:FunctionalSoftware.net
Tags: gray-code , code , binary , pattern