141 lines
2.8 KiB
OCaml
141 lines
2.8 KiB
OCaml
let rempliru u i =
|
|
u.(i) <- 15731*u.(i-1) mod 32003;;
|
|
let getu u0 = let arr = Array.make 40000 0 in
|
|
arr.(0) <- u0;
|
|
for i=1 to 39999 do
|
|
rempliru arr i
|
|
done;
|
|
arr;;
|
|
|
|
let uarr = getu 1;;
|
|
let u i = uarr.(i);;
|
|
let v i j = u (1+i+(j*(j-1)/2));;
|
|
|
|
u 1000;;
|
|
u 10000;;
|
|
u 30000;;
|
|
|
|
let g m n = let adj = Array.make n (Array.make n false) in
|
|
for i=0 to (n-1) do
|
|
adj.(i) <- Array.make n false;
|
|
for j=0 to (i-1) do
|
|
adj.(i).(j) <- ((v j i) mod m) = 0
|
|
done;
|
|
for j=i+1 to (n-1) do
|
|
adj.(i).(j) <- ((v i j) mod m) = 0
|
|
done
|
|
done;
|
|
adj;;
|
|
let aretes g = let n = Array.length g and count = ref 0 in
|
|
for i=0 to (n-1) do
|
|
for j=0 to (n-1) do
|
|
if g.(i).(j) then
|
|
count := !count+1
|
|
done
|
|
done;
|
|
!count/2;;
|
|
g 5 10;;
|
|
aretes(g 5 10);;
|
|
aretes(g 10 50);;
|
|
aretes(g 50 250);;
|
|
|
|
let deg g = let n = Array.length g in
|
|
let count = Array.make n 0 in
|
|
for i=0 to (n-1) do
|
|
for j=0 to (n-1) do
|
|
if g.(i).(j) then
|
|
count.(i) <- count.(i)+1
|
|
done
|
|
done;
|
|
count;;
|
|
let degre m n = deg (g m n);;
|
|
let max arr = let m = ref arr.(0) in
|
|
for i=1 to (Array.length arr)-1 do
|
|
if arr.(i) > !m
|
|
then m := arr.(i)
|
|
done;
|
|
!m;;
|
|
let minLastIndex arr = let im = ref 0 in
|
|
for i=1 to (Array.length arr)-1 do
|
|
if arr.(i) <= arr.(!im)
|
|
then im := i
|
|
done;
|
|
!im;;
|
|
let maxFirstIndex arr = let im = ref 0 in
|
|
for i=1 to (Array.length arr)-1 do
|
|
if arr.(i) > arr.(!im)
|
|
then im := i
|
|
done;
|
|
!im;;
|
|
|
|
max (degre 5 10);;
|
|
max (degre 10 50);;
|
|
max (degre 50 250);;
|
|
|
|
minLastIndex (degre 5 10);;
|
|
minLastIndex (degre 10 50);;
|
|
minLastIndex (degre 50 250);;
|
|
|
|
maxFirstIndex (degre 5 10);;
|
|
maxFirstIndex (degre 10 50);;
|
|
maxFirstIndex (degre 50 250);;
|
|
|
|
(*** 2 Méthode éxacte ***)
|
|
open List;;
|
|
let rec putall l x rst=
|
|
match l with
|
|
| [] -> rst
|
|
| e::s -> (x::e):(putall s x);;
|
|
let rec llen l = match l with
|
|
| [] -> 0
|
|
| e::s -> 1+(llen s);;
|
|
|
|
let rec parties k l = let n = llen l in
|
|
if k=0 then [ [] ]
|
|
else
|
|
if k=n then [ l ]
|
|
else
|
|
let l0::lr = l in
|
|
(putall (parties (k-1) lr) l0 [])@(parties k lr);;
|
|
|
|
let rec lin l x = match l with
|
|
| [] -> false
|
|
| e::s -> x=e || (lin s x);;
|
|
|
|
let tester l g = let n = Array.length g and out = ref true in
|
|
for i = 0 to n-1 do
|
|
for j = 0 to n-1 do
|
|
if g.(i).(j) then
|
|
out := !out && ((lin l i) || (lin l j))
|
|
done
|
|
done;
|
|
!out;;
|
|
exception PasDeCouverture;;
|
|
let rec testerliste ll g = match ll with
|
|
| [] -> raise PasDeCouverture
|
|
| l::s -> if tester l g
|
|
then l
|
|
else testerliste s g;;
|
|
let rec range i n = match n-i with
|
|
| 0 -> []
|
|
| _ -> i::(range (i+1) n);;
|
|
|
|
let rec testall g k = let n = Array.length g in
|
|
let l = range 0 (n-1) in
|
|
try (testerliste (parties k l) g)
|
|
with PasDeCouverture -> testall g (k+1);;
|
|
|
|
testall (g 5 10) 0;;
|
|
testall (g 6 16) 0;;
|
|
testall (g 7 20) 0;;
|
|
|
|
range 0 4;;
|
|
parties 1 (range 0 4);;
|
|
parties 2 (range 0 4);;
|
|
parties 3 (range 0 4);;
|
|
|
|
putall (parties 3 (range 0 4)) 6 [];;
|
|
|
|
|
|
|