Advertisement
Guest User

sc1

a guest
Sep 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.59 KB | None | 0 0
  1. (* the AC/DC said n is in [100;1000[ *)
  2. let mystery_func n =
  3.   if ((n > 99) && n < (1000)) then
  4.     let hundreds = (n / 100) and tens = ((n/10) mod 10) and units =(n mod 10) in
  5.  
  6.     if (hundreds + tens + units) < 10 then
  7.         let prod_2_first = (hundreds * tens) in
  8.           (prod_2_first < units) && (tens = (units - hundreds))
  9.       else
  10.         false
  11.   else
  12.     invalid_arg ((string_of_int(n))^" is not a three digits positive int");;
  13. let forAll n  =
  14.   string_of_int(n)^": "^string_of_bool(mystery_func(n))^(
  15.     if (n < 999) then
  16.       forAll(n+1)
  17.     else
  18.       ""
  19.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement