Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
In stumbling across this disturbing writeup, the author claims that not only can the majority of comp-sci majors not solve the 'fizzbuzz' problem, but he's also seen "senior" programmers take 10 or 15 minutes to solve it:
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

I was quite sure I had already seen this thing. I thought it must have surely been in clpmisc. So I searched there and... much to my surprise it was actually a thread started by me! (available from Google Groups, too.)

Actually the requirements there were slightly different: to print "'fizz' if the number is divisible by 5, 'buzz' if it is divisible by 7 and 'fizzbuzz' if it is divisible by both." (Dor all numbers from 1 up to 100.) The best solution there was given by Jay Tilton:

print+fizz x/0|5$/.buzz x!($_%7)||$_,$/for 1..100

It can be directly adapted to this thread's "FizzBuzz":

print+Fizz x!($_%3).Buzz x/0|5$/||$_,$/for 1..100

And it's 49. But Sidhekin's solution, if amended with a newline:

print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..100

scores 48, and wins!


In reply to Re: Golf Challenge: FizzBuzz by blazar
in thread Golf Challenge: FizzBuzz by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-20 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found