diff options
| author | Simon Green <mail@simon.green> | 2025-08-03 17:54:51 +1000 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2025-08-03 17:54:51 +1000 |
| commit | 39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e (patch) | |
| tree | 01264677624c449a5e65dcd01bf7347d4fd82d0d /challenge-332/sgreen/python/ch-1.py | |
| parent | 6f0d16f05f2773a17829abb2db30dff2c2f73444 (diff) | |
| download | perlweeklychallenge-club-39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e.tar.gz perlweeklychallenge-club-39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e.tar.bz2 perlweeklychallenge-club-39d8e45fc8a55d48a2b5bbceef09d7a2de1d846e.zip | |
sgreen solutions to challenge 332
Diffstat (limited to 'challenge-332/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-332/sgreen/python/ch-1.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-332/sgreen/python/ch-1.py b/challenge-332/sgreen/python/ch-1.py new file mode 100755 index 0000000000..ece17b48dd --- /dev/null +++ b/challenge-332/sgreen/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import sys + + +def binary_date(input_string: str) -> str: + """Convert a date string in the format 'YYYY-MM-DD' to a binary representation. + + Args: + input_string (str): The date string in 'YYYY-MM-DD' format. + + Returns: + str: The binary representation of the date, with parts separated by hyphens. + """ + + # Split the input string by hyphens + date_parts = input_string.split('-') + + # Convert each part to binary and remove the '0b' prefix + binary_parts = [bin(int(part))[2:] for part in date_parts] + + # Join the binary parts with hyphens + return '-'.join(binary_parts) + + +def main(): + result = binary_date(sys.argv[1]) + print(result) + + +if __name__ == '__main__': + main() |
