Jump to content

Jskid

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    Canada

Jskid's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Just to make sure there's no misunderstanding: the first line prints "started" and then it goes into the convoluted process of prime factoring. With the number 15999 the program really quickly crashes - doesn't even print out "started". Does this mean that the preprocessed was trying to do an optimization and got screwed up? I mean is no one else surprised that the first line of code which defiantly isn't problematic is not being executed?
  2. Say I wanted to do a loop and the condition never changes. How can I make it so that the condition doesn't get recalculated each time? For example $myString = 'hello world';//I'm not going to reassign anything to this variable for($i = 1; i<=strlen($myString); i++) { ... } $people = 342;//not going to change for($j = 0; j<sqrt($people); j++) { ... } [/php} I could calculate it outside the loop and save it in a variable and it would be good for readability if there's a statment to help people know that the variables not going to change. Or is there a completely different method?
  3. I thought this is how PHP works: it is red through once so that the functions have a definition, and then it starts at the <?php and executes one line of code at a time?
  4. I only get this problem using EasyPHP 1.8(http://software.emule.com/easyphp-1-8/), older and newer versions work fine. What I really like to understand is how come the program crashes immediately and doesn't even do the very first line that is a print statement?
  5. Along time ago I wrote this program that prime factors a number. Under EasyPHP 1.8 certain numbers crash the program. The program crashes even if the first thing it does is print out a line it won't do this. An example number is 15999. This was one of the first programs I wrote and my style was very poor, this is a prime example of spaghetti code. <?php print("started"); $num = 15999; $startnum = 1; if($num == 1){ print("1 has no factors"); exit; } if($num == 0){ print("0 has no factors"); exit; }else{ print("The factors of ".$num." are:<br />"); } primefind($num, $startnum); if($num == 0){ print("0"); } else if($num == 1){ print("1"); }else{ } function primefind($num, $startnum){ $primestat = 'f'; for($counter1 = $startnum; $counter1<=$num; $counter1++){ for($counter2 = 2; $counter2<$counter1; $counter2++){ $primecheck = $counter1%$counter2; if($primecheck != 0){ $primestat = 't'; }else{ $primestat = 'f'; break; } } if($primestat == 't'||$counter1 == 2){ factorcheck($counter1, $num); break; } } } function factorcheck($prime, $num){ $remainder = $num%$prime; if($remainder == 0) { print($prime.'<br />'); $startnum = 1; primefind(($num/$prime), $startnum); //exit; return $prime; } else{ $prime++; primefind($num, $prime); } } ?> Does anyone know why certain numbers crash this program? How does PHP work, how is it possible for a script to crash immediately without printing the first line?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.