g | x | w | all
Bytes Lang Time Link
030Janet250905T141340ZAdam
006Nibbles250905T135527ZAdam
024AWK250905T132529Zxrs
008Thunno 2230714T085015ZThe Thon
00705AB1E210316T164245ZMakonede
009J180522T164312ZFrownyFr
008Japt180522T171933ZOliver
052Common Lisp180601T120647ZASCII-on
056Prolog SWI180530T031537ZASCII-on
050F#180522T212241ZCiaran_M
026Python 2180525T150944Zlynn
071JavaScript ES6180525T145828Zuser3604
042C GCC180525T143314ZJasmes
032Kotlin180525T125101ZKromzem
040Clojure180524T225203ZGabe Lau
008MATL180524T082124ZStewie G
091Go180523T205056Zlukass
043PowerShell Core180522T224533Zbriantis
050C gcc180523T040600ZErikF
037JavaScript180523T105846Zkanine
035Java 8180523T032210ZJakob
027Octave180522T161321ZLuis Men
070PHP180522T160933ZFrancisc
023Clean180523T122547Zuser8059
015APL Dyalog Unicode180522T165316ZJeff Zei
013Befunge98180523T062853ZJo King
011CJam180522T155853Zmaxb
006Charcoal180522T164542ZNeil
007Jelly180522T154509Zuser2027
050Scala180523T003051ZJared K
020Cubix180522T222419ZMickyT
024Chip z180522T221418ZPhlarx
024///180522T214029Zboboquac
014GolfScript180522T213530Zwastl
024Ruby180522T212957Zbenj2240
018Perl 5180522T212040Zwastl
007Stax180522T200319Zwastl
059Mathematica180522T210448ZMannyC
008Husk180522T195834Zuser4854
039dc180522T184043ZDigital
143Java OpenJDK 8180522T183958ZX1M4L
009Japt180522T174744ZShaggy
044R180522T162058ZJayCe
044JavaScript180522T161108ZAlgirdas
00805AB1E180522T171524ZMr. Xcod
029Python 2180522T165904ZMr. Xcod
028JavaScript ES6180522T162052ZArnauld
009Pyth180522T162333Zuser4854
028Haskell180522T155124ZAngs
nan180522T160817ZBrad Gil
007Jelly180522T154437ZJonathan
011Retina180522T155608Zuser4854

Janet, 30 bytes

|(["y""n"](%(count even? $)2))

Nibbles, 6.5 6 bytes

=`/+~@+"ny"

Attempt This Online!

=`/+~@+"ny"
   +~@      Add 1 to each character,
 `/   +     sum their codepoints
=      "ny" and cyclically index into "ny".

AWK, 24 bytes

$0=gsub(/n/,X)%2?"n":"y"

Attempt This Online!

Thunno 2, 8 bytes

'nc`ynsi

Try it online!

Same as all the other answers

