RosettaCodeData/Task/Look-and-say-sequence/Smalltalk/look-and-say-sequence-2.st
2020-02-17 23:21:07 -08:00

30 lines
795 B
Smalltalk

String compile:
'lookAndSay |anElement nextElement counter coll newColl|
coll := (self asOrderedCollection).
newColl := OrderedCollection new.
counter := 0.
anElement := (coll first).
[ coll size > 0 ]
whileTrue: [
nextElement := coll removeFirst.
( anElement == nextElement ) ifTrue: [
counter := counter + 1.
] ifFalse: [
newColl add: (counter displayString).
newColl add: (anElement asString).
anElement := nextElement.
counter := 1.
]
].
newColl add: (counter displayString).
newColl add: (anElement asString).
^('''' join: newColl)'
classified: 'toys'.
result := OrderedCollection new.
r := '1'.
result add: r.
result addAll: ((1 to: 10) collect: [ :i |
r := r lookAndSay.
]).
result.