7 Replies - 965 Views - Last Post: 14 January 2009 - 07:11 PM

#1 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Useless Algorythms

Posted 12 January 2009 - 07:24 AM

About a month ago I was upset with a fellow D.I.C. member, and decided instead of giving the polite "Please show some work you've done, we don't code for free / do homework" post... I wrote an algorythm to determine wether or not I'd help him.


I spent a good 15-30 minutes writing this, and realized that it might be a fun excersize in creative coding to make code for everyday life events. An example would be:

I'm thirsty...
a. Too Tired to move
b. TV is more important.
....1. Could I go on a commercial?
....2. Is this show worth dying of thirst for?
c. I'll have the woman get it.

And so-on.


So with this idea in mind, I'll share my quick project!

<?php
// This will start you out... 
// A PHP algorythm for knowing ahead of time if we will help you or not!


// You start out here like everyone else...
$noob = 'false';

// And post your first topic...
$helpme = $_GET['help'];

// But when you come in here and:
$demands = 'true';

// Without any...
$sample = $_GET['your_code'];

// And you want us to make your $problem = 'solved'; ...
$problem = 'unsolved';



function FREECODE(){
while ($demands = 'true'){
	if (isset($sample)){
		if ($noob = 'true'){
			$demands = 'denied';
			NOSOUP4U();
		} else {
			$demands = 'true';
			GIVEHELP();
		}
	} elseif (!isset($sample)){
		$noob = 'true';
		}
	}
}


function NOSOUP4U(){
$postcount = $_GET['post_count'];
$i = $postcount + 1;

while ($postcount <= $i){
	if ($noob = 'true'){
		echo 'Read a book.';
	} else {
		FREECODE();
	} if ($postcount > $i){
		FREECODE();  // Loop back to see if you are qualified for help yet
		}
	}
}


function GIVEHELP()
{
$response = $_GET['response'];
$answer = $_POST['answer'];
$logic = $_POST['ideas'];

while (isset($sample) && $noob = 'false' && $demands = 'true'){
	echo "How may I be of assistance to you?";
	if ($response = $answer){
		$demands = 'false';
		$problem = 'solved';
	} else {
		$answer = $logic;
		echo "I hope this answer helps!  If you still need help, be sure to send another ".$response."!";
		}
	}
}



// Now that we've declared our scenario's for the Help Algorythm...
// Let's figure out where to start!

