Computer Science Canada Prime Factorization Stack Overflow! |
Author: | MysticVegeta [ Sat Oct 29, 2005 7:06 pm ] | ||
Post subject: | Prime Factorization Stack Overflow! | ||
I am using the following procedure recursion but if i input in 714768071, i get the stack overflow error, is there a way to bypass it/resolve it?
Please help! Thank you ![]() |
Author: | Cervantes [ Sat Oct 29, 2005 7:43 pm ] |
Post subject: | |
Maybe it's not entirely necessary, but it'd help if it were commented. ![]() |
Author: | MysticVegeta [ Sat Oct 29, 2005 10:09 pm ] | ||
Post subject: | |||
|
Author: | Mr. T [ Sun Oct 30, 2005 12:48 pm ] |
Post subject: | Alex's Opinion |
Does Turing have any other primitive types that can hold quantities larger then int? ![]() |
Author: | Cervantes [ Sun Oct 30, 2005 12:56 pm ] |
Post subject: | Re: Alex's Opinion |
Pwned wrote: Does Turing have any other primitive types that can hold quantities larger then int?
![]() natural numbers can go twice as high as integers, but they start at zero. real numbers can go very high. |
Author: | MysticVegeta [ Sun Oct 30, 2005 3:09 pm ] |
Post subject: | |
I dont know why they put nat as 0 too, in math, nats start at 1. Also knows as counting numbers, but then again, in math ints can go infinite |
Author: | zylum [ Mon Oct 31, 2005 12:20 am ] | ||
Post subject: | |||
the reason you are getting stack overflow is because you are recursing too far... you are using up all of the available memory. everytime you recurse forward, you are leaving the current function and going into a new one but the computer has to remember all the values of where you left off and what the values of the variables were. so if you recurse too far you run out of memory. the main problem with your function is that you are using it to iterate through devisors. this is unecesary because the body of you function can easily deal with this. heres a better implementation of a prime factor generator:
note: i added a depth variable to illustrate how much shallower my recursion was compared to yours. when i added a depth counter to yours, it reached a depth of over 15000... hope that helps.. ![]() |
Author: | MysticVegeta [ Mon Oct 31, 2005 2:37 pm ] |
Post subject: | |
Thanks a lot! ![]() |
Author: | beard0 [ Mon Oct 31, 2005 3:56 pm ] |
Post subject: | |
~ is just a "not" shorthand (thus ~true=false) |
Author: | MysticVegeta [ Mon Oct 31, 2005 6:56 pm ] |
Post subject: | |
I dont know why they changed the not sign (!) to (~) maybe they wanted to make it different.. (!) is better |
Author: | codemage [ Wed Nov 02, 2005 8:34 am ] |
Post subject: | |
Agreed. ! has always meant not in CS. ~ has often used as shorthand for "equivalent", or "roughly equal to" in the circles I've been taught in. |
Author: | zylum [ Wed Nov 02, 2005 9:55 am ] |
Post subject: | |
in discrete math we use ~ as negation. |
Author: | MysticVegeta [ Thu Nov 03, 2005 7:24 pm ] |
Post subject: | |
whats discrete math? a branch of math? |
Author: | zylum [ Sat Nov 05, 2005 12:46 am ] |
Post subject: | |
discrete math is probably the most useful branch of math for programming |
Author: | MysticVegeta [ Sun Nov 06, 2005 4:49 pm ] |
Post subject: | |
Do you mean math for like AI algorithms/other algorithms? |
Author: | zylum [ Mon Nov 07, 2005 10:09 am ] |
Post subject: | |
no. it covers stuff like combinatorics, set theory, logic, probability, trees, recursion... that sort of stuff... |