Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 A. Hinton
Copyright (c) 2018 Aaron H.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion arrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ def remove_element(nums: List[int], val: int) -> int:
return length - count
```

## Replace Elements with Greatest Element on Right Side
## Replace Elements with Greatest Element on Right Side

Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.

Expand Down
26 changes: 26 additions & 0 deletions math_problems/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* [Count Primes](#count-primes)
* [Fizz Buzz](#fizz-buzz)
* [Leap Year](#leap-year)
* [Power of Three](#power-of-three)

## Count Primes
Expand Down Expand Up @@ -65,6 +66,31 @@ def fizz_buzz(iterations: int) -> List[str]:
return output
```

## Leap Year

An extra day is added to the calendar almost every four years as February 29, and the day is called a leap day. It corrects the calendar for the fact that our planet takes approximately 365.25 days to orbit the sun. A leap year contains a leap day.

In the Gregorian calendar, three conditions are used to identify leap years:

The year can be evenly divided by 4, is a leap year, unless:
The year can be evenly divided by 100, it is NOT a leap year, unless:
The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years. Source

Task

Given a year, determine whether it is a leap year. If it is a leap year, return the Boolean True, otherwise return False.

Note that the code stub provided reads from STDIN and passes arguments to the is_leap function. It is only necessary to complete the is_leap function.

Input Format

* the year to test.

Output Format

* The function must return a Boolean value (True/False). Output is handled by the provided code stub.

## Moving Average

Create a class `MovingAverage` to calculate the average of a max amount of numbers (n).
Expand Down
25 changes: 25 additions & 0 deletions math_problems/leap_year.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


def leap_year(year: int) -> bool:
"""
In the Gregorian calendar, three conditions are used to identify leap years:
The year can be evenly divided by 4, is a leap year, unless:
The year can be evenly divided by 100, it is NOT a leap year, unless:
The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years,
while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years. Source
"""
leap = False

if year % 4 == 0:
if year % 100 == 0 and year % 400 == 0:
leap = True
elif year % 100 == 0:
leap = False
else:
leap = True
else:
leap = False

return leap
11 changes: 11 additions & 0 deletions math_problems/tests/test_leap_year.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from math_problems.leap_year import leap_year


def test_leap_year():
assert leap_year(2000)
assert leap_year(2400)
assert not leap_year(1800)
assert not leap_year(1900)
assert not leap_year(2100)
assert not leap_year(2200)
assert not leap_year(2300)
Loading