The Artima Developer Community
Sponsored Link

Agile Buzz Forum
The FizzBuzz Test

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
The FizzBuzz Test Posted: Feb 28, 2007 6:17 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: The FizzBuzz Test
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

I ran across this just now (I know Runar posted on it earlier; I wasn't really paying attention then). So anyway, I opened up a workspace in BottomFeeder. Two minutes later:


| stream |
stream := WriteStream on: String new.
1 to: 100 do: [:index |
	(index \\ 3) = 0 
		ifTrue: [stream nextPutAll: '(', index printString, ')', ' fizz '].
	(index \\ 5) = 0 
		ifTrue: [stream nextPutAll: '(', index printString, ')',' buzz '].
	(index \\ 3 ~= 0 and: [index \\ 5 ~= 0])
		ifTrue: [stream nextPutAll: ' ', index printString, ' ']].
^stream contents

You might wonder why I dumped to a stream instead of the Transcript - well, I was doing this in my BottomFeeder runtime, so I didn't have a Transcript to dump to :) The output looks like this - I included the numbers in front of the Fizz and Buzz so I could be lazy about checking the output :)


 1  2 (3) fizz  4 (5) buzz (6) fizz  7  8 (9) fizz (10) buzz  11 (12) fizz  13  14 (15) fizz (15) buzz  
16  17 (18) fizz  19 (20) buzz (21) fizz  22  23 (24) fizz (25) buzz  26 (27) fizz  28  29 
(30) fizz (30) buzz  31  32 (33) fizz  34 (35) buzz (36) fizz  37  38 (39) fizz (40) buzz  
41 (42) fizz  43  44 (45) fizz (45) buzz  46  47 (48) fizz  49 (50) buzz (51) fizz  52  
53 (54) fizz (55) buzz  56 (57) fizz  58  59 (60) fizz (60) buzz  61  62 (63) fizz  
64 (65) buzz (66) fizz  67  68 (69) fizz (70) buzz  71 (72) fizz  73  74 (75) fizz (75) buzz  
76  77 (78) fizz  79 (80) buzz (81) fizz  82  83 (84) fizz (85) buzz  86 (87) fizz  88  
89 (90) fizz (90) buzz  91  92 (93) fizz  94 (95) buzz (96) fizz  97  98 (99) fizz (100) buzz 


Update: Dohhh - what if it's both :)

Read: The FizzBuzz Test

Topic: Turn it up to 11 Previous Topic   Next Topic Topic: March Design Improvement EAT Workshop

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use