99 bottles of beer: Difference between revisions

Line 12,448:
 
 
This version uses Squeak Smalltalk's String >> format: method. and SequencableCollection >> atPin: method
<syntaxhighlight lang="smalltalk">
|bottles plurals |
Transcript clear.
bottles:='{1} bottle{2} of beer on the wall
{31} bottle{42} of beer
Take one down, pass it around
{53} bottle{64} of beer on the wall'.
plurals := #('' 's').
99 to: 1 by: -1 do:[:v |
ifTrue:[ Transcript show: (bottles format: {(v asString) . 's'(plurals . (atPin:v asString) . 's' . ((v -1) asString). 's'(plurals atPin:v) }); cr; cr.].
(v > 1)
 
ifTrue:[Transcript show: (bottles format: {(v asString) . 's' . (v asString) . 's' . ((v -1) asString). 's'}); cr; cr.]
ifFalse:[Transcript show: (bottles format: {(v asString) . '' . (v asString) . '' . ((v -1) asString). ''}); cr; cr.]
].
Transcript show: 'hic!'; cr.
 
</syntaxhighlight>
 
3

edits