Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let g3 n =
- if n=0 then 0 else
- if n<=2 then 1 else
- let t = ref [|0;1;1|] in
- for i=3 to n do
- t := [|!t.(1);!t.(2);!t.(0) + !t.(2)|];
- done;
- !t.(2);;
- g3 22;;
- g 20 3;;
- let g n m =
- if n=0 then 0 else if n<=(m-1) then 1 else
- let t = ref (Array.make m 1) in
- !t.(0) <- 0;
- for i=m to n do
- let temp = !t.(0) + !t.(m-1) in
- for j=0 to (m-2) do
- !t.(j) <- !t.(j+1);
- done;
- !t.(m-1) <- temp;
- done;
- !t.(m-1);;
- g 22 4;;
- 43 mod 42;;
- (* Exercice III. 3) et 4) *)
- let g_rapide n m=
- if n=0 then 0 else if n<=(m-1) then 1 else
- let t = ref (Array.make m 1) in
- !t.(0) <- 0;
- for i=m to n do
- let (a,b) = ( (i-m) mod m , (i-1) mod m ) in
- let temp = !t.( a ) + !t.( b ) in
- !t.( a ) <- temp;
- done;
- !t.( (n-m) mod m);;
- g 200 3;;
- g_rapide (2*(499)-1+1789) 499;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement