Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open ("input.txt", "r") as myfile:
- data = myfile.readlines()
- data = map(lambda line: map(lambda num: int(num, 16), line.replace('\n', '').split("|")), data)
- head = data[0]
- data = data[1:]
- def getSeq(data, firstDataIndex, sequenceIndex, expectedValue, nextExpectedValues):
- last = len(nextExpectedValues) == 0
- for index in range(firstDataIndex, len(data)):
- seq = data[index]
- if seq[sequenceIndex] == expectedValue:
- if last:
- yield [index]
- else:
- for nextItem in getSeq(data, index + 1, sequenceIndex, nextExpectedValues[0], nextExpectedValues[1:]):
- yield [index] + nextItem
- maxL = lambda mx, item: mx if mx > item else item
- longestSequence = 0
- for seq in data:
- longestSequence = maxL(reduce(maxL, seq, 0), longestSequence)
- with open("output.txt","w") as file:
- for valueIndex in range(0, longestSequence): # For each index
- # Collect sequences of such length
- seqs = []
- rev = []
- for i in range(len(data)):
- seq = data[i]
- if len(seq) > valueIndex:
- seqs.append(seq)
- rev.append(i)
- print("Seeking at index {0}/{1} in {2} total sequences".format(valueIndex + 1, longestSequence, len(seqs)))
- # Take every sequence as if it could be the first
- for sequenceIndex in range(len(seqs)):
- val = seqs[sequenceIndex][valueIndex]
- for sequences in getSeq(seqs, sequenceIndex, valueIndex, val + head[0], map(lambda var: var + val, head[1:])):
- result = ", ".join(map(lambda val: "sequences[{0}][{1}] == {2}".format(rev[val], valueIndex, seqs[val][valueIndex]), sequences))
- file.write(result);
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement