Function for finding unique string

This commit is contained in:
2022-12-06 12:46:07 +02:00
parent f9ace9f63d
commit 5498f566a0

22
06/f.py
View File

@@ -6,19 +6,15 @@ input = open(os.path.dirname(__file__) +
index, index1, index2 = 0, 0, 0
buf = []
def findUniq(length):
ind = 0
for x in input:
index += 1
buf.append(x)
if index1 == 0 and len(buf) == 4:
if len(set(buf)) == 4:
index1 = index
buf.pop(0)
ind += 1
if len(set(input[ind:ind+length])) == length:
return ind+length
return False
if index2 == 0 and len(buf) == 14:
if len(set(buf)) == 14:
index2 = index
break
buf.pop(0)
print("First answer: " + str(index1))
print("Second answer: " + str(index2))
print("First answer: " + str(findUniq(4)))
print("Second answer: " + str(findUniq(14)))