0

Unable to solve Test case #4 of problem named "Security" in hard section of code coach

I am using REGEX in this problem (personal preference). Can anyone identify exactly what my pattern is not recognising or where am I going wrong? from re import search pattern = r"(^G(x)*(\$)+(x)*T$)|(^T(x)*(\$)+(x)*G$)" if search(pattern, input()): print("ALARM") else: print("quiet")

8th Mar 2020, 6:16 AM
Pronoy Mandal
Pronoy Mandal - avatar
3 Respostas
+ 1
Money doesn't have to be in middle, consider two other cases, explicitly : $_T_G G_T_$
8th Mar 2020, 6:39 AM
Gordon
Gordon - avatar
0
Still the fourth test case is failing. I added the above two conditions in the regex.
8th Mar 2020, 6:53 AM
Pronoy Mandal
Pronoy Mandal - avatar
0
Because it doesn't have to begin with one of the three special characters and also does not have to end with one of the three special characters. Instead of ^G, use "any character of any number exists or not exists", i. e. "^.*G..... Same idea for handling the end. Here is a reading about {n}, {a, b}, +, ? and *
8th Mar 2020, 7:30 AM
Gordon
Gordon - avatar