Add tags

Add tags to the following comment

とても素朴な書き方。剰余の計算を禁止しても引き算の繰り返しでできてしまいますね。一応、大きい順に引くことで繰り返しの回数を減らしてあります。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
>>> def leap(x, d=400):
    if x < 0:
        return leap(-x, d)

    if x == 0:
        if d == 400:
            return True
        if d == 100:
            return False
        if d == 4:
            return True

    if x < d:
        if d == 400:
            return leap(x, 100)
        if d == 100:
            return leap(x, 4)
        if d == 4:
            return False

    return leap(x - d, d)

>>> leap(1900)
False
>>> leap(2000)
True
>>> leap(2008)
True
>>> leap(2100)
False

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...