Quick question about the phrase 'occasionally missing off a bracket'. Is
it possible to have lost more than one braket missing from the string,
or will it be a case of 0..1 brackets missing? I assume just one. If it
is possible to have more than one bracket missing, you could never trust
what the program was saying, even when the string was valid.
Ie, [{(B),(B)}] -> [(B),(B)]
- Stu
···
-----Original Message-----
From: Ruby Quiz [mailto:james@grayproductions.net]
Sent: 05 May 2006 12:47
To: ruby-talk ML
Subject: [QUIZ] Bracket Packing (#78)
The three rules of Ruby Quiz:
1. Please do not post any solutions or spoiler discussion for this quiz
until
48 hours have passed from the time on this message.
2. Support Ruby Quiz by submitting ideas as often as you can:
3. Enjoy!
Suggestion: A [QUIZ] in the subject of emails about the problem helps
everyone
on Ruby Talk follow the discussion. Please reply to the original quiz
message,
if you can.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-=-=-=-=
by Ross Bamford
The BigCo Bracket Company, one of the world's largest suppliers of
brackets,
hinges and fittings, has lately been experiencing problems in it's
manufacturing
division, with a large number or brackets lost or broken in transit
owing to
faulty packaging at the end of the line.
Investigations into the cause of the problem have led engineers to an
ancient
COBOL program controlling the packaging machinery. This program is
responsible
for selecting the type of packaging a given bracket should be shipped
in, based
on input from an array of sensors on the production line. It then sends
a
description of the package to the packager itself, which packs the
bracket and
sends it on to shipping. The description is a simple text string, made
up of
brackets with the following format:
(B) - Bracket in a soft wrapping
[B] - Bracket in a cardboard box
{B} - Bracket in a wooden box
Often, brackets have multiple layers of packaging for protection, for
example:
{(B)} - Soft-wrapped bracket in a wooden box
[{B}] - Wooden-boxed bracket with cardboard outer
[{(B)}{(B)(B)}] - Wooden boxed single and double bracket packs
with soft
inner wrap, in cardboard outer.
Now, the problem is that this venerable program has for some reason
begun to
output malformed packaging descriptions, occasionally missing off a
bracket, for
example:
[{(B}{(B)(B)}]
or:
{(B)}{(B)(B)}]
After a fruitless search for someone with the skills to fix this
problem, the
engineers changed tack and called you in to fix the problem from the
outside.
What needs to be done?
======================
Basically, the plan is to insert another computer between the controller
and the
packer, upon which will run your program. The engineers can handle the
integration with their systems - they just need you to write a slick bit
of Ruby
code to validate the packaging descriptions as they're passed in. You've
been
given two choices:
* Check the description, and return exitcode indicating it's
okay (0)
or bad (1). If correct, you should also print the description
to stdout.
If it's bad, the system can then force the controller to try
again.
* Fix the description, if possible, and print it to stdout. The
system
will then pass the fixed code to the packer.
<body>
<blockquote>
<font FACE="Arial,Arial" SIZE="1"><p ALIGN="JUSTIFY">This Email may contain confidential and privileged information and is intended for the use of the addressee(s) only. If you are not the intended recipient please notify the sender and delete the Email from your system. It should not be transmitted to any other person without the consent of the sender. Additional important notifications regarding Email transmissions from and to members of Baring Asset Management can be accessed at <a href="http://www.barings.com/email/index.hcst">http://www.barings.com/email/index.hcst</a></font></p></body>
</p>
</font>
</blockquote>
<p> </p>
</body>
</html>