[Haskell-cafe] Code Review Request - Unbalanced Parenthesis correction
Andreas Abel
abela at chalmers.se
Fri Mar 24 10:30:15 UTC 2017
> balance _ = ""
Haha!
The other trivial solution simply replaces each parenthesis by "()":
balance = concatMap $ const "()"
balance "))(" then returns "()()()".
This achieves that the balanced string is a superstring of the original
string. (Not a minimal one.)
On 21.03.2017 18:23, Michael Orlitzky wrote:
> On 03/21/2017 01:16 PM, David McBride wrote:
>> Whether your algorithm is correct depends on how you are supposed to
>> rebalance them. My naive attempt gives very different results.
>>
>
> You guys are trying to hard. Here's an algorithm that meets the stated
> requirements:
>
> balance _ = ""
--
Andreas Abel <>< Du bist der geliebte Mensch.
Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden
andreas.abel at gu.se
http://www.cse.chalmers.se/~abela/
More information about the Haskell-Cafe
mailing list