------art_46858_25543943.1228679360192
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

This was a nice quiz, maybe not too challenging, but as Tom put it
correctly the different codes can easily get mangled up. I have found
a solution that seems to handle the few testcases well, we will see if
it pleases ;).
My additional challenge was to make my solution work with HighLine,
Facets and Term::Ansicolor, and that is what I did :).

The solution can be found here too: http://pastie.org/333319

And to test all libraries simply type

 > for i in term/ansicolor facets/ansicode highline; do ruby1.9
rd-185-sol.rb -f $i; done

 > ruby1.9 rd-185-sol.rb

runs, transparently, with a random library of all registered

HYLI

Robert


P.S.
I do not recall ever have answered 3 RQ in a row before :-P

------art_46858_25543943.1228679360192
Content-Type: application/x-ruby; name=rd-185-sol.rb
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fog3ukix0
Content-Disposition: attachment; filename=rd-185-sol.rb

IyEvdXNyL2Jpbi9ydWJ5CiMKIyAgQXMgd2UgaGF2ZSBtb3JlIHRoYW4gb25lIGxpYnJhcnkgdG8g
aGVscCB1cyB3aXRoIHRoaXMsIGFuZAojICBhcyB3ZSBhcHByZWNpYXRlIEZhY2V0cyBhbmQgSGln
aGxpbmUgbGV0IHVzIHRyeSB0byBjb21lIHVwCiMgIHdpdGggYSBsaWJyYXJ5IGRpc3BhdGNoZXIg
d2hpY2ggd2lsbCBhbGxvdyB0aGUgY29kZSB0byBydW4KIyAgb24gZWFjaCBwbGF0Zm9ybSB0aGF0
IGhhcyBhdCBsZWFzdCBvbmUgb2YgdGhlIHJlcXVpcmVkIGxpYgojICBhdmFpbGFibGUuIFRoYXQg
aXMsIHVubGVzcyB0aGUgdXNlciBoYXMgZm9yY2VkIHVzIHRvIHVzZSBhCiMgIHNwZWNpZmljIGxp
YiB3aXRoIHRoZSAtZnwtLWZvcmNlIG9wdGlvbi4KCmJlZ2luCiAgcmVxdWlyZSAncnVieWdlbXMn
CnJlc2N1ZSBMb2FkRXJyb3IKICAiV2UgZ290dGEgaGF2ZSB0byBkbyB3aX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