Legible word generator

Questions about programming languages and debugging
Post Reply
User avatar
Gogeta70
^_^
^_^
Posts: 3257
Joined: 25 Jun 2005, 16:00
15

Legible word generator

Post by Gogeta70 »

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

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
15
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

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.

User avatar
Gogeta70
^_^
^_^
Posts: 3257
Joined: 25 Jun 2005, 16:00
15

Post by Gogeta70 »

Oops, sorry.

user: beta
pass: tester

By the way, you can see it in action here: Link
¯\_(ツ)_/¯ It works on my machine...

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
15
Location: Belgistahn
Contact:

Post by FrankB »

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

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
15
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

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 :wink:

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.

User avatar
Gogeta70
^_^
^_^
Posts: 3257
Joined: 25 Jun 2005, 16:00
15

Post by Gogeta70 »

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

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
15
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

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 :roll:
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

User avatar
Gogeta70
^_^
^_^
Posts: 3257
Joined: 25 Jun 2005, 16:00
15

Post by Gogeta70 »

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

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
15
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

No problem :wink:
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

Post Reply