10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-19 20:42:22 +01:00

permtutations -> permutations

This commit is contained in:
Anthony Scemama 2020-12-26 01:54:39 +01:00
parent ebd753d48e
commit dfadaf14c1
4 changed files with 18 additions and 18 deletions

View File

@ -485,14 +485,14 @@ let rec to_list ?(accu=[]) = function
Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45)));
#+end_src
*** ~permtutations~
*** ~permutations~
~permtutations m n~ generates the list of all possible ~n~-bit
~permutations m n~ generates the list of all possible ~n~-bit
strings with ~m~ bits set to ~1~.
Algorithm adapted from [[https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation][Bit twiddling hacks]].
#+begin_example
Bitstring.permtutations 2 4 |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;;
Bitstring.permutations 2 4
|> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;;
- : string list =
["++--------------------------------------------------------------";
@ -504,11 +504,11 @@ Bitstring.permtutations 2 4
#+end_example
#+begin_src ocaml :tangle (org-entry-get nil "mli" t)
val permtutations : int -> int -> t list
val permutations : int -> int -> t list
#+end_src
#+begin_src ocaml :tangle (org-entry-get nil "ml" t)
let permtutations m n =
let permutations m n =
let rec aux k u rest =
if k=1 then
@ -529,7 +529,7 @@ let permtutations m n =
#+begin_src ocaml :tangle (org-entry-get nil "test-ml" t)
check "permutations"
(permtutations 2 4 = List.map of_int
(permutations 2 4 = List.map of_int
[ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]);
#+end_src

View File

@ -208,8 +208,8 @@ let rec to_list ?(accu=[]) = function
|> (to_list [@tailcall]) ~accu:newlist
(* ~to_list~:2 ends here *)
(* [[file:../bitstring.org::*~permtutations~][~permtutations~:2]] *)
let permtutations m n =
(* [[file:../bitstring.org::*~permutations~][~permutations~:2]] *)
let permutations m n =
let rec aux k u rest =
if k=1 then
@ -226,7 +226,7 @@ let permtutations m n =
(aux [@tailcall]) (k-1) (logor t' t'') (u :: rest)
in
aux (Util.binom n m) (minus_one (shift_left_one n m)) []
(* ~permtutations~:2 ends here *)
(* ~permutations~:2 ends here *)
(* [[file:../bitstring.org::*Printers][Printers:2]] *)
let pp ppf = function

View File

@ -211,14 +211,14 @@ val popcount : t -> int
val to_list : ?accu:(int list) -> t -> int list
(* ~to_list~:1 ends here *)
(* ~permtutations~
(* ~permutations~
*
* ~permtutations m n~ generates the list of all possible ~n~-bit
* ~permutations m n~ generates the list of all possible ~n~-bit
* strings with ~m~ bits set to ~1~.
* Algorithm adapted from [[https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation][Bit twiddling hacks]].
*
* #+begin_example
* Bitstring.permtutations 2 4 |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;;
* Bitstring.permutations 2 4
* |> List.map (fun x -> Format.asprintf "%a" Bitstring.pp x) ;;
* - : string list =
* ["++--------------------------------------------------------------";
@ -230,9 +230,9 @@ val to_list : ?accu:(int list) -> t -> int list
* #+end_example *)
(* [[file:../bitstring.org::*~permtutations~][~permtutations~:1]] *)
val permtutations : int -> int -> t list
(* ~permtutations~:1 ends here *)
(* [[file:../bitstring.org::*~permutations~][~permutations~:1]] *)
val permutations : int -> int -> t list
(* ~permutations~:1 ends here *)
(* Printers
*

View File

@ -63,11 +63,11 @@ let test_all () =
Alcotest.(check bool) "to_list" true ([ 1 ; 3 ; 4 ; 6 ] = (to_list (of_int 45)));
(* ~to_list~:3 ends here *)
(* [[file:../bitstring.org::*~permtutations~][~permtutations~:3]] *)
(* [[file:../bitstring.org::*~permutations~][~permutations~:3]] *)
check "permutations"
(permtutations 2 4 = List.map of_int
(permutations 2 4 = List.map of_int
[ 3 ; 5 ; 6 ; 9 ; 10 ; 12 ]);
(* ~permtutations~:3 ends here *)
(* ~permutations~:3 ends here *)
(* Tests *)