Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Golf Challenge: FizzBuzz

by shmem (Canon)
on Mar 03, 2007 at 00:29 UTC ( #602996=note: print w/ replies, xml ) Need Help??


in reply to Golf Challenge: FizzBuzz

This is my entry on FizzBuzz:

print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..100
or in words: since for any n multiple of 3 n % 3 == 0 I just make a list which has Fizz at index 0 and nothing else in it, and pull the (n%3)th element out of that list. Same for 5. Then I concatenate them together, print the result of that if it's true (not empty string), otherwise just n; then the default input record separator. Repeat for 1 to 100.

Straight forward and (almost) readable code (just add whitespace :-)

--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}


Comment on Re: Golf Challenge: FizzBuzz
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-11-27 17:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (186 votes), past polls