Created
June 12, 2011 04:17
-
-
Save dbrady/1021248 to your computer and use it in GitHub Desktop.
FizzBuzz!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Transcript clear. | |
(1 to: 100) do: [ :i | (i \\ 15 = 0) | |
ifTrue: [Transcript show: 'FizzBuzz'] | |
ifFalse: [ | |
(i \\ 3 = 0) | |
ifTrue: [ Transcript show: 'Fizz'] | |
ifFalse: [ | |
(i \\ 5 = 0) | |
ifTrue: [ Transcript show: 'Buzz' ] | |
ifFalse: [Transcript show: i]. | |
]. | |
]. | |
Transcript cr. | |
]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about this?
| mapping |
mapping := { [:i | i \ 15 = 0] -> 'FizzBuzz' .
[:i | i \ 3 = 0] -> 'Fizz' .
[:i | i \ 5 = 0] -> 'Buzz' }.
(1 to: 100) do: [:i |
Transcript show: (mapping
detect: [:assoc | assoc key value: i]
ifNone: [nil -> i]) value; cr].