Skip to main content
edited body
Source Link

Javascript (ES5ES6), 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y

Javascript (ES5), 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y

Javascript (ES6), 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y
added 6 characters in body
Source Link

Javascript (ES5), 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y

Javascript, 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y

Javascript (ES5), 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y
added 321 characters in body
Source Link

Javascript, 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y

Javascript, 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

Javascript, 21 characters

The standard rule is that y is a leap year if 4 divides y and if either 100 doesn't divide y or 400 does divide y. In code,

y%4 == 0 && (y%100 != 0 || y%400 == 0)

There's no need for that 100 and 400. Instead it suffices to check whether 16 or 4 divides y, with 16 chosen if 25 divides y, 4 otherwise. Golfed, this becomes

!(y%(y%25?4:16))

A javascript function that implements this is 21 characters long:

l=y=>!(y%(y%25?4:16))

# Perl, 28 26 characters

Same idea, but in perl.

$_=$_%($_%25?4:16)?"n":"y"

Run using the -lp options. For example,

perl -lpe '$_=$_%($_%25?4:16)?"n":"y"'

With the test set as input, this produces

1936
y
1805
n
1900
n
2272
y
2400
y
Source Link
Loading