C, 81
I can do shorter, but this one neatly sticks to 'char' types, without parsing the argument (e.g. with atoi
):
main(c,v)char**v;{char*p=*v+9;p-=2*(96==*p+p[1]);putchar("ynnn"[(2**p^p[1])&3]);}
It must be invoked with a name 4 characters long, because it makes the standard assumption that arguments immediately follow the program name, separated by NULs. Furthermore, it assumes that the single argument is encoded in ASCII and has no leading space.
###Explanation:
Explanation:
main(c,v)
char**v;
{
char *p = *v+9;
if (p[0] + p[1] == '0'+'0')
p -= 2;
putchar("ynnn"[((*p << 1) ^ p[1])&3]);
}
*v+9
is the position of the 'tens' digit in v[1]+2
.
If the 'tens' and 'units' characters add to 96, we end in 00
, so back up two characters, so that 'tens' and 'units' point to the century number.
Now xor 'units' with twice the 'tens', mod 4. This works because 10==±2 mod 4
, so the lower bit of the 'tens' can just toggle bit 1 of the 'units'. We use the result as an index into our remainders table, printing y
only if the modular result is zero.