From 923a1d5b5c5ba524eaff390d2df4222a46d34030 Mon Sep 17 00:00:00 2001 From: kjubik Date: Mon, 6 Jan 2025 14:38:17 +0100 Subject: [PATCH] add solution for TaskC21 --- TaskC21_TODO/solution.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 TaskC21_TODO/solution.py diff --git a/TaskC21_TODO/solution.py b/TaskC21_TODO/solution.py new file mode 100644 index 0000000..d4a998f --- /dev/null +++ b/TaskC21_TODO/solution.py @@ -0,0 +1,25 @@ +# HORSE HEAD -> 46773 4323 +import re +import sys + +pattern = r'^[A-Z][A-Z][A-Z][A-Z][A-Z] [A-Z][A-Z][A-Z][A-Z]$' + +def get_number(c): + result = re.sub(r'[ABC]', '2', c) + result = re.sub(r'[DEF]', '3', result) + result = re.sub(r'[GHI]', '4', result) + result = re.sub(r'[JKL]', '5', result) + result = re.sub(r'[MNO]', '6', result) + result = re.sub(r'[PQRS]', '7', result) + result = re.sub(r'[TUV]', '8', result) + result = re.sub(r'[WXYZ]', '9', result) + return result + +for line in sys.stdin: + line = line.strip() + if not re.match(pattern, line): + print('no') + continue + + num = ''.join(get_number(c) for c in line.replace(' ', '')) + print('yes' if re.match(r'^467734323$', num) else 'no')