Jump to content

Jessica

Staff Alumni
  • Posts

    8,968
  • Joined

  • Last visited

  • Days Won

    41

Everything posted by Jessica

  1. Use some logic.
  2. Don't store the image in the DB. Either store the name of the image, or rename the image to something like their username or user id.
  3. LCM of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10: 2520 LCM of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15: 360360 LCM of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20: 232792560
  4. I added this code to it: function getDivisors($nums){ rsort($nums); $use_these_nums = array(); foreach($nums AS $num){ $goes_into_another = FALSE; foreach($nums AS $bigger){ if($bigger%$num==0 && $num != $bigger){ $goes_into_another = TRUE; } } if(!$goes_into_another){ $use_these_nums[] = $num; } } return $use_these_nums; } and changed the other function to: function findLCM($nums, $debug=true){ //First, order them largest to smallest. rsort($nums); $count_nums = count($nums); if($count_nums > 1){ //Then remove any numbers that go into other numbers. $nums = getDivisors($nums); .... You don't need to check if the possible LCM is divisible by any number that goes into another number you're checking.
  5. Just for fun I wrote this function. I'm not going to claim it is the best way, it just made sense to me. It worked for 1-10 no problem and 1-20 took a while, but eventually finished. 1-18 was fast enough, after that it takes a while, I had to put my max exec time up to 1 min. Don't try to do 1-10 and 1-20 on the same page though. If it doesn't do what you want, please explain what you're trying to do. And why. Original Idea: <?php set_time_limit(60); function findLCM($nums, $debug=true){ //First, order them largest to smallest. rsort($nums); $count_nums = count($nums); if($count_nums > 1){ //The greatest possible solution is the product of all numbers. $max = 1; foreach($nums AS $n){ $max *= $n; } if($debug) echo "Max is: $max"; //Start out assuming we haven't found it. $lcm_found = FALSE; if($debug) $tries = 0; //The first possible is the max number in the list. $possible_lcm = $nums[0]; while(!$lcm_found && $possible_lcm < $max){ if($debug) $tries++; //Check if it's the LCM. Since we care if any one isn't it, first assume we found it $lcm = true; if($debug) echo "<br><br><b>Try #{$tries}<br> Possible LCM: {$possible_lcm}</b><br>"; //Check each number - checking the max number is redundant but oh well. foreach($nums AS $n){ if($debug) echo "Checking $possible_lcm % $n ... ".($possible_lcm % $n).' ... '; if($possible_lcm % $n != 0){ //And we didn't find it, so break out. $lcm = false; if($debug) echo 'Not LCM</br>'; break; }else{ if($debug) echo '<br>'; } } if($lcm == true){ $lcm_found = true; }else{ $possible_lcm += $nums[0]; } } return $possible_lcm; } } $a=1; $b=20; $nums = range($a,$B); $lcm = findLCM($nums, true); echo "LCM of ".implode($nums, ', ').": $lcm<br>"; I had a better idea, wrote out why it was better, and then erased it by accident. working on it now.
  6. Can you explain again what you're trying to do? This code doesn't look like anything to do with LCM. http://en.wikipedia.org/wiki/Least_common_multiple Or if it does you're going about it in a weird way.
  7. Post your code, turn on error reporting, blah blah blah
  8. *smh*. You shouldn't use global. You should either put all of the logic that uses that variable in the function, (all your sql stuff) or return the variable you need.
  9. Did you google PHP variable scope? If it's too complicated what part of it don't you understand?
  10. You have the array, now loop through it and use isset().
  11. Did you try trim?
  12. Use MySQL.
  13. If your form is using get as the method, replace 'username' with $_GET['username'] etc. If it uses post, use POST.
  14. We could help but this is entirely the wrong way to store login information. Are you just trying to learn about writing to files, or actually make something people log into?
  15. So you think someone who doesn't know to simply add the number after his existing sort, actually knows that MySQL allows you to use the column numbers and wants to sort on it? *shrug* Barand you have more faith in people than I do I guess.
  16. There is no way for you to conduct a number of transactions without being charged transaction fees.
  17. Brackets, not parens
  18. But why would you add a number to a sort? MySQL will interpret it as sort by the nth column (afaik, not sure if it does that if you've named another column in your order). If you're trying to do that, just use the name of the column.
  19. That doesn't make much sense.
  20. There are various levels in which data could be compromised. It's entirely possible to data to be leaked and not allow inserts. Also just saying PHP could be placed in a database, doesn't mean it can be executed unless the existing PHP code allows for that. Which is a good reason to NEVER DO THAT.
  21. Considering OP hasn't posted in 5 days, either it wasn't that "urjent" or he got help elsewhere.
  22. Totally agree.
  23. You can, and you need to if it's a 1-many/0-many etc. But the data you're describing might as well be in one table, it will save you a lot of effort. If you are going to allow every user to have more than one character, they need to be separate. If one user = one character, save the bother and store them in one.
×
×
  • 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.