19
2
After inputting a string [length 1-20], only containing the chars y for yes and n for no,
your program should output the result (y or n). Example input: yynynynny
would output y.
The result is determined by combining the y's and n's in the following way:
yes and no equals no
yes and yes equals yes
no and no equals yes
If the string contains more than 2 characters (likely...), the calculation would look the same. Examples:
yes and yes and no equals no (because the no merges with the first yes to no. then there are no and yes left and the same thing happens again)
no and no and no equals no (the first two no's merge to yes, then there are yes and no left, which emerge to no)
Example input with output:
yynynynynyyn
= n
Tip: have in mind that the order of the chars your program works off doesn't care. (for example you can read the input from back, or from behind, mix the letters, sort it, whatever. What counts is the correct ouptput) have fun!
Winning criteria: this is code-golf, so shortest code in byte wins.
3Congratulations on the first challenge with clear specification! (although it's unfortunate that some community members don't like "too trivial" challenges....) – user202729 – 2018-05-22T15:30:25.730
3Very similar. – user202729 – 2018-05-22T15:40:20.053
The boolean relationship defined is XNOR, sometimes called EQV in older BASICs. It is the inverse of XOR, and can be achieved as NOT(XOR...) if using boolean values directly; the additional complexity in this challenge is strictly from the requirement to deal with strings of 'yn' in both input and output. – Jeff Zeitlin – 2018-05-22T17:06:37.997
7Can we output an alternative pair? Say
1
fory
, and0
forn
. – Oliver – 2018-05-22T17:27:36.4875Can we take input as a list of characters ie
["y", "n", "n"]
– Okx – 2018-05-22T17:34:24.3901Can we take input as an alternative pair? Say
1
fory
, and0
forn
. – Adám – 2018-05-23T05:19:55.2472@Adám Then this would be an exact duplicate of the linked challenge, I guess not :P – Mr. Xcoder – 2018-05-23T06:56:16.827
1@Mr.Xcoder No, XNOR vs XOR. But why the unnecessary complication of I/O formats here, when the much related challenge doesn't need it? – Adám – 2018-05-23T08:12:19.563
2XNOR is just NOT XOR so this would be too closely related to be kept open. – Mr. Xcoder – 2018-05-23T08:23:01.177
@Mr.Xcoder It's only a duplicate if it's "
1
forn
,0
fory
"... – user202729 – 2018-05-23T12:03:17.9231@Mr.Xcoder If the only thing keeping this question from being a duplicate is different characters for input format, how is it not already a dupe? – jpmc26 – 2018-05-23T18:56:21.987
Why not close the old one as a dupe of the new one? The old one was poorly received, and I think this one is more interesting – Conor O'Brien – 2018-05-23T22:43:34.823
@ConorO'Brien What's wrong with doing this? HNQ questions rarely "have the correct votes". – user202729 – 2018-05-24T02:47:21.840
@ConorO'Brien Some discussion in chat.
– user202729 – 2018-05-24T02:51:09.5702The output format makes this more interesting than the problem it's marked a duplicate of. That one is just sum of elements, reduce modulo 2. Many of those answers would not be optimal here. – Angs – 2018-05-24T06:36:09.683
1Your first example doesn't make sense to me. How does the no merge with the first yes? Isn't evaluation left-to-right? Do you mean the two yeses merge, then the resulting yes merges with the no to make no? – David Conrad – 2018-05-24T12:42:18.787
1Could we have a few more examples? – L3viathan – 2018-05-24T17:23:57.827
2Why close this as a duplicate of a heavily downvoted challenge? I voted to leave this open in the review queue. – Stewie Griffin – 2018-06-01T13:17:09.910
@davidconrad you're right, but as I said, the order doesn't matter – Squareoot – 2018-06-01T18:31:34.033
3
Since the duplicate of this challenge was heavily downvoted, I don't think it's very helpful to close this as a duplicate. If anything, the older challenge should be a duplicate of this one since it's policy to leave the better challenge open I've reopened this challenge
– James – 2018-06-01T19:51:25.100Can we output truthy or falsy values? – MilkyWay90 – 2018-11-09T16:38:37.880