diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2024-03-04 09:39:17 +0100 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2024-03-04 14:19:40 +0100 |
| commit | 2b5457f572cf53ed6ff5b679de754feafa5b8eb6 (patch) | |
| tree | dee7a4007ed79c9bbbc87a1000d910eae4b80396 /challenge-259/luca-ferrari/python/ch-1.py | |
| parent | ad381c1123e47114d3d98f1749f9f354eebafcdd (diff) | |
| download | perlweeklychallenge-club-2b5457f572cf53ed6ff5b679de754feafa5b8eb6.tar.gz perlweeklychallenge-club-2b5457f572cf53ed6ff5b679de754feafa5b8eb6.tar.bz2 perlweeklychallenge-club-2b5457f572cf53ed6ff5b679de754feafa5b8eb6.zip | |
PWC 259
Task 1 Raku done
Task 2 Raku done
Task 1 PL/Perl done
Task 2 PL/Perl done
Task 1 PL/PgSQL done
Task 2 PL/PgSQL done
Task 1 Python done
Task 2 Python done
Task 1 PL/Java done
Task 2 PL/Java done
Diffstat (limited to 'challenge-259/luca-ferrari/python/ch-1.py')
| -rw-r--r-- | challenge-259/luca-ferrari/python/ch-1.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-259/luca-ferrari/python/ch-1.py b/challenge-259/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..9b3a0fd121 --- /dev/null +++ b/challenge-259/luca-ferrari/python/ch-1.py @@ -0,0 +1,37 @@ +#!python + +# +# Perl Weekly Challenge 259 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-259> +# + +import sys +from datetime import date, timedelta + +# task implementation +# the return value will be printed +def task_1( args ): + day = date.fromisoformat( args[ 0 ] ) + offset = int( args[ 1 ] ) + holidays = list( map( lambda x: date.fromisoformat( x ), args[ 2: ] ) ) + one_day = timedelta( days=1 ) + + while offset > 0 : + day += one_day + + while day.weekday() >= 6 or day.weekday() == 0: + day += one_day + + while day in holidays : + day += one_day + + offset -= 1 + + return day + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) |
