bool isLeap(int year) { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); }
- bool isLeap(int year) {
bool leap = true;if(year % 4 != 0){leap = false;}if(year % 100 == 0 && year % 400 != 0) {leap = false;}return leap;- return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
- }
succ = lambda n: lambda f: lambda x: f (n (f) (x)) add = lambda a: lambda b: lambda f: lambda x: a (f) (b (f) (x)) zero = lambda f: lambda x: x one = succ(zero) two = succ(one) three = succ(two) four = succ(three) five = succ(four) nine = add(four)(five) fst = lambda a: lambda b: a snd = lambda a: lambda b: b pair = lambda a: lambda b: lambda f: f (a) (b) zadd = lambda a: lambda b: pair (add (a (fst)) (b (fst))) (add (a (snd)) (b (snd))) phi = lambda p: pair (p (snd)) (succ (p (snd))) pred = lambda n: n (phi) (z0) (fst) sub = lambda a: lambda b: b (pred) (a) true = lambda p: lambda q: p false = lambda p: lambda q: q and_ = lambda p: lambda q: p (q) (false) or_ = lambda p: lambda q: p (true) (q) zerop = lambda n: n (lambda x: false) (true) leq = lambda a: lambda b: zerop (sub (a) (b)) eq = lambda a: lambda b: and_ (leq (a) (b)) (leq (b) (a)) zzerop = lambda n: eq (n (fst)) (n (snd)) zneg = lambda n: pair (n (snd)) (n (fst)) equal = lambda a: lambda b: zzerop (zadd (a) (zneg (b))) z0 = pair(zero)(zero) z3 = pair(three)(zero) z4 = pair(four)(zero) z5 = pair(five)(zero) z9 = zadd(z4)(z5) z_2 = pair(zero)(two) sum = zadd bool = lambda p: p (True) (False)
sum = lambda a, b: a + b- succ = lambda n: lambda f: lambda x: f (n (f) (x))
- add = lambda a: lambda b: lambda f: lambda x: a (f) (b (f) (x))
- zero = lambda f: lambda x: x
- one = succ(zero)
- two = succ(one)
- three = succ(two)
- four = succ(three)
- five = succ(four)
- nine = add(four)(five)
- fst = lambda a: lambda b: a
- snd = lambda a: lambda b: b
- pair = lambda a: lambda b: lambda f: f (a) (b)
- zadd = lambda a: lambda b: pair (add (a (fst)) (b (fst))) (add (a (snd)) (b (snd)))
- phi = lambda p: pair (p (snd)) (succ (p (snd)))
- pred = lambda n: n (phi) (z0) (fst)
- sub = lambda a: lambda b: b (pred) (a)
- true = lambda p: lambda q: p
- false = lambda p: lambda q: q
- and_ = lambda p: lambda q: p (q) (false)
- or_ = lambda p: lambda q: p (true) (q)
- zerop = lambda n: n (lambda x: false) (true)
- leq = lambda a: lambda b: zerop (sub (a) (b))
- eq = lambda a: lambda b: and_ (leq (a) (b)) (leq (b) (a))
- zzerop = lambda n: eq (n (fst)) (n (snd))
- zneg = lambda n: pair (n (snd)) (n (fst))
- equal = lambda a: lambda b: zzerop (zadd (a) (zneg (b)))
- z0 = pair(zero)(zero)
- z3 = pair(three)(zero)
- z4 = pair(four)(zero)
- z5 = pair(five)(zero)
- z9 = zadd(z4)(z5)
- z_2 = pair(zero)(two)
- sum = zadd
- bool = lambda p: p (True) (False)
test.assert_equals(bool (equal (sum (z4) (z5)) (z9)), True, "Failed") test.assert_equals(bool (equal (sum (z_2) (z5)) (z3)), True, "Failed")
# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)# test.assert_equals(actual, expected, [optional] message)# test.assert_not_equals(actual, expected, [optional] message)test.assert_equals(sum(4,5), 9, "Failed")test.assert_equals(sum(-2,5), 3, "Failed")# You can use Test.describe and Test.it to write BDD style test groupings- test.assert_equals(bool (equal (sum (z4) (z5)) (z9)), True, "Failed")
- test.assert_equals(bool (equal (sum (z_2) (z5)) (z3)), True, "Failed")