PDA

View Full Version : Will it go through the Green Glass Door?



kochier
08-16-2008, 05:00 AM
Ok so I made a script that checks if something will go through the Green Glass Door or not, it's based off of the game some of us played in school. You can find it implemented here (http://absurdity981.com/willitgothrough106.php), the code is lower down, I moved the code lower as it will spoil the game for those of you who haven't played it (go ahead try to figure it out without looking). Note words you can check are limited to 25 characters (more than enough I would think) and you can only check one word at a time. If you put in multiple words it will ignore all the words but the first word.






































<p>You are walking through a forest and all of a sudden you come upon a magic Green Glass Door. You walk around the window, trying to find a way through, but you can't figure out how to get through the door. As you continue your investigations you find only certain objects can go through. Can you figure out what can and can not go through the Green Glass Door, can you figure out the magic behind the door?</p>
<ul>
<li>Trees can go through the green glass door, but no branches.</li>
<li>There is a hell beyond the green glass door, but no heaven.</li>
<li>There is Google and Yahoo on the other side of the green glass door, but no Microsoft.</li>
<li>There are tomorrows, but no yesterdays.</li>
</ul>
<form method = "post" id = "form" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<p>
<input type ="text" name="Name" size="30" /><br />
Will it go through the Green Glass Door?<br />
<input name ="update" title = "Check and see" type ="submit" value="Check To See" /><br />
</p>
</form>
<?php
function first_words($Name, $num2, $num)
{
$words = str_word_count($Name, 2);
$firstwords = array_slice( $words, $num2, $num);
return implode(' ', $firstwords);
}
if(isset($_POST['update']))
{
$Name = $_POST['Name'];
$Name = preg_replace("/[^a-zA-Z]/", "\n", $Name);
$Name2 = first_words($Name, 0, 1);
$Name3 =first_words($Name, 1, 1);
if (preg_match('/([a-z])\1/i', $Name2) and empty($Name3))
{
echo $Name2 .' will go through the Green Glass Door.';
}
else
{
if (preg_match('/([a-z])\1/i', $Name2) and preg_match('/([a-z])\1/i', $Name3))
{
echo $Name2 .' ' .$Name3 .' will go through the Green Glass Door.';
}
else
{
if (preg_match('/([a-z])\1/i', $Name2) or preg_match('/([a-z])\1/i', $Name3))
{
echo $Name2 .' ' .$Name3 .' will both go through and not go through the Green Glass Door.';
}
else
{
if (!empty($Name3))
{
echo $Name2 .' ' .$Name3 .' will not go through the Green Glass Door.';
}
else
{
echo $Name2 .' will not go through the Green Glass Door.';
}
}
}
}
}
?>

shyam
08-16-2008, 04:26 PM
unless there is some obvious attempt at obfuscation you could do this


if ( preg_match('/([a-z])\1/i', $Name) ) {
echo $Name .' will go through the Green Glass Door.';
} else {
echo $Name .' will not go through the Green Glass Door.';
}

samsfriend
08-16-2008, 04:48 PM
I just want say, I love that game! We still use it on new friends to see if they can figure it out.

kochier
08-17-2008, 12:44 AM
Well that actually is a lot easier, so welcome to version 1.1 of the Green Glass Door game.
-I've added an intro to the game, with a few examples.
-I've used preg_match instead of splitting everything up into a million strings.



<p>You are walking through a forest and all of a sudden you come upon a magic Green Glass Door. You walk around the window, trying to find a way through, but you can't figure out how to get through the door. As you continue your investigations you find only certain objects can go through. Can you figure out what can and can not go through the Green Glass Door, can you figure out the magic behind the door?</p>
<ul>
<li>Trees can go through the green glass door, but no branches.</li>
<li>There is a hell beyond the green glass door, but no heaven.</li>
<li>There is Google and Yahoo on the other side of the green glass door, but no Microsoft.</li>
<li>There are tomorrows, but no yesterdays.</li>
</ul>
<form method = "post" id = "form" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<p>
<input type ="text" name="Name" size="30" /><br />
Will it go through the Green Glass Door?<br />
<input name ="update" title = "Check and see" type ="submit" value="Check To See" /><br />
</p>
</form>
<?php
function first_words($Name, $num)
{
/** words into an array **/
$words = str_word_count($Name, 2);
/*** get the first $num words ***/
$firstwords = array_slice( $words, 0, $num);
/** return words in a string **/
return implode(' ', $firstwords);
}
if(isset($_POST['update']))
{
$Name = $_POST['Name'];
$Name = preg_replace("/[^a-zA-Z]/", "\n", $Name);
$Name = first_words($Name, 1);
if ( preg_match('/([a-z])\1/i', $Name) ) {
echo $Name .' will go through the Green Glass Door.';
} else {
echo $Name .' will not go through the Green Glass Door.';
} }
?>

kochier
08-17-2008, 03:51 AM
Alright on request, version 1.2
-Added support for two words, for example Mary Poppins will both go through and not go through the Green Glass Door.



<p>You are walking through a forest and all of a sudden you come upon a magic Green Glass Door. You walk around the window, trying to find a way through, but you can't figure out how to get through the door. As you continue your investigations you find only certain objects can go through. Can you figure out what can and can not go through the Green Glass Door, can you figure out the magic behind the door?</p>
<ul>
<li>Trees can go through the green glass door, but no branches.</li>
<li>There is a hell beyond the green glass door, but no heaven.</li>
<li>There is Google and Yahoo on the other side of the green glass door, but no Microsoft.</li>
<li>There are tomorrows, but no yesterdays.</li>
</ul>
<form method = "post" id = "form" action = "<?php echo $_SERVER['PHP_SELF'];?>">
<p>
<input type ="text" name="Name" size="30" /><br />
Will it go through the Green Glass Door?<br />
<input name ="update" title = "Check and see" type ="submit" value="Check To See" /><br />
</p>
</form>
<?php
function first_words($Name, $num2, $num)
{
$words = str_word_count($Name, 2);
$firstwords = array_slice( $words, $num2, $num);
return implode(' ', $firstwords);
}
if(isset($_POST['update']))
{
$Name = $_POST['Name'];
$Name = preg_replace("/[^a-zA-Z]/", "\n", $Name);
$Name2 = first_words($Name, 0, 1);
$Name3 =first_words($Name, 1, 1);
if (preg_match('/([a-z])\1/i', $Name2) and empty($Name3))
{
echo $Name2 .' will go through the Green Glass Door.';
}
else
{
if (preg_match('/([a-z])\1/i', $Name2) and preg_match('/([a-z])\1/i', $Name3))
{
echo $Name2 .' ' .$Name3 .' will go through the Green Glass Door.';
}
else
{
if (preg_match('/([a-z])\1/i', $Name2) or preg_match('/([a-z])\1/i', $Name3))
{
echo $Name2 .' ' .$Name3 .' will both go through and not go through the Green Glass Door.';
}
else
{
if (!empty($Name3))
{
echo $Name2 .' ' .$Name3 .' will not go through the Green Glass Door.';
}
else
{
echo $Name2 .' will not go through the Green Glass Door.';
}
}
}
}
}
?>

Inigoesdr
08-18-2008, 01:23 AM
You should make a note in your original post that there is a newer version further down, or move the updated version to the original post.

kochier
08-18-2008, 05:11 AM
You should make a note in your original post that there is a newer version further down, or move the updated version to the original post.

Done that, put the updated version in my first post.

gregmcdonald
11-22-2008, 06:17 PM
does anyone know of the green glass door beyond the trees?