SitePoint Sponsor

User Tag List

Page 2 of 5 FirstFirst 12345 LastLast
Results 26 to 50 of 114
  1. #26
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    for (
        
    $time = (string) strtotime('Fri, 13 Feb 2009 23:31:30 GMT'),
        
    $time substr($time, -1).substr($time0, -1),
        
    $len  strlen($time),
        
    $pos  0;
        
    $pos $len;
        print(
    $time[$pos++])
    ); 
    Any solution using Friday the 13th has got to be worth a good mark.
    Salathe
    Software Developer and PHP Manual Author.

  2. #27
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I'm surprised there has been no binary shenanigans!
    PHP Code:
    <?php
    for($i=0;$i<=9;$i++){
    $aData explode('2','02121021121002101211021112100021001');
    echo 
    bindec($aData[$i]).'<br />';
    }
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #28
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Mine was kind of binary... just used for loops to generate the binary string then convert :P

  4. #29
    Sesame Street Iimitk's Avatar
    Join Date
    Feb 2006
    Posts
    662
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $i 0;
    do {
        echo 
    "$i ";
        
    $i++;
    } while (
    $i <= 9); // $i < 10 will print 10. 
    Off Topic:

    Too bad there's no longer Funniest Thread of The Year award.
    Last edited by Iimitk; Nov 5, 2008 at 16:50.
    Imagination is more important than knowledge. - Einstein

  5. #30
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Meets the technical requirements but obviously not the intent.
    PHP Code:

    try{
        for(
    $i='Q'$i<17$i++) {
            throw new 
    Exception('Monkey');
        }
    }
    catch (
    Exception $e) {
        echo 
    '0123456789';

    Last edited by QMonkey; Nov 5, 2008 at 18:11.
    - Robert

  6. #31
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    only you forgot to output '0' :P

    Rather a strange way of doing it, but interesting anyway

    We should have 'obscure ways of solving problems' threads...

  7. #32
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah, yes. 0-9 I edited it to help anyone in the future looking for this very useful solution.
    - Robert

  8. #33
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some simple solutions:
    PHP Code:
     
    for ($ord 48$ord 58$ord++) {
        echo 
    chr($ord);
    }
     
    for (
    $nums range(90); !is_null($n array_pop($nums)); print($n));
     
    for (print(
    '0123456789'); 0;);
     
    for (
    $str '0123456789', print($str); isset($str);) {
        unset(
    $str);
    }
    // var:
    for ($str '0123456789', print($str), $str ''; isset($str);) 

  9. #34
    Non-Member DelvarWorld's Avatar
    Join Date
    Jul 2004
    Location
    Baloney
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No OOP yet?!

    PHP Code:
    Class Counter {
        public 
    $count 0;
        function 
    countMe() {
            echo 
    $count;
            return 
    this;
        }
        function 
    addMe() {
            
    $this->count++;
        }
    }

    $counter = new Counter();
    for(
    $i 0$i 10; $++) {
        
    $counter->countMe()->addMe();

    (thorougly untested)


    Also, people posting do and do/while loops will be banned from this forum for not following the thread rules. You are providing misleading information to newcomers .

  10. #35
    Sesame Street Iimitk's Avatar
    Join Date
    Feb 2006
    Posts
    662
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This thread is starting to get really inspiring.

    I nominate it for highlighting.
    Imagination is more important than knowledge. - Einstein

  11. #36
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Delvar-
    I fixed yours up so it runs, and put it all into a for loop:
    PHP Code:
     
    for ($i 0$i 10$i++) {     
        if (!isset(
    $counter)) {
            class 
    Counter 
            
    {     
                public 
    $count 0;     
                function 
    countMe() 
                {         
                    echo 
    $this->count;         
                    return 
    $this;     
                }     
                function 
    addMe() 
                {
                    
    $this->count++;     
                } 
            }
            
    $counter = new Counter(); 
        }  
        
    $counter->countMe()->addMe(); 


  12. #37
    Non-Member DelvarWorld's Avatar
    Join Date
    Jul 2004
    Location
    Baloney
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by registrant View Post
    Delvar-
    I fixed yours up so it runs, and put it all into a for loop:
    I had no idea you could declare a class inside a for loop. That's frightening.

  13. #38
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yeh, although it's fairly pointless since PHP doesn't have lexical scope (yet).

  14. #39
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ha, and still no reply from the OP.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  15. #40
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    He is probably in a state of shock!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  16. #41
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    for($i=print("01");$i^bindec(1001);print($i^=$i&~-~$i|~$i&-~$i)); 

  17. #42
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by simsim
    I nominate it for highlighting.
    Thread now featured on the home page
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #43
    whagwan? silver trophybronze trophy akritic's Avatar
    Join Date
    Nov 2006
    Posts
    2,780
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:


    Well, you guys should think of having a monthly PHP challenge - a simple problem + the interesting/obscure ways of implementing it... would probably be a popular thing

  19. #44
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I thought of that above I think it would be good fun!

  20. #45
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Code php:
    function check($integer, $beginning, $end) {
     if(is_int($integer)) {
      if(($integer >= $beginning) && ($integer <= $end)) {
       return true;
      }
      else {
       return false;
      }
     }
     else {
      return false;
     }
    }
     
    function write($string) {
     echo $string;
    }
     
    function loop($beginning, $end) {
     for($integer = $beginning; $integer < ($end + 1); $integer++) {
      if(check($integer)) {
       write($integer);
      }
      else {
       write("Something went terribly wrong!");
      }
     }
    }
     
    loop(0, 9);
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  21. #46
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by C. Ankerstjerne View Post
    Code php:
    function check($integer, $beginning, $end) {
     if(is_int($integer)) {
      if(($integer >= $beginning) && ($integer <= $end)) {
       return true;
      }
      else {
       return false;
      }
     }
     else {
      return false;
     }
    }
     
    function write($string) {
     echo $string;
    }
     
    function loop($beginning, $end) {
     for($integer = $beginning; $integer < ($end + 1); $integer++) {
      if(check($integer)) {
       write($integer);
      }
      else {
       write("Something went terribly wrong!");
      }
     }
    }
     
    loop(0, 9);
    Surely this won't work at all, since you don't pass a beginning or end to check() :P

    Corrected:

    PHP Code:
    function check ($integer$beginning$end) {
     if (
    is_int($integer)) {
      if ((
    $integer >= $beginning) && ($integer <= $end)) {
       return 
    true;
      } else {
       return 
    false;
      }
    //if
     
    } else {
      return 
    false;
     }
    //if
    }//function

    function write ($string) {
     echo 
    $string;
    }
    //function

    function loop ($beginning$end) {
     for (
    $integer $beginning$integer < ($end 1); $integer++) {
      if (
    check($integer$beginning$end)) {
       
    write($integer);
      } else {
       
    write("Something went terribly wrong!");
      }
    //if
     
    }//for
    }//function

    loop(09); 

  22. #47
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    PHP Code:
    for($i=print("01");$i^bindec(1001);print($i^=$i&~-~$i|~$i&-~$i)); 
    Bravo!
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  23. #48
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i may as well join in the fun with my "elegant" solution to this riddle!

    PHP Code:
    $lol '0123456789'
    for ( 
    $i=0$i<strlen($lol);  $i++ ){    
       print 
    $lol{$i}.'<br />';    


  24. #49
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    for($i=print(0);$i<=9;$i+=print($i));
    for(
    $i=print(0);$i++<=9;$i+=print(--$i)); 

  25. #50
    SitePoint Zealot Amenthes's Avatar
    Join Date
    Oct 2006
    Location
    Bucharest, Romania
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A little bit of recursion:

    Code PHP:
    function funny($i = 10) {
        if (! $i) return;
        funny($i - print($i - 10));
    }
    I'm under construction | http://igstan.ro/


Bookmarks

Posting Permissions

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