#

**1**
Banned

**363,**

**7**

Join Date: Jan 2012

Last Activity: 24 June 2017, 6:25 PM EDT

Posts: 363

Thanks Given: 318

Thanked 7 Times in 7 Posts

**Read values in each col starting 3rd row.Print occurrence value.**

Hello Friends,

Hope all are doing fine.

Here is a tricky issue.

my input file is like this

1. Please print another column as "0-0-0-0-0" for the first and second rows.

2. Read the first column of third row, which is 1. Look for this value in all columns of first and second row. 1 is not present in first or second rows, so print a value 2 for this.

3. Then read the second column of third row, which is 10. There is 10 in first and not in second rows. So, it basically skipped the second row only. Now print a value of 1.

4. Then read the third column of third row, which is 11. 11 does not appear in first or second rows, so print a value of 2.

5. 19 has no appearances in first or second rows, so its value will be 2.

6. 30 did not appear in first row, but it appears in second row, which is the IMMEDIATE row of the current row that is being read which is row no.3. So, since no rows were skipped, we will print 0 for this one

So far the output will be

7. Now read the first column of fourth row, which is 2. Look for this value across anywhere in all the three rows above. Since 2 is not present, we will print a value 3 for this. Because it is not present in the three rows above.

8. Now read the second column of 4th row, which is 6. 6 is also not present across any of the three rows above. So its value will also be 3.

9. Read the third column of 4th row, which is 14. 14 is present in first row only but not in the second or third rows, so it skipped two rows. So print a value of 2 for this.

10. Read forth column of 4th row, which is 15. It is not present in first row. Fine. It is present in second row and not in third row. It basically skipped one IMMEDIATE row which is the third. We don't really care for the first row here. All we worry about is the number of times a value skipped after it appeared in the input file. So, the value for 15 will be 1.

11. Read last column of 4th row, which is 17. It is not present in any of the three rows above. So, we will print 3. Basically, if a value is not present across all top rows of the current row being considered, we HYPOTHESIZE that this value was PRESENT before the first line of the input. That is the reason we are printing 3 for the values that are not seen in any of the rows above row number 4.

So far, the output looks like this

12. Now the last row's first value which is 01. This iss present in third row and skipped the 4th. So, its value will be 1. If you see a value present in any row above the current row, then you DONT have to move any way further up because you have already seen that value.

13. Second column of last row, which is 06. This is present in 4th row. So, the value will be zero and DO NOT check any lines above because a value has been encountered.

14. Third column of last row, which is 20. It is present in first row but not in second, third or fourth rows. So, it skipped three rows. Print a value of 3 for this.

15. Forth column of last row, which is 25. This is not present anywhere.

16. Fifth column of last row, which is 29. Present nowhere. So, print a value of 4.

Here is the final output

I would also like to have the frequency of unique numbers in the output column like this here

Please ask me any questions or comments in case of any doubt.

a. My columns are always 5.

b. My input file always has 25 records only.

c.

Thank You!

Hope all are doing fine.

Here is a tricky issue.

my input file is like this

**Logic:**1. Please print another column as "0-0-0-0-0" for the first and second rows.

2. Read the first column of third row, which is 1. Look for this value in all columns of first and second row. 1 is not present in first or second rows, so print a value 2 for this.

3. Then read the second column of third row, which is 10. There is 10 in first and not in second rows. So, it basically skipped the second row only. Now print a value of 1.

4. Then read the third column of third row, which is 11. 11 does not appear in first or second rows, so print a value of 2.

5. 19 has no appearances in first or second rows, so its value will be 2.

6. 30 did not appear in first row, but it appears in second row, which is the IMMEDIATE row of the current row that is being read which is row no.3. So, since no rows were skipped, we will print 0 for this one

So far the output will be

**Logic Continued:**7. Now read the first column of fourth row, which is 2. Look for this value across anywhere in all the three rows above. Since 2 is not present, we will print a value 3 for this. Because it is not present in the three rows above.

8. Now read the second column of 4th row, which is 6. 6 is also not present across any of the three rows above. So its value will also be 3.

9. Read the third column of 4th row, which is 14. 14 is present in first row only but not in the second or third rows, so it skipped two rows. So print a value of 2 for this.

10. Read forth column of 4th row, which is 15. It is not present in first row. Fine. It is present in second row and not in third row. It basically skipped one IMMEDIATE row which is the third. We don't really care for the first row here. All we worry about is the number of times a value skipped after it appeared in the input file. So, the value for 15 will be 1.

11. Read last column of 4th row, which is 17. It is not present in any of the three rows above. So, we will print 3. Basically, if a value is not present across all top rows of the current row being considered, we HYPOTHESIZE that this value was PRESENT before the first line of the input. That is the reason we are printing 3 for the values that are not seen in any of the rows above row number 4.

So far, the output looks like this

**Logic Continued:**12. Now the last row's first value which is 01. This iss present in third row and skipped the 4th. So, its value will be 1. If you see a value present in any row above the current row, then you DONT have to move any way further up because you have already seen that value.

13. Second column of last row, which is 06. This is present in 4th row. So, the value will be zero and DO NOT check any lines above because a value has been encountered.

14. Third column of last row, which is 20. It is present in first row but not in second, third or fourth rows. So, it skipped three rows. Print a value of 3 for this.

15. Forth column of last row, which is 25. This is not present anywhere.

*"Remember our hypothesis - this value occurred before the first line"*. So, we are printing 4 for this.16. Fifth column of last row, which is 29. Present nowhere. So, print a value of 4.

Here is the final output

I would also like to have the frequency of unique numbers in the output column like this here

Please ask me any questions or comments in case of any doubt.

__P.S:__a. My columns are always 5.

b. My input file always has 25 records only.

c.

__A bonus of 5000 bits will be awarded to the best working solution.__Thank You!

*Last edited by jacobs.smith; 04-10-2016 at 04:03 PM.. Reason: code tags format*