Skip to content

Commit f430e3c

Browse files
authored
running black on doomsday
1 parent ca64cd0 commit f430e3c

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

other/doomsday.py

+26-22
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,50 @@
99
https://en.wikipedia.org/wiki/Doomsday_rule
1010
"""
1111

12-
_doomsday_leap = [4,1,7,4,2,6,4,1,5,3,7,5]
13-
_doomsday_not_leap = [3,7,7,4,2,6,4,1,5,3,7,5]
14-
_week_day_names = {
15-
0 : "Sunday",
16-
1 : "Monday",
17-
2 : "Tuesday",
18-
3 : "Wednesday",
19-
4 : "Thursday",
20-
5 : "Friday",
21-
6 : "Saturday"
22-
}
12+
_doomsday_leap = [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
13+
_doomsday_not_leap = [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
14+
_week_day_names = {
15+
0: "Sunday",
16+
1: "Monday",
17+
2: "Tuesday",
18+
3: "Wednesday",
19+
4: "Thursday",
20+
5: "Friday",
21+
6: "Saturday",
22+
}
2323

2424

2525
def get_week_day(year: int, month: int, day: int) -> str:
26-
""" Returns the week-day name out of a given date.
27-
26+
"""Returns the week-day name out of a given date.
27+
2828
>>> get_week_day(2020, 10, 24)
2929
Saturday
3030
>>> get_week_day(2017, 10, 24)
3131
Tuesday
32-
32+
3333
"""
3434
# minimal input check:
35-
assert len(str(year)) > 2, 'Please supply year in YYYY format'
36-
assert 1 <= month <= 12, 'Invalid month value, please give a number between 1 to 12'
37-
assert 1 <= day <= 31, 'Invalid day value, please give a number between 1 to 31'
35+
assert len(str(year)) > 2, "Please supply year in YYYY format"
36+
assert 1 <= month <= 12, "Invalid month value, please give a number between 1 to 12"
37+
assert 1 <= day <= 31, "Invalid day value, please give a number between 1 to 31"
3838

3939
# Doomsday algorithm:
4040
century = year // 100
4141
century_anchor = (5 * (century % 4) + 2) % 7
4242
centurian = year % 100
4343
centurian_m = centurian % 12
44-
dooms_day = ((centurian // 12) + centurian_m +
45-
(centurian_m // 4) + century_anchor) % 7
46-
day_anchor = _doomsday_not_leap[month - 1] if (year % 4 != 0) or (centurian == 0
47-
and (year % 400) == 0) else _doomsday_leap[month - 1]
44+
dooms_day = (
45+
(centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor
46+
) % 7
47+
day_anchor = (
48+
_doomsday_not_leap[month - 1]
49+
if (year % 4 != 0) or (centurian == 0 and (year % 400) == 0)
50+
else _doomsday_leap[month - 1]
51+
)
4852
week_day = (dooms_day + day - day_anchor) % 7
4953
return _week_day_names[week_day]
5054

5155

52-
if __name__ == '__main__':
56+
if __name__ == "__main__":
5357
# unit-test:
5458
assert get_week_day(2020, 10, 24) == "Saturday"

0 commit comments

Comments
 (0)