16
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:
b┬K
l
And this:
A┬d
O┴p┬Z
q
And this:
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 (except in comments).
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.
Challenge
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.
Examples
1.
b┬K
i
FALSE (there's only one bachelor)
2.
A┬d
i┬O┴p┬Z
z F
FALSE (z and F are cousins)
3.
e┬N
L┬m┴p─┬F
B┴y┬A W┬y
E T
FALSE (B, E and T are all male)
4.
e┬N
L┬m┴p─┬F
q┴A┬y w┬R
U E
TRUE (q and E can marry)
5.
i┬────────N
m┬E
│ w
│
│
W
TRUE (w is not related to anybody)
6.
d┬F
a┬────────N┴─e┬E
│ │
│ w
│
│
V
FALSE (V and w are cousins)
7.
Ww
TRUE (W and w are unrelated)
8.
fw
FALSE (f and w are of the same gender)
9.
e┬N
L┬m┴p─┬F
n┬B┴y┬A w┬Y
C E i
TRUE (i and E, and also i and C)
10.
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 =.
Example:
d+F
a+--------N=-e+E
| |
| w
|
|
V
3
this person smells bad
those look like a bunch of unrelated persons. Maybe make the comments Cyrillic, now that the persons are latin? x) – Grimmy – 2019-11-18T13:27:30.5272I'd recommend to remove comments entirely to simplify the challenge some more. – Arnauld – 2019-11-18T13:37:37.383
Text between parentheses is considered a comment. But alright, I'll get rid of them then. – KeizerHarm – 2019-11-18T13:38:27.583
3if cyrillic is "annoying", aren't graphics drawing characters so too? – ngn – 2019-11-18T14:03:09.757
@ngn I'm guessing there's more codepages that include the box-drawing characters but not Cyrillic, because they were used in terminals and early interfaces? I agree with you though: I was pretty much assuming that I could get away with Cyrillic because I already had those characters. – KeizerHarm – 2019-11-18T14:12:46.370
3You only seem to have 4 control characters,
┬
,┴
,─
and│
. You could make this entirely ASCII by either converting the two T's to+
, (or simply allow any two non-alphabetical chars to be used determined by the submitters if you want to keep them as two separate symbols),|
, and-
. – Veskah – 2019-11-18T14:21:19.713Oh, guess you'll need two separate characters to handle
┴
above a┬
. – Veskah – 2019-11-18T14:28:01.7033@Veskah Okay. I think the latter is a solution that works best while keeping the original challenge intact. + for ┬ and = for ┴ should work. – KeizerHarm – 2019-11-18T14:29:04.850
How could the syntax show a family with three or more children that are each married? – Aganju – 2019-11-21T00:14:39.687
@Aganju No family ever has more than two children. – KeizerHarm – 2019-11-21T08:07:29.470