iwk #1737(2007/08/02 15:50 GMT) [ OCaml ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#light open LazyList type LListBuilder() = member l.Bind(v,f) = LazyList.concat (LazyList.map f v) member l.Return x = LazyList.consf x LazyList.empty member l.Let(v,f) = f v let doLList = new LListBuilder() let replicate n x = LazyList.take n (LazyList.repeat x) let rec fact (n:int) = if n = 0 then 1 else n * fact (n-1) let combination n m = if n < m then 0 else (fact n)/((fact m) * (fact (n-m))) let rec make_perm n m = match n,m with | n,0 -> doLList { return (replicate n 0) } | n,m when n = m -> doLList { return (replicate n 1)} | n,m when n < m -> doLList { return (empty()) } | n,m -> let c = combination n m let d = combination (n-1) (m-1) append (map2 append (replicate d (consf 1 empty)) (make_perm (n-1) (m-1))) (map2 append (replicate (c-d) (consf 0 empty)) (make_perm (n-1) m)) let inv_hash (n,m) num = let nth lls i = take i lls |> hd let c = (combination n m) nth (make_perm n m) (c-num)
Rating0/0=0.00-0+
[ reply ]
iwk
#1737()
[
OCaml
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]