This is the exact same question I asked earlier, but without the annoying Cyrillic factor which many found superfluous. I hope this is a better puzzle!
The quaint hamlet of North Codetown in the Scottish far north has a problem: their population is low (below 52), and no new people have arrived for years. Moreover, after centuries of near-isolation in their secluded valley without much economic opportunity, just about everybody is related to each other.
Mayor Montgomery has a solution that should keep the morale high: organise a wedding. However, the question is, are there two bachelors in the town that aren't at least cousins of each other?
The mayor fired up his state-of-the-art Microsoft Bob computer to consult the genealogy charts. They had just been updated to the brand-new ASCII format, and look like this:
A┬d O┴p┬Z q
e┬N L┬m┴p─┬F B┴y┬A z┬Y f E
And even this:
i┬────────N m┬E │ Z │ │ z
Here's how it works. Each person is a letter from the Latin alphabet. Males are capital letters (any of ABCDEFGHIJKLMNOPQRSTUVWXYZ), females are lowercase letters (any of abcdefghijklmnopqrstuvwxyz).
A '┬' between two people means they are married. Right below that is either another person - their child - or a '┴', meaning that this couple has two children; located to the left and right of the symbol.
Moreover, to the right and left of '┬' and '┴' there can be any number of '─' characters, to extend the lines, as it were. Similarly, there can be any number of '│' characters above a '┴' or below a '┬'.
Lastly, a character without any defined symbol above them is considered a new arrival to the village, and by definition unrelated to anybody.
Also be aware that this is a very conservative village. Nobody marries more than once, and every marriage is heterosexual. Furthermore, assume everybody in the graph is alive, and no two people share the same name: e.g., the same character never occurs more than once.
The two bachelors should be of the opposite gender, and they should not be first cousins or any more closely related. First cousins once removed is okay. In other words: they should not share a parent, or a grandparent, or have one's grandparent be another's parent.
Make the shortest possible program (by byte count) with as input either a string (containing newline characters), or a string array, or a rectangular two-dimensional string or char array (no higher or wider than 100 characters), containing the family tree of the town. Assume the input is a valid family tree, consisting of nothing but ASCII printable characters and the mentioned line/forking characters. Ignore any character not given an explicit function in the above description.
Return a boolean value of true or false (or a bit/int of 1 or 0, or any consistent truthy/falsey value used by the language of your choice) to indicate whether there can be a wedding given the family tree.
FALSE (there's only one bachelor)
A┬d i┬O┴p┬Z z F
FALSE (z and F are cousins)
e┬N L┬m┴p─┬F B┴y┬A W┬y E T
FALSE (B, E and T are all male)
e┬N L┬m┴p─┬F q┴A┬y w┬R U E
TRUE (q and E can marry)
i┬────────N m┬E │ w │ │ W
TRUE (w is not related to anybody)
d┬F a┬────────N┴─e┬E │ │ │ w │ │ V
FALSE (V and w are cousins)
TRUE (W and w are unrelated)
FALSE (f and w are of the same gender)
e┬N L┬m┴p─┬F n┬B┴y┬A w┬Y C E i
TRUE (i and E, and also i and C)
A┬d f┬H m┴P┬z i┬Y F u
TRUE (F and u)
NOTE: You are free to substitute the control characters with ASCII characters if it makes your program simpler. In that case switch out │ with | (vertical bar), ─ with - (hyphen), ┬ with + and ┴ with =.
d+F a+--------N=-e+E | | | w | | V