(* The decimal number, 585 = 1001001001_(2) (binary), is palindromic in both bases. Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. (Please note that the palindromic number, in either base, may not include leading zeros.) *) let rec bin_of_dec n = if(n=0) then [] else ( n mod 2 )::(bin_of_dec (n / 2));; let rec list_of_dec n = if(n=0) then [] else ( n mod 10 )::(list_of_dec (n / 10));; let palindrom l = List.for_all2 (=) l (List.rev l);; let rec search i s = if(i>=1000000) then s else let b = bin_of_dec i in let l = list_of_dec i in if((palindrom b) && (palindrom l)) then ( Printf.printf "%d " i; List.iter (Printf.printf "%d") l; Printf.printf " "; List.iter (Printf.printf "%d") b; Printf.printf "\n"; search (i+1) (i+s) ) else search (i+1) s ;; Printf.printf "%d\n" (search 0 0);;