-
-
Save cpdean/af2383855e4ed9ac4020e8db30b7eb91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let exchange x = | |
let ones = (x mod 10) in | |
let tens = (x - ones) / 10 in | |
(ones * 10) + tens;; | |
let is_valid_answer (grand_father_age, grand_son_age) = | |
let four_multiply = (grand_father_age = (grand_son_age * 4)) in | |
let ex_f = exchange grand_father_age in | |
let ex_s = exchange grand_son_age in | |
let three_mult = (ex_s = (ex_f * 3)) in | |
four_multiply && three_mult;; | |
let rec find (max_father, min_son) = | |
match (max_father, min_son) with | |
| (f, s) when f < (s * 4) -> (-1, -1) | |
| (f, s) when (is_valid_answer (f, s)) -> (f, s) | |
| _ -> find (max_father, min_son + 1);; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment