I study F # ropes through Project Euler and have run into a problem several times. I write a function, run it in an interactive F # window, and the program freezes there. I suspect that the function is failing, but I am not getting any significant error message that will help me figure out what is going wrong. Is there a way to debug a program running in F # interactive?
As an illustration, here is an example from task 12. FindFirstTriangle (0,0,100) works fine, but when the divisor is around 150, everything gets stuck.
Note: this is not about what is wrong in this code, but how to figure out where everything goes wrong!
let NumberOfDivisors n =
[1 .. n] |> List.filter (fun i -> n % i = 0) |> List.length;;
let HasMoreThanDDivisors n d =
if NumberOfDivisors n >= d then
true
else
false
let rec FindFirstTriangle (index, number, divisors) =
if HasMoreThanDDivisors number divisors then
number
else
let nextIndex = index + 1
let nextNumber = number + index
FindFirstTriangle (nextIndex, nextNumber, divisors);;