Prelude is an esoteric programming language, which has very few, but unusual, restrictions on what constitutes a valid program. Any block of printable ASCII text ("block" meaning that lines of printable ASCII are separated by newlines - 0x0A) is valid provided that:
- Every (vertical) column of text contains at most one of
(and). - Ignoring their vertical position, the
(and)are balanced, that is, each(is paired with exactly one)to the right of it, and vice versa.
Write a program or function which, given a string containing printable ASCII and newlines, determines if it constitutes a valid Prelude program. You may take input via STDIN (or closest alternative), command-line argument or function argument. The result may be returned or printed to STDOUT, using any two fixed truthy/falsy values of your choice.
You must not assume that the input is rectangular.
This is code golf, so the shortest submission (in bytes) wins.
Examples
The following are valid Prelude programs (in fact, they're even real Prelude programs):
?1-(v #1)-
1 0v ^(# 0)(1+0)#)!
(#) ^#1-(0 #
1(# 1) v # - 1+)
vv (##^v^+
? v-(0 # ^ #)
?
1+ 1-!
And here are a number of inputs, all of which are invalid:
#(#(##)##)##(
)##(##(##)#)#
#(#)
)###
#(##
(##)
(##)
(#)#
(##)
(###
#(#)
(##)
#(#)
###)
#()#
()##
#(#)##
###
###(#)
)and 2(. Shouldn't it be only 1 per line? \$\endgroup\$