Jump to content

Recommended Posts

I think this sounds like a fun idea to do, create a new forum for the "Daily (or weekly) PHP Coding"  where each day/week a deal is posted for users to code and post how they coded it.

 

Could serve multiple purposes for learning and be fun for some of the more advanced members interested. I do not know if it will go without a hitch, but I would probably do the weekly one at least for the heck of it, it may even help improve the advanced members skills.

 

Anyhow just a suggestion =)

Link to comment
https://forums.phpfreaks.com/topic/132432-suggestion-daily-or-weekly-php-coding/
Share on other sites

I would like to see regular competitions happen, but as Dan said, there wasn't enough interest.  Ideally, I would like to for us to regularly host competitions in which there is an entry fee required.

 

One of the problems with the competitions in the past was people signing up and then dicing out, even though we made very large, colored and bolded statements about not signing up unless you were seriously for really real serious about doing it.  It's a waste of everybody's time when people don't follow through.  Requiring an entry fee ensures that people who enter are serious about following through instead of dicing out. 

 

Another problem was lack of rewards.  We're all volunteers here.  We don't get paid for doing any of this, and although we get some donations here and there, it goes straight towards hosting/server costs, and afaik it nowhere near covers those costs.  The owner of phpfreaks.com pays most of it out of pocket.  Only reason we're still even around is that he gets to write it off as a business expense for his real job (I think).

 

Point is, there isn't any money laying around to be coming up with prizes.  We've gotten some offers here and there for people willing to donate prizes (hosting packages, mostly), but it wasn't steady and reliable.  By requiring an entry fee, we can take that money and come up with prizes.

 

Another reason the contests failed was because the judges dragged ass when it came to judging.  Though I think that was a result of prizes being sucky and shady and people dicing out to begin with. By the time all that happened, I think the judges caught a "why bother?" attitude.  I think that having an entry fee would indirectly solve this problem, as well. 

 

Also, I think the contest challenges were too long.  The code itself wasn't really that hard to wrap one's head around.  Just a whole bunch of little things that add up to having a long project to do.  And on top of that, we would give the people like 1-2 months to do it.  Virtually every contest idea brought to the table involved doing things that took a long time to do.  I think if we were to consider running contests again, the challenge and contest duration would have to be significantly smaller.

Makes sense. I was thinking more of not a contest, just a learning curve thing. Say, here is the daily code, if you want code it and post it in this forum for critique and that would give the learners something to do that they could get critiqued on and urge them to try new stuff and know they have support.

 

I would say that the admins would not have to critique every code, leave that up to users who would like to. And definately not make it so complex that it takes a month to do, but if it can be done in a couple days by non-advance that would be kinda fun.

 

So I guess I am not looking for a contest between users more of a help session, such as for example :

 

This week's code project is create a Quadratic Equation solver that will solve any possible quadratic equation given and display all the steps to the user. Must include a form to pass data in and display the results in a viewable fashion.

 

I am not sure that anyone would do it, I know I would if I had a few hours of bordem (I actually just did that cause I was bored yesterday). I dunno, I like to see how other people take to solve problems and you can find new ways to make your code more reliable and efficient.

 

Anyhow just an idea I thought would be cool =)

This week's code project is create a Quadratic Equation solver that will solve any possible quadratic equation given and display all the steps to the user. Must include a form to pass data in and display the results in a viewable fashion.

 

I wouldn't know how to do that. I can do it in hand, but I wouldn't know how to put it into code.

This week's code project is create a Quadratic Equation solver that will solve any possible quadratic equation given and display all the steps to the user. Must include a form to pass data in and display the results in a viewable fashion.

 

I wouldn't know how to do that. I can do it in hand, but I wouldn't know how to put it into code.

 

I tried it last night, not fully tested but for my simple tests it worked. Right now it is just a function, but yea.

 

<?php
function solve_quadratic($a, $b, $c) {
if ((2 * $a) == 0) {
	$x[0] = "Cannot divide by 0, this is impossible to do.";
	return $x;
}

$x[0] = ((($b * -1) + sqrt((pow($b, 2) - (4 * $a * $c)))) / (2 * $a));
$x[1] = ((($b * -1) - sqrt((pow($b, 2) - (4 * $a * $c)))) / (2 * $a));
if ($x[0] == "NAN" || $x[1] == "NAN") {
	$x[0] = "This quadratic is not solveable."; 
	unset($x[1]);
	return $x;
}else {	
	$x[2] = ($b * -1) . " +/- SquareRoot (" . $b . "^2 - 4*$a*$c) / 2 * $a";
	$x[3] = ($b * -1) . " +/- SquareRoot (" . pow($b, 2) . " + " . (4 * $a * $c) . ") / " . (2 * $a);
	$x[4] = ($b * -1) . " +/- SquareRoot (" . (pow($b, 2) + (4 * $a * $c)) . ") / " . (2 * $a);
	$x[5] = ($b * -1) . " +/- " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a);
	$x[6] = ($b * -1) . " + " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a);
	$x[7] = ($b * -1) . " - " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a);
	$x[8] = ($b * -1) + sqrt(pow($b, 2) - (4 * $a * $c)) . " / 2 = " . (($b * -1) + sqrt(pow($b, 2) - (4 * $a * $c))) / 2;
	$x[9] = ($b * -1) - sqrt(pow($b, 2) - (4 * $a * $c)) . " / 2 = " . (($b * -1) - sqrt(pow($b, 2) - (4 * $a * $c))) / 2;
}
return $x;
}

