Function for finding unique string
This commit is contained in:
24
06/f.py
24
06/f.py
@@ -6,19 +6,15 @@ input = open(os.path.dirname(__file__) +
|
|||||||
index, index1, index2 = 0, 0, 0
|
index, index1, index2 = 0, 0, 0
|
||||||
buf = []
|
buf = []
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if index2 == 0 and len(buf) == 14:
|
def findUniq(length):
|
||||||
if len(set(buf)) == 14:
|
ind = 0
|
||||||
index2 = index
|
for x in input:
|
||||||
break
|
ind += 1
|
||||||
buf.pop(0)
|
if len(set(input[ind:ind+length])) == length:
|
||||||
|
return ind+length
|
||||||
|
return False
|
||||||
|
|
||||||
print("First answer: " + str(index1))
|
|
||||||
print("Second answer: " + str(index2))
|
print("First answer: " + str(findUniq(4)))
|
||||||
|
print("Second answer: " + str(findUniq(14)))
|
||||||
|
|||||||
Reference in New Issue
Block a user