Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Do you know where your variables are?
 
PerlMonks  

Re: Golf Challenge: FizzBuzz

by merlyn (Sage)
on Mar 02, 2007 at 16:48 UTC ( #602904=note: print w/ replies, xml ) Need Help??


in reply to Golf Challenge: FizzBuzz

Not really a golf entry, because Perl Golf is hurting the Perl community, and I object to that, but here's my "brief" entry first attempt:

print "$_\n" for map { ($_ % 3 ? "": "Fizz").($_ % 5 ? "" : "Buzz") || + $_ } 1..100;


Comment on Re: Golf Challenge: FizzBuzz
Download Code
Re^2: Golf Challenge: FizzBuzz
by shmem (Canon) on Mar 03, 2007 at 00:34 UTC
    Mind to elaborate on "Perl Golf is hurting the Perl community"? What kind of aches?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      It contributes to the notion of perl being obscure and hard to read. It's not fair, since golf is a game, not a normal way to write code, but it still reinforces stereotypes for outsiders.
        It contributes to the notion of perl being obscure and hard to read. It's not fair, since golf is a game, not a normal way to write code, but it still reinforces stereotypes for outsiders.

        Well, "outsiders" sometimes still confuse Perl and CGI, or even web server stuff. Who cares anyway? Some C programmers like to play obfu games too. That doesn't give C a bad reputation, though.

        It contributes to the notion of perl being obscure and hard to read.
        For me, it contributes also to the notion that perl is hard to write - summing both: that perl is very sophisticated.

        I like golf not only because it reveals dark corners of perl; it also reveals perl's tremendous ability to eliminate noise and produce dense expressions. Ultimately, golf tends to be noise, when shorter statement can not anymore be contrieved, but even those constructs - add a bit of air (white space) to them, a bit more verbosity, and many of them expand into beautiful, perfectly understandable nailing-downs of solutions to the problem at hand.

        Compare

        %hash = (); { my @keys = qw ( a, b, c); my @values = 1..3; for ( my $c = 0; $c <= $#keys; $c++ ) { $hash { $keys [$c] } = $values [ $c ]; } }

        which is a common idiom in many languages, to

        @hash { qw (a, b, c) } = 1..3;

        of which the latter is the golfed code version, useable in production code, and you must admit that perl to some extent is golf - well, compared to Java anyways ;-)

        Any language is "obscure and hard to read" for those that don't venture into it; and no matter whether that "obscure and hard to read" judgement is uttered as a pretext to not do so, or as a disinformed dismissive, it is just prejudice - and there being perl golf or not doesn't change that in the least.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^2: Golf Challenge: FizzBuzz
by Jenda (Abbot) on Mar 07, 2007 at 14:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://602904]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2014-04-21 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls