26
2
The quaint hamlet of Кодгольф in the Russian far east has a problem: their population is low (below 66), and no new people have arrived for years. Moreover, after centuries of near-isolation, just about everybody is related to each other.
Mayor Стекобмен 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 Боб computer to consult the genealogy charts. They had just been updated to the brand-new ASCII format, and look like this:
ы┬К
ю
And this:
А┬д
О┴п┬Щ
Ф
And this:
з┬Й
Л┬м┴п─┬Ф
Ы┴я┬А ш┬Я
З Е
And even this:
ю┬────────Й
м┬Е
│ ш
│
│
Щ
Here's how it works. Each person is a letter from the Russian alphabet. Males are capital letters (any of АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ), females are lowercase letters (any of абвгдеёжзийклмнопрстуфхцчшщъыьэюя).
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 Cyrillic 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.
Challenge
Make the shortest possible program 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. Ignore any character not given an explicit function in the above description.
It's fine to use an encoding other than Unicode for input/output purposes, e.g. KOI8-R as long as it's known and standardised by someone other than yourself. Scoring is done per this answer. If your language handles Cyrillic natively, it's an advantage!
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.
ы┬К
ю
FALSE (there's only one bachelor)
2.
А┬д
ю┬О┴п┬Щ
Щ ф
FALSE (Щ and ф are cousins)
3.
з┬Й
Л┬м┴п─┬Ф
Ы┴я┬А ш┬Я
З Е
FALSE (З, Е and Ы are all male)
4.
з┬Й
Л┬м┴п─┬Ф
ё┴А┬я ш┬Я
З Е
TRUE (ё and Е can marry)
5.
ю┬────────Й
м┬Е
│ ш
│
│
Щ
TRUE (ш is not related to anybody)
6.
д┬Ф
ю┬────────Й┴─ё┬З
│ │
│ ш <this person smells bad
│
│
Щ <this person betrayed the Party!
FALSE (Щ and ш are cousins)
7.
Щ 1234567890 quick brown foxes jumped over the lazy dog ш
TRUE (Щ and ш are unrelated)
8.
з┬Й
Л┬м┴п─┬Ф
й┬Ы┴я┬А ш┬Я
Э З ю
TRUE (ю and З, and also ю and Э)
9.
А┬д ф┬Ж
м┴п┬Щ ю┬Я
Ф ц
TRUE (ц and Ф)
NOTE: Here is an ASCII version of roughly the same challenge.
2Hi KeizerHarm, welcome to the site! Thanks for the question, it looks fun. A question: For example 4, aren't ё and З barred from marriage due to the fact that ё is З's aunt? In other words, ё's parent Л is З's grandparent? Also, I take it that we are to assume that marriages are always heterosexual, and that divorce and remarrying of widows/widowers does not exist? Making those assumptions is fine by me, I just wanted to be sure. – isaacg – 2019-11-15T17:38:40.563
1@isaacg Thanks. You're right about question 4; I missed that. I'll fix that right away, and then draw up another example with two possible marriages.
And yes to all of those. I'll add that too. – KeizerHarm – 2019-11-15T17:39:55.417
1Also for 6, shouldn't Щ and ш be allowed to marry because they are first cousin's once removed, not first cousins? Щ's great grandparents are д and Ф, who are ш's grandparents. – isaacg – 2019-11-15T17:40:47.433
1...I should really triple-check these things ^^; Thank you, I'll fix it right away. – KeizerHarm – 2019-11-15T17:41:59.500
Can we assume that no characters in the Unicode range from U+0400 to U+04FF will appear in the input other than those you've specified? Or do we need to handle characters like ө for example? – Nick Kennedy – 2019-11-15T19:07:31.927
1@NickKennedy Only expect Cyrillic, the box-drawing characters specified, and printable ASCII characters. – KeizerHarm – 2019-11-15T19:13:54.407
1@KeizerHarm what about Cyrillic characters not in your list of men and women? – Nick Kennedy – 2019-11-15T19:14:31.757
1@NickKennedy No need to take those into account. – KeizerHarm – 2019-11-15T19:16:49.120
10I've read through this a couple of times but maybe I'm still missing something: I don't see what requiring the use of the Russian alphabet adds to this challenge. – Shaggy – 2019-11-15T23:41:06.333
3@Shaggy Well, for one: were it in the Latin alphabet, to detect a person you could simply check a character against the range [a-zA-Z]. The Russian alphabet however is not on one continuous range, so either Ё&ё need to be treated separately or the entire string of allowed characters needs to be in there, and I wonder if you could even compress that. Plus this makes for a funnier story. – KeizerHarm – 2019-11-16T00:19:43.747
8Welcome to CGCC! I like your idea, but I'll agree with Shaggy: the really interesting core of this challenge has to do with first decoding the input into a graph of familial relationships, and then making some deductions based on that graph. The Cyrillic requirement is just an annoying distraction from those tasks, especially in languages where unicode is a bit of a pain. Maybe as a separate challenge "Is this Cyrillic unicode letter a capital letter?" would be interesting to golf for some; but as it is, it really detracts from my interest in answering your question. Just sayin'! – Chas Brown – 2019-11-16T04:19:35.707
@ChasBrown Thanks for the feedback! I understand the issue; it's not something I really considered when I thought this up. I will definitely keep that sorta thing in mind if I come up with another puzzle. I'm not sure it would be proper form to just rewrite this question when there's been a whole discussion about character encoding (in now-deleted comments) and there's a chance someone already got started on a program with Cyrillic specifically in mind. – KeizerHarm – 2019-11-16T10:04:01.193
I always thought a female bachelor was called a spinster. But I guess these days women want to use male terms for everything... – Neil – 2019-11-16T13:16:24.540
@Neil Not sure what the gender-neutral term was... sorry, not an Anglophone ^^; – KeizerHarm – 2019-11-16T17:22:55.357
@Others I think if this question gets no answers after a couple of days, I'll leave it be but re-ask it without Cyrillics. I just don't want to piss off anyone of the 16 upvotes who might be working on it already. – KeizerHarm – 2019-11-16T17:22:57.560
Might the same letter occur multiple times if necessary to draw the graph? – Peter Taylor – 2019-11-18T08:54:05.563
@PeterTaylor It's your job to interpret the graph, not to draw it. The test cases do not ever repeat a letter. – KeizerHarm – 2019-11-18T09:01:34.813
The test cases might not, but I don't see any statement either way as to whether valid input might. – Peter Taylor – 2019-11-18T09:03:01.947
@PeterTaylor Alright; I'll clarify that. – KeizerHarm – 2019-11-18T09:09:18.823
I made a non-Cyrillic version: https://codegolf.stackexchange.com/questions/196035/can-this-scottish-village-have-a-wedding
– KeizerHarm – 2019-11-18T13:20:50.107