I'd write it this way, but only because I'm trying to learn ruby better.

1.upto(100) do |number|
  a=''
  a+= 'fizz' unless number.modulo(3) != 0
  a+= 'buzz' unless number.modulo(5) != 0
  a = number if a.empty?
  puts a
end


---------- Forwarded message ----------
From: Andy Matthews <[EMAIL PROTECTED]>
Date: Feb 27, 2007 6:50 PM
Subject: Fizzbuzz. Simple programming problems.
To: CF-Talk <[email protected]>


I was reading an article titled
(http://www.codinghorror.com/blog/archives/000781.html). The article
talked about programmers applying for positions and not being able to
write code FOR the position for which they're applying. Anyway, the
author came up with a series of small coding challenges meant to prove
that the applicant could in fact write code.

Here's the specific one he mentioned:
Write a program that prints the numbers from 1 to 100.
But for multiples of three print "Fizz" instead of the number.
For the multiples of five print "Buzz".
For numbers which are multiples of both three and five print "FizzBuzz".

Here's what I came up with, I'd be interested in seeing what you guys
might come up with. It took me about 4 or 5 minutes.

<cfoutput>
        <cfloop index="i" from="1" to="100">
                <cfif NOT i MOD (3*5)>
                        fizzbuzz
                <cfelseif NOT i MOD 5>
                        buzz
                <cfelseif NOT i MOD 3>
                        fizz
                <cfelse>
                        #i#
                </cfif>
                <br>
        </cfloop>
</cfoutput>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create Web Applications With ColdFusion MX7 & Flex 2. 
Build powerful, scalable RIAs. Free Trial
http://www.adobe.com/products/coldfusion/flex2/

Archive: 
http://www.houseoffusion.com/groups/CF-Community/message.cfm/messageid:229029
Subscription: http://www.houseoffusion.com/groups/CF-Community/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5

Reply via email to