if (isset($helpme){
	FREECODE();
} else {
	echo 'Thank god I don't have to write someone elses homework today!';
}

?>





Creative? Anyone ever done something like this?

Share yours!

Is This A Good Question/Topic? 0
  • +

Replies To: Useless Algorythms

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10558
  • View blog
  • Posts: 39,065
  • Joined: 27-December 08

Re: Useless Algorythms

Posted 12 January 2009 - 07:52 AM

Here is the algorithm for my Project Management and Intro. to Java classes. The same teacher teaches both of these classes:

0. Start Class 
1. Sit in seats
2. Review what we did last class
3. Can we open our computers?
	a. Yes:  Is the teacher standing behind me?
		a. Yes:  Open blank word document and alt-tab between screens.
i. Do I want to game or watch sci-fi?
				ii. Game:  Play dicewars
				iii. Sci-fi:  Letís watch Stargate Atlantis
		c. No: 
			i. Do I want to game or watch sci-fi?
				a. Game:  Play dicewars
				b. Sci-fi:  Letís watch Stargate Atlantis

	b. No:  Sleep
4. Is class Over?
	a. Yes:  Leave (END)
	b. No:  Goto 3



Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,462
  • Joined: 29-May 08

Re: Useless Algorythms

Posted 12 January 2009 - 09:01 AM

View Postmacosxnerd101, on 12 Jan, 2009 - 01:52 PM, said:

1. Sit in seats



So you're the person who eat all the pies. ;)
Was This Post Helpful? 0
  • +
  • -

#4 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Useless Algorythms

Posted 12 January 2009 - 09:54 AM

While I didn't see a GPL or similar license, I took the liberty of modifying your code.... :)
<?php
/*
1/12/2009 - Globalized the variables used so they would be accessible in the functions.
*/

// This will start you out... 
// A PHP algorythm for knowing ahead of time if we will help you or not!


// You start out here like everyone else...
$GLOBALS['noob'] = 'false';

// And post your first topic...
$GLOBALS['helpme'] = $_GET['help'];

// But when you come in here and:
$GLOBALS['demands'] = 'true';

// Without any...
$GLOBALS['sample'] = $_GET['your_code'];

// And you want us to make your $problem = 'solved'; ...
$GLOBALS['problem'] = 'unsolved';



function FREECODE(){
while ($GLOBALS['demands'] = 'true'){
	if (isset($GLOBALS['sample'])){
		if ($GLOBALS['noob'] = 'true'){
			$GLOBALS['demands'] = 'denied';
			NOSOUP4U();
		} else {
			$GLOBALS['demands'] = 'true';
			GIVEHELP();
		}
	} elseif (!isset($GLOBALS['sample'])){
		$noob = 'true';
		}
	}
}


function NOSOUP4U(){
$postcount = $_GET['post_count'];
$i = $postcount + 1;

while ($postcount <= $i){
	if ($GLOBALS['noob'] = 'true'){
		echo 'Read a book.';
	} else {
		FREECODE();
	} if ($postcount > $i){
		FREECODE();  // Loop back to see if you are qualified for help yet
		}
	}
}


function GIVEHELP()
{
$response = $_GET['response'];
$answer = $_POST['answer'];
$logic = $_POST['ideas'];

while (isset($GLOBALS['sample']) && $GLOBALS['noob'] = 'false' && $GLOBALS['demands'] = 'true'){
	echo "How may I be of assistance to you?";
	if ($response = $answer){
		$demands = 'false';
		$problem = 'solved';
	} else {
		$answer = $logic;
		echo "I hope this answer helps!  If you still need help, be sure to send another ".$response."!";
		}
	}
}



// Now that we've declared our scenario's for the Help Algorythm...
// Let's figure out where to start!

if (isset($GLOBALS['helpme']){
	FREECODE();
} else {
	echo 'Thank god I don't have to write someone elses homework today!';
}

?>


Was This Post Helpful? 0
  • +
  • -

#5 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Useless Algorythms

Posted 12 January 2009 - 10:15 AM

0. Wake Up
1.Check DIC
-->Find interesting topic?
----> Yes: Post Random stuff, be late to #2.
----> No: Go to #2 on time.
2. Go to class
---->Test today?
------>Yes: Fail because of what happens when there is no test.
------>No:
-------->Check DIC.
---------->Find interesting topic?
------------>Yes: Post Random Topic
------------>No: Create interesting topic
--------->Class done?
----------->Yes: goto #3
----------->No: repeat
3. Another class?
-->Yes: goto #2
-->No: goto #4
4. Home yet
-->Yes: Check DIC
---->Find interesting topic?
------>Yes: Post random stuff.
------> No: Post topics
--->Time to sleep yet?
----->No: repeat
----->Yes: repeat one more time then goto #5
5. Sleep.
-->Restless?
----->Yes:Repeat #4 until really exhausted.
----->No: Dream in code!!! :D
6. goto #1


now I really have to study for that test......Post random stuff :lol:
Was This Post Helpful? 0
  • +
  • -

#6 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: Useless Algorythms

Posted 12 January 2009 - 06:53 PM

Well, thanks snoj :-P

I wasn't exactly trying to make the script flawless in execution with the correct given input... it was more of the READABILITY of the whole thing.

For instance, a non PHP programmer (possibly a non-programmer in general) could read this without getting too confused.

Global variables, ok you win... but READING $GLOBALS['something'] isn't as friendly as reading $something




Got some good suggestions, perhaps I'll code up BigAnt's ideas when I get a spare minute... unless he wanted to do so and was just making notes!

:fool:
Was This Post Helpful? 0
  • +
  • -

#7 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Useless Algorythms

Posted 12 January 2009 - 07:31 PM

Quote

perhaps I'll code up BigAnt's ideas when I get a spare minute... unless he wanted to do so and was just making notes!

Feel Free, I was just delaying studying for my Embedded System Test I had earlier today. :D
Was This Post Helpful? 0
  • +
  • -

#8 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Useless Algorythms

Posted 14 January 2009 - 07:11 PM

Can anybody find the error in my algorithm :(

It seems right, but I didn't fail my test I got a Hundred! :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1