From 8bb69f7cf56687088037c7ac7c328d52b677cb5d Mon Sep 17 00:00:00 2001 From: eddie Date: Wed, 18 Dec 2024 17:47:53 +0100 Subject: [PATCH] Solve TaskC03 --- TaskC03/solution.py | 13 +++++++++++++ TaskC03/test.out | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 TaskC03/solution.py create mode 100644 TaskC03/test.out diff --git a/TaskC03/solution.py b/TaskC03/solution.py new file mode 100644 index 0000000..4858bb0 --- /dev/null +++ b/TaskC03/solution.py @@ -0,0 +1,13 @@ +import re +import sys + +def is_valid_nip(line: str) -> bool: + # matching either: + # xxx-xxx-xx-xx OR xxx-xx-xx-xxx + p = re.compile(r'^(?:\d{3}-\d{3}-\d{2}-\d{2}|\d{3}-\d{2}-\d{2}-\d{3})$') + return bool(p.match(line)) + +if __name__ == "__main__": + for line in sys.stdin: + stripped_line = line.strip() + print("yes" if is_valid_nip(stripped_line) else "no") diff --git a/TaskC03/test.out b/TaskC03/test.out new file mode 100644 index 0000000..29fe7aa --- /dev/null +++ b/TaskC03/test.out @@ -0,0 +1,5 @@ +yes +yes +yes +no +no