I wrote the following Caml light code to find prime factors of a number (part of an early Project Euler question).
Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143?
let rec find_factors target check =
if (check > (int_of_float (sqrt (float_of_int target)))) then [] else
(find_factors target (check+1))@if target mod check == 0 then
[ check; (target/check)] else[] ;;
let display n =
print_int n;print_newline();;
do_list display (find_factors 10 1);
print_newline();;
I'm very new to functional programming and I suspect I'm all over the place - if anyone would like to give me some tips that would be ideal. :)