Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Will it go through the Green Glass Door?

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





































    PHP Code:
    <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($Name2);
            
    $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($Name01);
    $Name3 =first_words($Name11);
    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.';
    }
    }
    }
    }
    }
    ?>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    unless there is some obvious attempt at obfuscation you could do this

    PHP Code:
    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.';

    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    51
    Thanks
    18
    Thanked 0 Times in 0 Posts
    I just want say, I love that game! We still use it on new friends to see if they can figure it out.

  • #4
    Regular Coder
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    18
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    <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($Name2);
            
    /*** get the first $num words ***/
            
    $firstwords array_slice$words0$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($Name1);
    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.';
    } }
    ?>

  • #5
    Regular Coder
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    18
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    <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($Name2);
            
    $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($Name01);
    $Name3 =first_words($Name11);
    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.';
    }
    }
    }
    }
    }
    ?>

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Jul 2008
    Posts
    136
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    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.

  • #8
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    green glass door

    does anyone know of the green glass door beyond the trees?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •