algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

main.ml (649B)


      1 let readInt () = 
      2     Scanf.scanf " %d" (fun x->x)
      3 let handleTestCase () = 
      4     let size = readInt () in
      5         let arr = Array.make size 0 in
      6         let () =  
      7             let rec acc idx = 
      8                 if idx = size  then () else (arr.(idx) <- readInt (); acc (idx+1))
      9             in acc 0 in
     10         print_int (snd ((Array.fold_left (fun (prior,total) current -> (if prior+2 <= current then (current,total+1) else (prior, total))) (-10,0) arr)));
     11         print_newline ()
     12 let () = 
     13     let testCases = readInt () in 
     14         let rec acc idx =   
     15             if idx = testCases then () else (acc (idx+1); handleTestCase ())
     16         in acc 0