1 people like it.

Hall Paradox

Demonstration Hall Paradox Game1 xxx - 1 strategy; Game2 xxx - 2 strategy (change choice).

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
open System
let Game1 count=
  let rnd=new Random()
  List.init count (fun _ ->rnd.Next(3))
    |>List.fold (fun a x->x|>function
                       |x when x=rnd.Next(3)->a+1
                       |_->a)
                0|>printf "%d wins\n"
let Game2 count=
  let rnd=new Random()
  List.init count (fun _ ->rnd.Next(3))
    |>List.fold (fun a x->x|>function
                       |x when x=rnd.Next(3)->a
                       |_->a+1)
                0|>printf " %d wins\n"
//> Game1 1000;​;
//> 317 wins
//val it : unit = ()
//> Game2 1000;​;
//> 668 wins
//val it : unit = ()
namespace System
val Game1 : count:int -> unit

Full name: Script.Game1
val count : int
val rnd : Random
Multiple items
type Random =
  new : unit -> Random + 1 overload
  member Next : unit -> int + 2 overloads
  member NextBytes : buffer:byte[] -> unit
  member NextDouble : unit -> float

Full name: System.Random

--------------------
Random() : unit
Random(Seed: int) : unit
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 init : length:int -> initializer:(int -> 'T) -> 'T list

Full name: Microsoft.FSharp.Collections.List.init
Random.Next() : int
Random.Next(maxValue: int) : int
Random.Next(minValue: int, maxValue: int) : int
val fold : folder:('State -> 'T -> 'State) -> state:'State -> list:'T list -> 'State

Full name: Microsoft.FSharp.Collections.List.fold
val a : int
val x : int
val printf : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf
val Game2 : count:int -> unit

Full name: Script.Game2
Raw view Test code New version

More information

Link:http://fssnip.net/nO
Posted:10 years ago
Author:Zhukoff Dima
Tags: mathematic