Comment detail
除算・余剰を使わずに閏年 (Nested Flatten)This comment is reply for 5336 sumim: Squeak Smalltalk で。(除算・余剰を使わずに閏年). Go to thread root.
まあ、こういうのもあるということで。
1 2 3 4 5 6 7 8 9 10 | | 閏年か? |
閏年か? := [:int |
(int isDivisibleBy: 4)
and: [(int isDivisibleBy: 100) not or: [int isDivisibleBy: 400]]].
閏年か? value: 1900. "=> false "
閏年か? value: 2000. "=> true "
閏年か? value: 2008. "=> true "
閏年か? value: 2100. "=> false "
|





sumim
#5339()
[
Smalltalk
]
Rating0/0=0.00
考えたら、べつに無限にせずともこれで十分ですね(^_^;)。
| 閏年か? | 閏年か? := [:int | ((0 to: int by: 4) includes: int) and: [((0 to: int by: 100) includes: int) not or: [(0 to: int by: 400) includes: int]]]. 閏年か? value: 1900. "=> false " 閏年か? value: 2000. "=> true " 閏年か? value: 2008. "=> true " 閏年か? value: 2100. "=> false "Rating0/0=0.00-0+