Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -3,3 +3,10 @@ let rec fib_rec n =
|
|||
n
|
||||
else
|
||||
fib_rec (n - 1) + fib_rec (n - 2)
|
||||
|
||||
(* with support for negatives *)
|
||||
let rec fib = function
|
||||
0 -> 0
|
||||
| 1 -> 1
|
||||
| n -> if n > 0 then fib (n-1) + fib (n-2)
|
||||
else fib (n+2) - fib (n+1)
|
||||
|
|
|
|||
|
|
@ -5,3 +5,8 @@ let fib n =
|
|||
| _ -> fib_aux (n-1) b (a+b)
|
||||
in
|
||||
fib_aux n 0 1
|
||||
|
||||
(* support for negatives *)
|
||||
let fib n =
|
||||
if n < 0 && n mod 2 = 0 then -fib (abs n)
|
||||
else fib (abs n)
|
||||
|
|
|
|||
|
|
@ -7,3 +7,13 @@ let fib =
|
|||
| n -> fib_aux f1 (f1 +/ f0) (n - 1)
|
||||
in
|
||||
fib_aux (num_of_int 0) (num_of_int 1)
|
||||
|
||||
(* support for negatives *)
|
||||
let fib n =
|
||||
if n < 0 && n mod 2 = 0 then minus_num (fib (abs n))
|
||||
else fib (abs n)
|
||||
;;
|
||||
(* It can be called from the command line with an argument *)
|
||||
(* Result is send to standart output *)
|
||||
let n = int_of_string Sys.argv.(1) in
|
||||
print_endline (string_of_num (fib n))
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
open Num
|
||||
|
||||
let mul (a,b,c) (d,e,f) =
|
||||
(a*/d +/ b*/e, a*/e +/ b*/f, b*/e +/ c*/f)
|
||||
let mul (a,b,c) (d,e,f) = let bxe = b*/e in
|
||||
(a*/d +/ bxe, a*/e +/ b*/f, bxe +/ c*/f)
|
||||
|
||||
let id = (Int 1, Int 0, Int 1)
|
||||
let rec pow a n =
|
||||
if n=1 then a else
|
||||
if n=0 then id else
|
||||
let b = pow a (n/2) in
|
||||
if (n mod 2) = 0 then mul b b else mul a (mul b b)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue