Determining Yes or No?
Octave, 29 27 bytes
Thanks to @RickHithcock for pointing out a mistake, now corrected. Also, 2 bytes off thanks to @StewieGriffin!
@(s)'yn'(mod(sum(s+1),2)+1)
Try it online!
Explanation
The ASCII code point of 'y'
is odd, and that of 'n'
is even. The code
- adds
1
to each char in the input string to make'y'
even and'n'
odd; - computes the sum;
- reduces the result to
1
if even,2
if odd; - indexes (1-based) into the string
'yn'
.
JavaScript (ES6), 28 bytes
Takes input as a string.
s=>'ny'[s.split`n`.length&1]
Try it online!
JavaScript (ES6), 30 bytes
Takes input as an array of characters.
y=>'yn'[n=1,~~eval(y.join`^`)]
Try it online!
Charcoal, 6 bytes
§yn№Sn
Try it online! Link is to verbose version of code. Explanation:
S Input string
№ n Count number of `n`s
§yn Circularly index into string `yn`
Implicitly print appropriate character