By Peter Bell

FizzBuzz in CF

Couldn't help myself - FizzBuzz is strangely addictive- kind of like Twitter for people with no friends :-> Here is a simple but ugly ColdFusion implementation . . .

<cfset Count = 1>
<cfset FizzCount = 5>
<cfset BuzzCount = 3>
<cfset TotalCount = 100>
<cfloop condition="#Count# LTE #TotalCount#">
   <cfif (NOT (Count MOD FizzCount)) AND (NOT (Count MOD BuzzCount))>
      <cfoutput>FizzBuzz</cfoutput>
   <cfelseif NOT (Count MOD FizzCount)>
      <cfoutput>Fizz</cfoutput>      
   <cfelseif NOT (Count MOD BuzzCount)>
      <cfoutput>Buzz</cfoutput>
   <cfelse>
      <cfoutput>#Count#</cfoutput>
   </cfif>
   <cfoutput><br /></cfoutput>
<cfset Count = Count + 1>
</cfloop>

Comments
Peter,

Where are the Unit tests?

Will this be included in Lightwire?

dw
# Posted By Dan Wilson | 3/13/07 12:12 PM
Ask Paul Kenney about the unit tests. I heard a rumor he was going to use FizzBuzz as one of the real world samples he'll be adding to the documentation for cfcunit.

As for LightWire, I am afraid not. There is just too much code in FizzBuzz so it doesn't fit with the minimalist LightWire approach. We've already bloated up to two core files plus a config. If I start adding FizzBuzzs, pretty soon you'll need to buy an extra hard drive to download it :->
# Posted By Peter Bell | 3/13/07 12:38 PM
Now hear this. There will be no FizzBuzz samples included with cfcUnit. They will not be part of the core framework. Now as a thrid party extension...
# Posted By Paul Kenney | 3/13/07 1:30 PM
Well, maybe you could fit it in the test runner framework? I hear you have more room for extras there :->
# Posted By Peter Bell | 3/13/07 1:36 PM
The current cfweekly quiz is a variant of FizzBuzz... maybe you should submit your entry? :)
# Posted By Sean Corfield | 3/13/07 2:39 PM
Not until I get the unit tests done! Still at least I have an excuse with the site being down :->
# Posted By Peter Bell | 3/13/07 3:19 PM
I knew it wouldn't be long until /someone/ did it. I thought about it, but had to pry myself away =)

And regarding LightWire, I think it would be so much cooler if for every 3rd object it instantiated it instead printed out "Fizz", every 5th "Buzz", and ...
# Posted By Sam | 3/19/07 12:45 PM
I like it! A temperamental DI engine. Perhaps it could even stop working on certain days of the month or on the Monday after Superbowl Sunday?!
# Posted By Peter Bell | 3/19/07 12:53 PM
+1 on taking the day off the day after Superbowl Sunday. DI on that Sunday stands for Drunk and Incapable... so he'll need a day off to recover, naturally.
# Posted By Sam | 3/19/07 1:06 PM
:->
# Posted By Peter Bell | 3/19/07 1:18 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.