SitePoint Sponsor

User Tag List

Page 8 of 9 FirstFirst ... 456789 LastLast
Results 176 to 200 of 219

Thread: PHP Quiz

  1. #176
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You looked!













    Your question Mr anode

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  2. #177
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't, it popped up on one of the PHP sites' RSS feeds earlier today and I took note.

    Ok...

    Turn this array:
    Apple =>Jobs
    Microsoft =>Gates
    Oracle => Ellison
    Sun => McNealy

    into this one

    ylaencm => nus
    nosille =>elcaro
    setag => tfosorcim
    sboj => elppa

    Using the least lines of code possible
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  3. #178
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nah! I am PHP.
    Aaron Brazell
    Technosailor



  4. #179
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

        $firstArr 
    = array ( 'Apple' => 'Jobs''Microsoft' => 'Gates''Oracle' => 'Ellison''Sun' => 'McNealy');

        
    $firstArr array_flip array_reverse $firstArr ) );

        foreach ( 
    $firstArr as $key => $val ) {

            
    $key strrev strtolower $key ) );

            
    $secondArr[$key] = strrev strtolower $val ) );

        }

    ?>
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #180
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it may be able to be just a bit shorter(I'm specifically thinking of all the Lisp-like array functions), but I'll accept that.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  6. #181
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you come up with a way to do it? I'm sure it could be shorter

    Anybody want to ask a question?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #182
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I have my coffee I will. I forget the specifics of working with array_map and friends, but I had a rough plan of how I'd do it when I came up with the question.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  8. #183
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $array array_change_key_case(array_reverse(array_flip(array('Apple' => 'Jobs''Microsoft' => 'Gates''Oracle' => 'Ellison''Sun' => 'McNealy'))), CASE_LOWER);
    foreach (
    $array as $key => $content$new_array[strrev($key)] = strtolower(strrev($content)); 
    You said shortest number of lines right?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  9. #184
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cyborg from dh
    PHP Code:
    $array array_change_key_case(array_reverse(array_flip(array('Apple' => 'Jobs''Microsoft' => 'Gates''Oracle' => 'Ellison''Sun' => 'McNealy'))), CASE_LOWER);
    foreach (
    $array as $key => $content$new_array[strrev($key)] = strtolower(strrev($content)); 
    You said shortest number of lines right?
    Now that you mention it
    PHP Code:
    foreach ((array_change_key_case(array_reverse(array_flip(array('Apple' => 'Jobs''Microsoft' => 'Gates''Oracle' => 'Ellison''Sun' => 'McNealy'))), CASE_LOWER)) as $key => $content$new_array[strrev($key)] = strtolower(strrev($content)); 
    In your face, Perl!
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  10. #185
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    damn you!
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  11. #186
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    foreach(array_reverse(array_flip(array('Apple'=>'Jobs','Microsoft'=>'Gates','Oracle'=>'Ellison','Sun'=>'McNealy')))as$k=>$c)$n[strtolower(strrev($k))]=strtolower(strrev($c)); 
    there. [img]images/smilies/tongue.gif[/img]
    Last edited by cyborg from dh; May 29, 2003 at 10:06.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  12. #187
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's have a question from someone

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  13. #188
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    define('C''f');
    define('S' strtoupper(str_rot13(C)), 'c'0);
    $d '2.';
    $q 'S';
    list (
    $x$y) = array('p''gg');
    $b substr(str_rot13('a'.$x.'xy'.$y), 1, -4);
    $c = ($e 'a') . (25 2) . ($f 22 45);
    ${
    'a1'.${((${'h'} = SS) ? ++$h 0)}.'5'.(($g 126 5) + ($g 1.5))} = (float) ($d . ($f 1.9047619047619));
    $a = ${${$b}};
    ob_start();
    var_dump(${$e});
    eval(
    '${S'.$q.'} = substr(strrchr(ob_get_contents(), substr(\'(\',0)), 1, -(int) substr($c, 2, -2)) . round(floor($$b));');
    ob_end_clean();
    echo $
    $b
    What's the output?
    Last edited by cyborg from dh; Jun 19, 2003 at 15:26.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  14. #189
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, man... so tempting to simply run code... but I can resist. :-)

    Good one, cyborg! Either really evil or there's a trick to it, I'm banking on the later as the former would require doing str_rot13 conversions by hand.

    Man, I had never even heard of str_rot13 before. That's a wacky function.

    Ok, I've stared at this for about five minutes, and I'm not coming up with a trick to it. Hopefully someone else is more devious than I. :-)
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  15. #190
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sam, do it on paper.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  16. #191
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But wouldn't that be kind of like just running the script?

    If I follow the documentation and do it by hand it'll essentially just execute like PHP would do it... only much much much slower.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  17. #192
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    But wouldn't that be kind of like just running the script?

    If I follow the documentation and do it by hand it'll essentially just execute like PHP would do it... only much much much slower.
    Sure, but it's a learning experience, as opposed to running it.

    Personally, I got tripped up by the bitwise stuff and gave up. I'll try it if I ever read more Knuth
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  18. #193
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no trick to it, I started out with a basic thing, and kept adding more and more stuff.

    The bitwise thing is about the hardest part.


    (Thought I'd revive this thread with something more difficult [img]images/smilies/wink.gif[/img], oh yeah, and doing it on paper's not cheating, you are still figuring it out, and the PHP Parser's not.)
    Last edited by cyborg from dh; Jun 19, 2003 at 21:14.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  19. #194
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll give you hint on what the value of the bitwise equation: It's half of double 6.3, that's all i'll say.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  20. #195
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh well, the lazy part of me was hoping that there was some part at the end that made most of the equation irrelevant.

    Whoever gets this needs to show a proof to demonstrate that they did this by hand. :-)
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  21. #196
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump. somebody's gotta do it....
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  22. #197
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Crap. Ok, the whole thing is a bit daunting but none of the steps are THAT bad.

    How about this. Each of use will simplify it one step and post the result and perhaps a brief rationalization for that simplification. We'll continue until it's solved.

    I'll begin.

    (Used this as help with the bitwise stuff)
    PHP Code:
    define('C''f');
    define('SPc'0);

    $d '2.';
    $q 'S';

    $x 'p';
    $y 'gg';


    $b 'c';

    // $c = '1' . (25 / 2) . ($f = 22 | 45);

    /*
    22 / 2 == 11 r 0
    11 / 2 == 5  r 1
     5 / 2 == 2  r 1
     2 / 2 == 1  r 0
     1 / 2 == 0  r 1

    10110 = 22
    */


    /*

    45 / 2 == 22 r 1
    22 / 2 == 11 r 0
    11 / 2 == 5  r 1
     5 / 2 == 2  r 1
     2 / 2 == 1  r 0
     1 / 2 == 0  r 1

    101101 = 45
    */

    /*
    bitwise or:
     10110
    101101
    ------
    111111

    1+2+4+8+16+32 == 63

    so...
    $c = '1' . 12.5 . 63;
    so...
    */

    $c 112.563;

    ${
    'a1'.${((${'h'} = SS) ? ++$h 0)}.'5'.(($g 126 5) + ($g 1.5))} = (float) ($d . ($f 1.9047619047619));
    $a = ${${$b}};
    ob_start();
    var_dump(${$e});
    eval(
    '${S'.$q.'} = substr(strrchr(ob_get_contents(), substr(\'(\',0)), 1, -(int) substr($c, 2, -2)) . round(floor($$b));');
    ob_end_clean();
    echo $
    $b
    There. Hope errors didn't slip in, as humans are prone to that sort of thing. I'm done for the evening as far as this thing is concerned, someone else pitch in a little and I'll get rid of a few more lines. :-)
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  23. #198
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the second define should be
    PHP Code:
    define('SS''c'0); 
    You made another obvious mistake, however you've simplified it so much i'm not sure why you stopped, being so close and all....
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  24. #199
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Elsewhere
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cyborg from dh
    bump. somebody's gotta do it....
    cyborg: I found the answer after quite a bit of work, but I got the wrong answer at first (I checked). After that I did manage to get the right result, but since I'd already seen the correct answer, it feels a bit like cheating.

    I can post a complete solution if it's ok with everyone though.

  25. #200
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Azmo
    cyborg: I found the answer after quite a bit of work, but I got the wrong answer at first (I checked). After that I did manage to get the right result, but since I'd already seen the correct answer, it feels a bit like cheating. [img]images/smilies/xeye.gif[/img]

    I can post a complete solution if it's ok with everyone though. [img]images/smilies/smile.gif[/img]
    Please do. I would be interested in seeing it!


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
  •