From bc54598bbc43e5fa9e8d9735152968905cae94fc Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Mon, 24 Jul 2023 15:43:33 +0200 Subject: feat(challenge-227/lubos-kolouch/perl,python/): Challenge 227 LK Perl Python --- challenge-227/lubos-kolouch/python/ch-1.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-227/lubos-kolouch/python/ch-1.py (limited to 'challenge-227/lubos-kolouch/python/ch-1.py') diff --git a/challenge-227/lubos-kolouch/python/ch-1.py b/challenge-227/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..1a2e1d0042 --- /dev/null +++ b/challenge-227/lubos-kolouch/python/ch-1.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from datetime import datetime, timedelta + + +def friday_13ths(year): + dt = datetime(year, 1, 1) + friday_13_count = 0 + + while dt.year == year: + if dt.weekday() == 4 and dt.day == 13: + friday_13_count += 1 + dt += timedelta(days=1) + + return friday_13_count + + +print(friday_13ths(2023)) # 2 -- cgit