'nc`ynsi  # Implicit input
'nc       # Count of "n"s
      si  # modularly indexed
   `yn    # into the string "yn"
          # Implicit output

05AB1E, 7 bytes

'n¢„ynè

Try it online!

'n¢„ynè  # full program
      è  # character in...
         # (implicit) commutative indèx...
   „yn   # literal...
      è  # at 0-based index...
         # (implicit) commutative, modular indèx...
  ¢      # number of...
'n       # literal...
  ¢      # s in...
         # implicit input
         # implicit output

J, 10 9 bytes

{&'ny'@=/

Try it online!

Japt, 8 bytes

"yn"gUèn

Try it online!

Explanation:

"yn"gUèn
"yn"       String literal - "yn"
    g      Return the char at index:   
      è      Number of matches where:
       n       "n" is found in
     U         Input

Japt uses index-wrapping, so if Uèn returns 2, it will return y when getting the char from "yn".

Common Lisp, 52 bytes

(lambda(s)(reduce(lambda(a b)(if(eq a b)#\y #\n))s))

Try it online!

Prolog (SWI), 56 bytes

[H,H]-121.
[_,_]-110.
[A]-A.
[A,B|T]-S:-[A,B]-C,[C|T]-S.

Try it online!

F#, 54 50 bytes

-4 bytes thanks to Laikoni.

let c=Seq.reduce(fun a x->if a=x then 'y'else 'n')

Try it online!

Seq.reduce applies a function with an accumulator (a) to each element (x) in the string. For the first call, a is the first element in the string and x is the second element.

Python 2, 26 bytes

lambda s:'yn'[int(s,35)%2]

Try it online!

JavaScript (ES6), 71 bytes

f=a=>(a.split("").map(b=>(b=="y")?1:-1).reduce((b,c)=>b*c)==1)?"y":"n";

C (GCC) 42 bytes

g(char*a){return*a?"yn"[(g(a+1)^*a)&1]:1;}

Try in online!

Solution is simply based on XNOR operation.

Kotlin, 32 Bytes

"yn"[s.filter{it=='n'}.length%2]

Try it online!

Clojure, 40 bytes

(if(even?(count(filter #(= %\n)s)))\y\n)

Try it online!

MATL, 8 bytes

Qs'ny'w)

Try it online!

Saved 2 bytes thanks to Luis Mendo! I previously used the explicit modulus command to get the index into the range 1,2.

Explanation

This uses the fact that MATL have modular indexing, which means that the 1st, 3rd, 5th ... element of the string ny are the same (n). So are the 2nd, 4th, 6th ... element of the string (y).

Q          % Grab input implicitly, and increment each ASCII-value by 1
           % This makes 'n' odd, and 'y' even
 s         % Take the sum of all elements
  'ny'     % Push the string `ny`
      w    % Swap the stack to facilitate the indexing
       )   % Take the n'th element of 'yn' and output it.

Go, 91 bytes

package main;import ."strings";type s=string;func f(S s)(s){return s("yn"[Count(S,"n")%2])}

105 bytes if ;func main(){} is added; unsure of Gode Golf golang norms.

PowerShell Core, 48 43 bytes

"$args"|% t*y|%{$z=$z-xor$_-eq'n'};'yn'[$z]

Try it online!

Not the best method. Split into char array, use -xor, invert it implicitly at the end with the array lookup to get back a char.

C (gcc), 52 50 bytes

Thanks to @Neil for the suggestions.

I borrowed the solution of counting ns, but instead of keeping a count, I just flip between the initial state and its inverse on an n.

i;f(char*a){for(i=*a;*++a;i^=*a&1?0:23);return i;}

Try it online!

JavaScript, 3937 Bytes

s=>[...s].reduce((x,y)=>x==y?'y':'n')

Simple reduce function after splitting the input string.

Java 8, 35 bytes

A decider for a regular language! I can do that.

s->s.matches("y*(ny*ny*)*")?'y':'n'

Try It Online

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

  1. adds 1 to each char in the input string to make 'y' even and 'n' odd;
  2. computes the sum;
  3. reduces the result to 1 if even, 2 if odd;
  4. indexes (1-based) into the string 'yn'.

PHP, 77 70 Bytes

Try it online

Code, recursive function

function f($p){echo($p[1])?f(strtr($p,[yy=>y,yn=>n,ny=>n,nn=>y])):$p;}

Explanation

Why use strtr with a replace array like [yy=>y,yn=>n,ny=>n,nn=>y], as the string the function takes can be shown like (example with test case "yynynynynyyn")

  (y and y) and (n and y) and (n and y) and (n and y) and (n and y) and (y and n)

What does the function do?

  function f($p){
      echo($p[1])
           //The function will replace yy yn ny nn while strlen>1
           ?f(strtr($p,[yy=>y,yn=>n,ny=>n,nn=>y]))
           //Length greater than one, apply strtr
           :$p;
           //ok, just one letter left, "echo" it
     }    

With a loop, 83 Bytes

Try it online

Simulates "run as pipe"

Code

<?php $p=$argv; while(strlen($p)>1){$p=strtr($p,[yy=>y,yn=>n,ny=>n,nn=>y]);}echo$p;

Explanation

It does the exact same thing as the recursive function

$p=$argv; //Accepting value from the script variable
while(strlen($p)>1){ //the loop ends when string length is one
   $p=strtr($p,[yy=>y,yn=>n,ny=>n,nn=>y]); //replace
}
echo$p; //echo the result.

Clean, 26 23 bytes

foldr1\a b|a==b='y'='n'

Try it online!

APL (Dyalog Unicode), 15 bytes

'ny'[1+=/'y'=⍞]

Try it online!

Note: TIO defaults to ⎕IO = 1. If run with ⎕IO←0,

APL (Dyalog Unicode), 13 bytes

'ny'[=/'y'=⍞]

Try it online!

This is the XNOR function (sometimes called EQV, especially in old BASICs.

Decomposition/Analysis:

             ⍞  - Accept string input  
         'y'=   - Compare it to the letter `y`. This "converts" the input 
                  string into a vector of 1s and 0s where the 1s correspond 
                  to 'y' and the 0s to 'n'.  
       =/       - XNOR/EQV/equality reduction - converts the vector into a 
                  single boolean value by evaluating e.g., 1 xnor 0 xnor 0 
                  xnor 1 ...  
     1+         - adds one for subscripting in ⎕IO = 1 environment. In 
                  ⎕IO = 0, should be omitted (save 2 bytes)  
    [         ] - subscript indicator - the expression, which should be 
                  either a 1 or 2 (0 or 1 in `⎕IO = 0`), is now going to be 
                  interpreted as a subscript of...  
'ny'            - The string of possible results - a 0/1 is 'n', a 1/2 is 'y'

Befunge-98, 13 bytes

~k!aj@,+n'*b!

Try it online!

Basically inverts a 0 for every n in the input, and once more for good measure, then outputs y for 1 and n for 0

~     Get inputted character
 k!   Invert the current value 110 (n) or 121 (y) + 1 times
   aj Jump past the rest of the code
~     Get input again. If no more input, reverse direction
            ! Invert the value once again
       +n'*b  Convert 0/1 to n/y
     @,       Output letter

CJam, 20 11 bytes

q~'ne="yn"=

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

Jelly, 7 bytes

ċ”nị⁾ny

Try it online!

ċount number of ”n, ndex into the string ⁾ny. (with modulo 2)


ċḢịɗ⁾ny

Try it online!

{ċount number of, take the ead, then ndex into} string ⁾ny.


OCSị⁾ny

Try it online!

Similar to the Octave answer above. Calculate Ord value, take the Complement (for each ord value x calculate 1-x), Sum, then ndex into string ⁾ny.

Scala, 50 Bytes

def?(b:String)=b.reduce((r,l)=>if(r==l)'y'else'n')

Cubix, 24 20 bytes

Been a while since I played with Cubix, so ...

i;iwW-?;o@..!'yv.n'|

Try it online!

Fairly naive implementation that steps through the string and compares the character against current result.

Interactive Demo

This unwraps onto the cube as follows

    i ;
    i w
W - ? ; o @ . .
! ' y v . n ' |
    . .
    . .

Chip -z, 24 bytes

B}Zvv~vedSD~t
 `'bc af*g

