Questions about programming languages and debugging
Gogeta70
^_^
Posts: 3275 Joined: 25 Jun 2005, 16:00
19
Post
by Gogeta70 » 11 Jun 2006, 20:03
Hey guys, it's been forever since i've coded something, so i decided to make this. Tell me what you guys think...
Taking suggestions!
Source
Last edited by
Gogeta70 on 11 Jun 2006, 22:18, edited 1 time in total.
¯\_(ツ)_/¯ It works on my machine...
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
19
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 11 Jun 2006, 20:28
usrname and pws required.
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.
Gogeta70
^_^
Posts: 3275 Joined: 25 Jun 2005, 16:00
19
Post
by Gogeta70 » 11 Jun 2006, 22:17
Oops, sorry.
user: beta
pass: tester
By the way, you can see it in action here:
Link
¯\_(ツ)_/¯ It works on my machine...
FrankB
Ph. D. in Sucko'logics
Posts: 315 Joined: 06 Mar 2006, 17:00
19
Location: Belgistahn
Contact:
Post
by FrankB » 12 Jun 2006, 06:54
Congratulations.
There is no more to add.
Maybe, there's a shortcut for the arrays but i am not sure, at eye-view, just like that i cannot tell but here's the hint : multidimensional arrays.
Now, i cannot see immediately how you could force that through your code but still, it is a very good exercise and an example for many.
--
FrankB
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
19
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 12 Jun 2006, 12:37
Code: Select all
if(strlen($word) == $amt)
{
$finished = TRUE;
}
else
{
$finished = FALSE;
}
I don't know anything about php but if it works, I think this would be better:
Code: Select all
$finished = (strlen($word) == $amt);
I guess $finished is a bool and the condition return a bool to
I keep looking at the code... why don't u use this condition in the FOR? strlen($word) == $amt ... If WHILE exist in this case it would be more appropriate
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.
Gogeta70
^_^
Posts: 3275 Joined: 25 Jun 2005, 16:00
19
Post
by Gogeta70 » 12 Jun 2006, 18:52
Well nerdz, it'd been about 3 or 4 months since i've coded something in PHP.
That line of code suggested would not work.
Code: Select all
for($finished = FALSE; $finished != TRUE;) //if the word length is > 8 characters, $ finished = false;
{
$tmp1 = count($letters[$last]['ok']) -1; //blah
$tmp2 = rand(0, $tmp1); // blah
$word .= $letters[$last]['ok'][$tmp2]; // blah
$last = $letters[$last]['ok'][$tmp2]; // blah
if(strlen($word) == $amt) // if $word is equal to 8 characters (specified in $amt, then $finished is true, else $finished is false.
{
$finished = TRUE;
}
else
{
$finished = FALSE;
}
}
That's what that part of code means.
¯\_(ツ)_/¯ It works on my machine...
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
19
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 12 Jun 2006, 20:31
I know what the code is doing... but i tought it would like other programming language where
Code: Select all
bool b;
while ( b == true)
{
if ( conditionA)
b = true;
else
b = false;
}
is the same as:
Code: Select all
while (conditionA)
{
//do your code...
}
Sry maybe i'm a bit confuse
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.
Gogeta70
^_^
Posts: 3275 Joined: 25 Jun 2005, 16:00
19
Post
by Gogeta70 » 12 Jun 2006, 21:41
Well i would include the if statement in the for, however it's got to set a variable depending on data, which takes more than 1 line of code.
for(set the variable; (the if); (the then))
{}
WHOA, i just kinda corrected myself. Now i see where you're coming from. I could do this:
Code: Select all
while(strlen($word) != $amt)
{
do code
}
Thanks for the heads up, nerdz.
Last edited by
Gogeta70 on 13 Jun 2006, 18:08, edited 1 time in total.
¯\_(ツ)_/¯ It works on my machine...
Nerdz
The Architect
Posts: 1127 Joined: 15 Jun 2005, 16:00
19
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:
Post
by Nerdz » 13 Jun 2006, 09:34
No problem
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.