Ajout de tests pour trouver la table du mathématicien généreux.
This commit is contained in:
parent
51d2e44ff8
commit
b65493f0d6
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
|||||||
*.a
|
*.a
|
||||||
*.ascii.txt
|
*.ascii.txt
|
||||||
/tipe
|
/tipe
|
||||||
|
.directory
|
||||||
|
|||||||
77
Test.ml
77
Test.ml
@ -77,3 +77,80 @@ print_matrice 4 cocylined.h;;
|
|||||||
distance_minimale cocylined;;
|
distance_minimale cocylined;;
|
||||||
|
|
||||||
print_vecteur 7 (cyclencode cocycl 0b1010);;
|
print_vecteur 7 (cyclencode cocycl 0b1010);;
|
||||||
|
|
||||||
|
(* Essayons de générer une table d'addition *)
|
||||||
|
|
||||||
|
type element = Zero | Ap of int;;
|
||||||
|
|
||||||
|
exception NotApException;;
|
||||||
|
let getap a = match a with
|
||||||
|
| Zero -> raise NotApException
|
||||||
|
| Ap(i) -> i;;
|
||||||
|
|
||||||
|
let add tble i j =
|
||||||
|
let n = (Array.length tble) +1 in
|
||||||
|
if i=j then Zero else
|
||||||
|
match i,j with
|
||||||
|
| Zero,x | x,Zero -> x
|
||||||
|
| (Ap(0),Ap(k)) -> tble.(k-1)
|
||||||
|
| (Ap(k),Ap(0)) -> tble.(k-1)
|
||||||
|
| (Ap(ii),Ap(jj)) -> let tt = getap (tble.(((jj-ii+n) mod n)-1)) in
|
||||||
|
Ap((tt+ii) mod n);;
|
||||||
|
|
||||||
|
let rangearray i j =
|
||||||
|
let out = Array.make (j-i+1) 0 in
|
||||||
|
for k=i to j do
|
||||||
|
out.(k-i) <- k
|
||||||
|
done;
|
||||||
|
out;;
|
||||||
|
let randtabl n =
|
||||||
|
let tab = rangearray 1 (n-1) in
|
||||||
|
Random.self_init ();
|
||||||
|
for i=n-2 downto 1 do
|
||||||
|
let j = Random.int (i+1) in
|
||||||
|
let a,b=tab.(i),tab.(j) in
|
||||||
|
tab.(i) <- b;
|
||||||
|
tab.(j) <- a
|
||||||
|
done;
|
||||||
|
let rout = Array.make (n-1) Zero in
|
||||||
|
for i=0 to n-1-1 do
|
||||||
|
rout.(i) <- Ap(tab.(i))
|
||||||
|
done;
|
||||||
|
rout;;
|
||||||
|
|
||||||
|
randtabl n;;
|
||||||
|
exception PasTransitifException;;
|
||||||
|
let estTransitif tble =
|
||||||
|
let n = Array.length tble +1 in
|
||||||
|
try
|
||||||
|
for i=1 to (n-1) do
|
||||||
|
for j=1 to (i-1) do (* i et j distincts et non nuls (transititivité évidente)*)
|
||||||
|
(* On teste si (0+i)+j = (0+j)+i *)
|
||||||
|
let sa = add tble (add tble (Ap(0)) (Ap(i))) (Ap(j)) in
|
||||||
|
let sb = add tble (add tble (Ap(0)) (Ap(j))) (Ap(i)) in
|
||||||
|
if sa<>sb then raise PasTransitifException
|
||||||
|
done
|
||||||
|
done;
|
||||||
|
true
|
||||||
|
with PasTransitifException -> false;;
|
||||||
|
let printalp a = match a with
|
||||||
|
| Zero -> print_string "o"
|
||||||
|
| Ap(i) -> print_int i;;
|
||||||
|
|
||||||
|
let arr=[|Ap(3);Ap(6);Ap(1);Ap(5);Ap(4);Ap(2)|] in
|
||||||
|
for i=0 to n-2 do printalp arr.(i) done;
|
||||||
|
print_endline"";
|
||||||
|
estTransitif arr;;
|
||||||
|
let arr=randtabl n in
|
||||||
|
for i=0 to n-2 do printalp arr.(i) done;
|
||||||
|
print_endline"";
|
||||||
|
estTransitif arr;;
|
||||||
|
|
||||||
|
|
||||||
|
let n = 7 (* alpha est racine neme de l'unité *);;
|
||||||
|
for i=0 to 100_000 do
|
||||||
|
let arr=randtabl n in
|
||||||
|
if estTransitif arr;
|
||||||
|
then (for i=0 to n-2 do printalp arr.(i) done;
|
||||||
|
print_endline"")
|
||||||
|
done;;
|
||||||
Loading…
x
Reference in New Issue
Block a user