Computer Science Canada Recursion Error |
| Author: | Tewg [ Sun Apr 13, 2008 10:13 pm ] | ||
| Post subject: | Recursion Error | ||
I'm having a java.lang.StackOverflowError when i run, i know its n RTP but where would my logic be off, I'm looking to find the lowest number divisable by 1, 20 inclusive.
|
|||
| Author: | Tewg [ Sun Apr 13, 2008 10:16 pm ] |
| Post subject: | Re: Recursion Error |
ok i tryed it with the smaller numbers 1,10 inclusive which works, but stops 1 number before 2520 (answer) in a continuos loop and i can't for the life of me see why. I have put several output statements in to trace the execution but i still can't find the logic error. |
|
| Author: | Tony [ Sun Apr 13, 2008 10:30 pm ] |
| Post subject: | RE:Recursion Error |
Are you sure that recursion is the best method to loop here? The lowest number would be a multiple of all the largest factors (I mean factors that are not already a part of larger factors in the list), so: 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 = 670 442 572 800 That's a lot to stack. Assuming an unreasonably low 1 byte per stack call, you gonna need to find a computer with 670 GB of RAM. This will probably take a while to run as well. |
|
| Author: | Tewg [ Sun Apr 13, 2008 10:33 pm ] |
| Post subject: | Re: Recursion Error |
oh I've already figured this wont work with this bg a number I'm just playing with recursion because i have little to no experience with it. |
|
| Author: | Tony [ Sun Apr 13, 2008 10:37 pm ] |
| Post subject: | Re: Recursion Error |
Tewg @ Sun Apr 13, 2008 10:33 pm wrote: i have little to no experience with it.
It's probably helpful to know how recursion is handled by the compiler/interpreter. |
|
| Author: | Tewg [ Sun Apr 13, 2008 10:43 pm ] |
| Post subject: | RE:Recursion Error |
Yah, I'm just reading up on that now, thanks for your help. |
|