TI-BASIC, 20 17 16 15-1613
BecauseBecause it is tokenized, TI-BASIC is often competitive at simple math challenges, but not this one since there is no "divisible" command. Maybe it is tokenized, TI-BASIC is often competitive at simple math challengesafter all, but not this one since there is no "divisible" commandstill longer than CJam and Pyth. 16 bytes:
This uses David Hammond's method.
not(fPart(Ans/16not4/4^not(fPart(sub(Ansnot(fPart(Ans/4
UngolfedOld code at 16 bytes:
not(fPart(Ans/16) and not16not(fPart(Ans/100) and notsub(Ansnot(fPart(Ans/4))))
//equivalent to:
Ungolfed:
not(fPart(Ans/16)) orand not(fPart(Ans/100) and not(fPart(Ans/4))))
fPart(
is "fractional part", and there is implied multiplication going onpart"; exponentiation has higher precedence than division. In TI-BASIC allows elision of, close-parens, so to minimize the size, seven have been removed. If output of 0 for a leap year and a positive float for a non-leap year is acceptable, the first not(
can be removed, making the code 15 bytes are optional.
This usesI use undocumented behavior of the sub(
command, usually used to get a substring: when its argument is a number instead of a string, it divides the number by 100. This codeIt will work on a TI-83 or 84 series calculator.
If there were a divisible( command to return 0 or 1 depending on whether the first argument divides the second, the code could have been divisible(16,Ansdivisible(E2,Ansdivisible(4,Ans
.
Edit: 20 -> 17 by rearranging code to allow removal of close-parens.
parens; 17 ->16> 16 by replacing 400 with 16; 16 -> 13 by using David Hammond's idea.