Comment detail

議席数をドント方式で (Nested Flatten)
scan_leftを使ってみました。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#light
open List
let rec take n xs =
    match n,xs with
    | n,_ when n <= 0 -> []
    | _,[] -> []
    | n,(x::xs') -> x::(take (n-1) xs')

let dhont seat vs =
    let vs' = map float vs
    let mkTable v =
        scan_left (fun w n -> ((n - 1.0)*w/n)) v [2.0 .. (float seat)]
    let size = length vs -1
    map mkTable vs'
    |> mapi (fun n xs -> map (fun x -> (x,n)) xs)
    |> concat
    |> sort (fun x y -> compare y x)
    |> take seat
    |> split
    |> snd
    |> (fun xs -> map (fun n -> (length (filter ((=) n) xs))) [0 .. size])

do print_any (dhont 100 [123;4;56;78])

Index

Feed

Other

Link

Pathtraq

loading...