I am trying to solve a problem from project euler, for the purpose of learning I'm not asking here for the answer or logic, I got the latter but it seems that I have a problem in outputting the integer since it exceeds the limit of variable limit in PHP (as I know).
What is the result if you call var_dump() on your $even_count variable?
My simple guess is that you have indeed exceeded the limit on your platform for handling numerical values and that if you have a 32BIT operating system you are out of luck. Perhaps with a 64BIT operating system it would be fine.
I checked the PHP manual but I cannot find any object/function that would allow you to store the numerical value as something else and work with it to get around your problem.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
What is the result if you call var_dump() on your $even_count variable?
My simple guess is that you have indeed exceeded the limit on your platform for handling numerical values and that if you have a 32BIT operating system you are out of luck. Perhaps with a 64BIT operating system it would be fine.
Thanks for your reply, I checked the PHP manual but I cannot find any object/function that would allow you to store the numerical value as something else and work with it to get around your problem.
Archie
Whenever I call var_dump() on $even_count variable it outputs float(INF). Yeah you're right, I'm using 32-bit operating system.
Thanks once more for your reply NogDog, I checked the link you gave me but I can't seem to have an idea how to start using it. Can you give me some samples or simple approach regarding this? Thanks so much.
Can't stand long hours coding in front of computer without being intoxicated.
Whenever I call var_dump() on $even_count variable it outputs float(INF). Yeah you're right, I'm using 32-bit operating system.
Thanks once more for your reply NogDog, I checked the link you gave me but I can't seem to have an idea how to start using it. Can you give me some samples or simple approach regarding this? Thanks so much.
As long as you have the package installed (see the Installation section on the link NogDog gave) you just need to exchange your
And be prepared to wait awhile, and probably have to use set_time_limit() to allow it to run long enough. (120 seconds was not enough on my PC.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Upon reading the BCMath and your replies I finally get the idea how does this things work, however I can't make it run due to some execution time limit.
@NogDog
I wonder where will I set the execution time to greater value, I had looked into the php.ini but the only BCMath related thing I could get is in here
Code:
[bcmath]
; Number of decimal digits for all bcmath functions.
; http://php.net/bcmath.scale
bcmath.scale = 0
Sorry for being quite redundant in asking, its just that its not my usual hobby to manipulate the php.ini configurations
Can't stand long hours coding in front of computer without being intoxicated.
Sorry for my earlier post, after doing some research and trials I found out how to use the set_time_limit(). I added set_time_limit(1000) on top of my php code. But still I got the fatal error for maximum execution time. What is the maximum seconds I could set? Is the problem lies in my 1gb ram laptop?
Can't stand long hours coding in front of computer without being intoxicated.
Sorry for my earlier post, after doing some research and trials I found out how to use the set_time_limit(). I added set_time_limit(1000) on top of my php code. But still I got the fatal error for maximum execution time. What is the maximum seconds I could set? Is the problem lies in my 1gb ram laptop?
You can set it to zero (0), which means no time limit. However, before doing that, try setting the maximum for $i in the loop condition to a much smaller number to test your code before letting it loose for 4 million iterations so you can find out if the code is reasonable. If it takes 1/1000th of a second per iteration (purely hypothetically, maybe more, maybe less), you'll need at least 4000 seconds -- a bit over an hour -- for it to run.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks