stack overflow for big input -


so part of program. causes stack overflow when call bound numbers difference more 250000.. how can fix this? program works fine smaller input.. i'm pretty sure rest of program fine. there way rewrite function work? prefer not use while loops.

let rec sqdigits = if = 0 0 else ( mod 10)*( mod 10) + sqdigits (a/10);;  let rec bound c d = if c>d [] else (sqdigits (c))::(bound (c+1) d);; 

your functions aren't tail recursive. don't need eliminate recursion (perish thought in functional programming language!). need make them tail recursive.

in fact, number of recursive calls sqdigits limited number of digits in int, quite small number. need fix bound.

i don't want write code (since looks assignment). usual way make tail recursive function pass accumulated result parameter.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -