From: Stuart Holden
Date: 2006-05-09T21:01:53+09:00
Subject: Re: [QUIZ] Bracket Packing (#78)
------_=_NextPart_001_01C67360.3C89C50B
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable
Hi,
I've refined my solution a little bit. It's now a bit smarter at
positioning missing opening brackets. The old version would misbehave
given...
[([B])}] -> [([B]){}]
The new version produces...
[([B])}] -> [{([B])}]
After spotting that we had a missing opening bracket, I was trying to
scan backwards to find the last unclosed occurrence of the next expected
bracket. This was getting a bit messy, then I spotted the technique used
by Ross to add the opening position to the stack along with the bracket
type - being a Ruby newbie I didn't think of pushing a tuple onto the
stack. Slotted that technique in there, and it seems to work a charm.
Some test results below...
=09
[B] -> [B] (valid=3Dtrue)
[[B] -> [[B]] (valid=3Dfalse)
[B]] -> [[B]] (valid=3Dfalse)
[(B)] -> [(B)] (valid=3Dtrue)
[(B] -> [(B)] (valid=3Dfalse)
[B)] -> [(B)] (valid=3Dfalse)
[([B])}] -> [{([B])}] (valid=3Dfalse)
[{([B])] -> [{([B])}] (valid=3Dfalse)
[(B)(B)(B)}] -> [{(B)(B)(B)}] (valid=3Dfalse)
[(B){(B)(B)({B})] -> [(B){(B)(B)({B})}] (valid=3Dfalse)
[(B)(B)(B)({B}})] -> [(B)(B)(B)({{B}})] (valid=3Dfalse)
[(B)(B)(B)}({B})] -> [{(B)(B)(B)}({B})] (valid=3Dfalse)
Regards,
Stu
-----Original Message-----
From: Stuart Holden=20
Sent: 09 May 2006 00:22
To: ruby-talk ML
Subject: Re: [QUIZ] Bracket Packing (#78)
Here is my attempt. Go easy... my first quiz entry, and my first Ruby
script.
Regards,
Stu
This Email may c=
ontain confidential and privileged information and is intended for the use =
of the addressee(s) only. If you are not the intended recipient please no=
tify the sender and delete the Email from your system. It should not be tra=
nsmitted to any other person without the consent of the sender. Additional =
important notifications regarding Email transmissions from and to members o=
f Baring Asset Management can be accessed at http://www.barings.com/email/index.hcst