Try it online!

Explanation

This prints 'h', which is 'n' & 'y':

        d    
       f*g

This converts the 'h' to either an 'n' or a 'y', according to whether the top-left wire is powered:

   vv~ve     
   bc a   

This is the xor counter, it powers the part described above as necessary:

B}Z          
 `'       

Finally, this causes the program to only print the last output and terminate when the input is exhausted (the -z flag adds a null terminator for this purpose):

         SD~t
          

Try replacing the S with a space to see the running result (the first 'y' is extraneous, the second char matches the first input, and the third is the result of the first nontrivial calculation).

///, 24 bytes

/ny/n//nn/y//yy/y//yn/n/<input>

Try it online!

I believe this is the shortest possible /// program, as making a one character substitution either is useless (if you insert something in its place) or prevents it from being an output (if you insert nothing). However, since the program must deal with the two character cases, this should be minimal.

First removes all ys right of an n. Then replaces double ns with ys, taking advantage of LTR substitution. At this stage there are many ys followed by at most one n; we deduplicate the ys and if there is an n use it to mop the last y up.

GolfScript, 14 bytes

'n'/,2%'ny'1/=

Try it online!

Ruby, 24 bytes

->s{"yn"[s.count(?n)%2]}

Try it online!

A lambda taking a string and returning a string.

Perl 5, 19 18 bytes

s/y|ny*n//g;s;^$;y

Try it online!

Similar to the Retina solution.

Stax, 9 7 bytes

Å8Dq↨W<

Run and debug it

Mathematica, 59 bytes

Not the shortest but anyway

f[s_]:=Times@@StringCases[s,a={"y"->1,"n"->-1}]/.Reverse/@a

Call if s is your string of y and n (included between ".."), call f[s].

All it does is to replace y by 1 and n by -1, then multiply them and replace the numbers back to strings.

Husk, 8 bytes

!"ny"#'n

Try it online!

dc, 39

?dsiZdsl[[]r1-d0<m]dsmxklixzll-2%B*C1+P

Input string is read from STDIN and should be in the form [yynynynynyyn].

dc is not known for its string handling, but we have just enough here to get this to work. The approach here is to count the ns, and output y if even or n if odd. This is done by executing the input string as a macro. dc will output 'y' (0171) unimplemented errors for all the ys and attempt to pop strings and print them for all the ns. So first we make sure we have plenty (total input string length) of empty strings [] on the stack to pop. Then we execute the input string and see how many [] are left on the stack. The original string length is subtracted from this to give the (-ve) total number of ns. The rest is arithmetic to do mod 2 and have the output come out right as ASCII y or n.

?dsi                                    # Read input string, duplicate, store in register i
    Zdsl                                # Get input length, duplicate, store in register l
        [         ]                     # define macro to:
         []                             #   push empty string
           r                            #   swap empty string and remaining length 
            1-                          #   subtract 1 from length
              d0                        #   duplicate and compare with 0
                <m                      #   if >0 recursively call this macro again
                   dsmx                 # duplicate macro, store in register m and execute
                       k                # discard left-over 0
                        lix             # load input string and execute as macro
                           z            # get stack length
                            ll-         # load string length and subract
                               2%       # mod 2 (result is -ve because difference is -ve)
                                 B*     # multiply by 11 ('y' - 'n')
                                   C1+  # add 121 ('y')
                                      P # print result as ASCII char

Try it online!

Java (OpenJDK 8), 143 bytes

a->{char[] u=a.toCharArray();if(u.length==1)return u[0];else{char b=(u[0]==u[1])?'y':'n',i=2;for(;i<u.length;b=(b==u[i++])?'y':'n');return b;}}

Try it online!

And if we take the input as a list:

Java (OpenJDK 8), 118 bytes

u->{if(u.length==1)return u[0];else{char b=(u[0]==u[1])?'y':'n',i=2;for(;i<u.length;b=(b==u[i++])?'y':'n');return b;}}

Try it online!

Explanation:

(input as string)

char[] u=a.toCharArray();  //turn string into char array
if(u.length==1){    
    return u[0];      //if single letter, return it
}else{
    char b=(u[0]==u[1])?'y':'n';     //first two XNOR
    for(char i=2;i<u.length;b=(b==u[i++])?'y':'n');   //XNOR each remaining character
return b;    //return final result
}

Japt, 9 bytes

Oliver beat me to the shortest solution so here are a couple that are just a byte longer.

B*aUèÍu¹d

Try it

#ndB*UèÍv

Try it


Explanations

              :Implicit input of string U
B             :11
 *            :Mutiplied by
  a           :  The absolute difference of 11 and
   UèÍ        :    The count of "n" in U
      u       :    Mod 2
       ¹d     :Get the character at that codepoint
              :Implicit input of string U
#n            :110
   B*         :Add 11 multiplied by
        v     :  The parity of
     UèÍ      :    The count of "n" in U
  d           :Get the character at that codepoint

R, 46 44 bytes

"if"(sum(1+utf8ToInt(scan(,"")))%%2,"n","y")

Try it online!

Down 2 bytes thanks to Giuseppe and ngm. Port of the Octave answer by Luis Mendo.

JavaScript, 44 bytes

(prompt()+"n").match(/n/gi).length%2?"y":"n"

Try it out on developer console.

05AB1E, 8 bytes

'n¢„ynsè

Try it online!

Python 2, 29 bytes

lambda s:'yn'[s.count('n')%2]

Try it online!

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!

Pyth, 9 bytes

@"yn"l@\n

Try it here

Explanation

@"yn"l@\n
     l@\nQ   Get the length of the intersection of the (implicit) input and "n".
@"yn"        Modular index into "yn".

Haskell, 33 28 bytes

f a=cycle"yn"!!sum[1|'n'<-a]

Indexes the count of n's into the infinite list "ynynynyn…". Previous approach (33 bytes) was folding pairs of different elements to n, otherwise y:

f=foldl1(\a b->last$'y':['n'|a/=b])

Try it online!

Perl 6, 21 bytes

{<y n>[.comb('n')%2]}

Try it

Expanded:

{  # bare block lambda with implicit parameter $_

  # index into the list ('y', 'n')
  <y n>[

    .comb('n') # get every instance of 'n' (implicit method call on $_)
    % 2        # turn it into a count and get the modulus

  ]
}

Jelly,  8  7 bytes

O‘Sị⁾ny

Try it online!

Retina, 11 bytes

y

nn

^$
y

Try it online!