echo "<pre>";
print_r(solve_quadratic(1, 3, -4));
echo "<br />";
?>

 

lol I was pretty bored yestarday, day off for Veterans Day.

Funny, that is where this idea came from. I have been working at it just cause I hate regex and need to get better at it.

 

I originally posted my take on it in the thread but decided to remove it due to me feeling like I would be helping him cheat, and offered up some advice instead.  Since I'm fairly sure the guy isn't going to randomly walk into this thread in this forum, I'll post what I came up with here.  I'm not all that great at coding and I'm sure there's more clever ways to do it, and in fact, I know I can streamline it a bit already, but anyways...

 

<?php
// array of example acronyms/meanings
$examples = array(
   "RADIUS"   => "Remote Authentication Dial In User Service",
   "TCP/IP"    => "Transmission Control Protocol / Internet Protocol",
   "FedExDel" => "Federal Express Delivery",
   "Bigpost"   => "Big Post",
   "R.I.P."     => "Rest In Pieces",
   "Cisco"     => "San Francisco",
   "ragnat"    => "Teragen International");

/*** function to determine what type, if any, the acronym is. ***/
function findAcronymType($acronym, $meaning) {

/*** If there is a special char somewhere, get rid of it ***/
// array of special chars. Feel free to add to it 
$sChars = array('/','.');
// remove each special char
foreach ($sChars as $val) {
   $acronym = str_replace($val,'',$acronym);
   $meaning = str_replace($val,'',$meaning);
} // end foreach   
// get rid of extra whitespace in acryonym
$acronym = str_replace(' ','',$acronym);
// get rid of extra whitespace in meaning
$meaning = explode(' ',$meaning);
foreach ($meaning as $key => $val) {
   if (trim($val) == '') unset($meaning[$key]);
} // end foreach $meaning
$meaning = implode(' ',$meaning);
/*** end get rid of special chars ***/

// *** check if type Simple ***
// get rid of caps
$tAcronym = strtolower($acronym);
$tMeaning = strtolower($meaning);
// make some arrays 
$tAcronym = str_split($tAcronym);
$tMeaning = explode(' ',$tMeaning);
// loop through each word in meaning and 
// chop everything off except first letter
foreach ($tMeaning as $key => $val) {
   $tMeaning[$key] = substr($val,0,1);
} // end foreach $tMeaning
// if the two arrays match, we have a winner!
if ($tAcronym == $tMeaning) {
   return "Simple";
} // *** end check if type Simple ***

// *** check if type Complex ***
// get rid of caps
$tAcronym = strtolower($acronym);
// get rid of caps and make an array of words
$tMeaning = explode(' ',strtolower($meaning));
// loop through each word in meaning, starting
// with last word, ending in first
for ($mPos = count($tMeaning)-1; $mPos >= 0; $mPos--) {
   // found out how many letters are in the acronym
   $cALen = strlen($tAcronym);
   // loop from 0 to however long the acronym is
   for ($aPos = 0; $aPos < $cALen; $aPos++) {
      // idea here is to take the acronym vs. word and 
      // slice off letters at beginning of acronym, end of word
      // and compare the result.  
      $aRange = substr($tAcronym,$aPos, $cALen);
      $mRange = substr($tMeaning[$mPos],0,$cALen-$aPos);
      // if we have a match...
      if ($aRange == $mRange) {
         // chop off the matched part off the end of acronym, so 
         // next loop iteration will use what's left of the acronym and go from there
         $tAcronym = substr($tAcronym,0,-strlen($aRange));
         // store the match in an array and break out of this current loop iteration
         $match[$mPos] = $aRange;
         break;
      } // end if
   } // end for
   // if any of the iterations do not yield a match, no point in 
   // continuing the loops, as it will not be a complex acronym
   if (!$match) break;
} // end for
// if we have some results...
if (is_array($match)) {
   // sort them (remember, we started back to front)
   ksort($match);
   // make a string out of the array
   $match = implode('',$match);
   // compare the result to the acronym. If they match, we have a winner!
   if (strtolower($acronym) == $match) {
      return "Complex";
   } // end if
} // *** end check if complex ***

// *** check if type Substring ***
// get rid of caps
$tAcronym = strtolower($acronym);
$tMeaning = strtolower($meaning);
// make an array of letters form acronym
$tAcronym = str_split($tAcronym);
// wrap all the letters up with "match everything" regex
$tAcronym = "(.*)" . implode("(.*)",$tAcronym) . "(.*)";
// check if the acronym can be linearly spelled out in the meaning
// if it can, we have a winner!
if (preg_match("/" . $tAcronym . "/",$tMeaning)) {
   return "Substring";
} // *** end check if type Substring ***

/*** Invalid acronym/meaning type ***/ 
// If we have gotten this far, then we do not 
// have a real acronym/meaning pair.
return "Acronym and Meaning do not match.";
// *** End invalid type ***

} // end function findAcronymType 

