Forum: Ruby Re: Bracket Packing (#78) (2 solutions)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eric I. (Guest)
on 2006-05-08 02:53
(Received via mailing list)
James Edward G. II writes:
> >
> > ["()", "{}", "[]"].each { |symbol_pair| exit(1) if 0 != ARGV
> > [0].count(symbol_pair) % 2 }
> > puts ARGV[0]
>
> Just thinking out loud here, but how does this fair with inputs like:
>
> ")B(" or "B()"
>
> ?

You're correct, the code I provided could not deal with those
situations.  However, those should never be presented as inputs
according to post 191513, which I'll quote:

Ross B. writes:
> >
> > Ie, [{(B),(B)}] -> [(B),(B)]
> >
>
> Good point. Let's assume just one bracket will be missing, if any.
> Obviously, to fix it, it needs to go back in the right place.

Eric
This topic is locked and can not be replied to.