So the golf question was like this:
You are given a number
T
and then a total ofT
number of 17-character strings. For each of the strings, outputyes
if it contains four consecutive identical characters or contains the substringDX
, else outputno
.
The following constraints are promised for each of the 17-character strings:
- The possible character set is
DX2AKQJT9876543
; - The input string is sorted in the above mentioned order, hence the number of times each character appears is exactly the size of the longest contiguous substring of the character;
- No characters will appear more than 4 times;
X
andD
will appear no more than once each.
Test case:
3
X2AAKKKKQT9765433
DX22AKKQJTT884443
X2AAAKQQJT8554433
should have the output
yes
yes
no
Note:
- Output is not case sensitive, so
YeS
is also legal; - You may assume an extra
\n
after the end of the input.
My attempt goes like this:
Python, probably 84 85 Bytes
import re
input()
while n:=input():print("yes"if re.search(r"(.)\1{3}|DX",n)else"no")
Also, I have the following alternatives for line 3, while are approximately the same length:
while n:=input():print("yneos"[not re.search(r"(.)\1{3}|DX",n)::2])
while n:=input():print(["yes","no"][not re.search(r"(.)\1{3}|DX",n)])
while n:=input():print((not re.search(r"(.)\1{3}|DX",n))*"no"or"yes")
Is there anything I can do to make this shorter? Thanks in advance!
Source: Question made by a friend, problem ID on Luogu is P8466
r
before my regex string, I’ll make an edit to add it, now it would be 85 bytes \$\endgroup\$re
here. The import andre.search
call are overkill what you're using them for, and they take too many bytes of overhead. Checking substrings or counting characters can be done with Python built-ins. \$\endgroup\$open(0)
be used to take input here? May we terminate with error? \$\endgroup\$