// example loop to loop through the example acronyms/meanings
foreach ($examples as $acronym => $meaning) {
   echo "$acronym : $meaning -> " . findAcronymType($acronym, $meaning) . "<br/>";
} // end foreach $examples
?>

This week's code project is create a Quadratic Equation solver that will solve any possible quadratic equation given and display all the steps to the user. Must include a form to pass data in and display the results in a viewable fashion.

 

I wouldn't know how to do that. I can do it in hand, but I wouldn't know how to put it into code.

 

I tried it last night, not fully tested but for my simple tests it worked. Right now it is just a function, but yea.

 

<?php
function solve_quadratic($a, $b, $c) {
if ((2 * $a) == 0) {
	$x[0] = "Cannot divide by 0, this is impossible to do.";
	return $x;
}

$x[0] = ((($b * -1) + sqrt((pow($b, 2) - (4 * $a * $c)))) / (2 * $a));
$x[1] = ((($b * -1) - sqrt((pow($b, 2) - (4 * $a * $c)))) / (2 * $a));
if ($x[0] == "NAN" || $x[1] == "NAN") {
	$x[0] = "This quadratic is not solveable."; 
	unset($x[1]);
	return $x;
}else {	
	$x[2] = ($b * -1) . " +/- SquareRoot (" . $b . "^2 - 4*$a*$c) / 2 * $a";
	$x[3] = ($b * -1) . " +/- SquareRoot (" . pow($b, 2) . " + " . (4 * $a * $c) . ") / " . (2 * $a);
	$x[4] = ($b * -1) . " +/- SquareRoot (" . (pow($b, 2) + (4 * $a * $c)) . ") / " . (2 * $a);
	$x[5] = ($b * -1) . " +/- " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a);
	$x[6] = ($b * -1) . " + " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a);
	$x[7] = ($b * -1) . " - " . sqrt(pow($b, 2) - (4 * $a * $c)) . " / " . (2 * $a);
	$x[8] = ($b * -1) + sqrt(pow($b, 2) - (4 * $a * $c)) . " / 2 = " . (($b * -1) + sqrt(pow($b, 2) - (4 * $a * $c))) / 2;
	$x[9] = ($b * -1) - sqrt(pow($b, 2) - (4 * $a * $c)) . " / 2 = " . (($b * -1) - sqrt(pow($b, 2) - (4 * $a * $c))) / 2;
}
return $x;
}

echo "<pre>";
print_r(solve_quadratic(1, 3, -4));
echo "<br />";
?>

 

lol I was pretty bored yestarday, day off for Veterans Day.

 

Oh, yeah if you already know what a, b, and c are then it's fairly easy, but take an equation like this:

(25*46x)(13*(-13x)) = -32

 

That's a quadratic equation, but how would you solve it using PHP? The answer is (rounded to 3 decimals):

x = -0.013 or x = 0.013

Oh, yeah if you already know what a, b, and c are then it's fairly easy, but take an equation like this:

(25*46x)(13*(-13x)) = -32

 

That's a quadratic equation, but how would you solve it using PHP? The answer is (rounded to 3 decimals):

x = -0.013 or x = 0.013

 

I knew I was missing something from that. lol I could not put my finger on it, now I have to go and re-do my code to take in an unknown and solve it lol.

 

=)

To be honest, the main reason the competitions failed to move forward was more of a lack of judges and prizes.  I doubt a weekly competition would work, let alone daily.

 

I could maybe see monthly, but even that is a long shot.  And people are only going to compete at a certain level without prizes.

To be honest, the main reason the competitions failed to move forward was more of a lack of judges and prizes.  I doubt a weekly competition would work, let alone daily.

 

I could maybe see monthly, but even that is a long shot.  And people are only going to compete at a certain level without prizes.

 

I guess what I am getting out is not necessarily a competition with prizes, just a fun piece of code for someone who wants to learn and get peer-critiqued to write.

 

But yea, just an idea =)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.