I am facing a strange question, which despite of trying many times, i am not able to find the logic and proper code to the problem.
I have a file in the format below:
aa:bb:cc dd:ee:ff 100 ---------->line1
aa:bb:cc dd:ee:ff 101 ---------->line2
dd:ee:ff aa:bb:cc 230 ---------->line3
dd:ee:ff aa:bb:cc 231 ---------->line4
dd:ee:ff aa:bb:cc 232 ---------->line5
aa:bb:cc dd:ee:ff 102 ---------->line6
aa:bb:cc dd:ee:ff 103 ---------->line7
aa:bb:cc dd:ee:ff 108 ---------->line8
dd:ee:ff aa:bb:cc 233 ---------->line9
gg:hh:ii jj:kk:ll 450 ---------->line10
jj:kk:ll gg:hh:ii 600 ---------->line11
My program should read the file line by line. In the first line and second line, corresponding column1 and column2 values are equal. Third column is the sequence number which is not the same for any two lines.
Since line1 and line2 are same except, their sequence numbers differ by value of only 1, i should read those two lines first and write their count as 2 to an output file. If we observe, line 6 and line 7 are same as line 1 and line 2, having consecutive sequence numbers, but the line numbers line3, line4, line5 having different column 1 and column 2 entries came in between them. Hence lines(1&2) and lines(6&7) should not be grouped all together. So, in the output file, i should get result like 2 3 2 1 1 1 1. And one more thing is, lines 7 and 8 are differed by sequence number more than 1. Hence, line 8 should be counted as a separate entry, not together with lines 6 and 7 though lines 6,7,8 has same first two columns.
I hope most people understood the question. If not, i will clarify anything on the question.
As you can see this is a very complicated problem. I tried using dictionary as that is the only data structure i know, but no logic works. Please help me solve this problem.