[squeak-dev] Hyphenation puzzle/exercise
Stéphane Rollandin
lecteur at zogotounga.net
Fri Mar 10 00:36:15 UTC 2023
> I was toying with different ways to add hyphens to a string in a
> specific pattern, like for a UUID. Here's what I came up with:
>
> | s oc |
> s := 'eg11dc5cad154625885bc70d4f42818e' readStream.
> oc := OrderedCollection new.
> #( 8 4 4 4 12 ) do: [:count | oc add: (s next: count)].
> oc joinSeparatedBy: $-
>
> " 'eg11dc5c-ad15-4625-885b-c70d4f42818e'"
>
>
> Does anyone have any more graceful or clever ways of accomplishing this?
Here is my take:
'eg11dc5cad154625885bc70d4f42818e'
with: 'oooooooopooopooopooopooooooooooo'
collect: [:c :h | h == $p ifTrue: [$-] ifFalse: [c]]
Stef
More information about the Squeak-dev
mailing list
|