3 Matching Annotations
  1. Jan 2024
    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
      
    2. 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);;