3 Matching Annotations
- Jan 2024
-
cs3110.github.io cs3110.github.io
-
Create a function fib_fast
let rec h n pp p = if n <= 1 then p else h (n-1) (p) (pp + p) let fib_fast n = h (n-1) 1 1;;
-
How terse (i.e., few and short lines of code) can you make your function? You can definitely do this in fewer than 12 lines.
let date_fun (d:int) (m:string) = if d > 31 || d < 0 then false else if d <= 28 then true else if d <= 30 && List.mem m ["Apr";"Jun";"Sept";"Nov"] then true else if d = 31 && List.mem m ["Jan";"Mar";"May";"Jul";"Aug";"Oct";"Dec"] then true else false
-
Define a function that computes the area of a circle given its radius. Test your function with assert.
let circle_area r = Float.pi *. r ** 2.;; assert( (circle_area 1.) -. (circle_area 1.) <= 1e-5);;
-