This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Finding a particular pattern in a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Finding a particular pattern in a file" Watch "Finding a particular pattern in a file" New topic

Finding a particular pattern in a file

sina sinchen

Joined: May 24, 2004
Posts: 9
Hallo everybody,

I have a file which indicates a link between 2 persons(column 1&2) and column3 is their relation.

1 2 1
2 3 1
1 3 1
3 4 1
3 5 1
4 5 1
5 4 1
6 7 1
6 8 1
7 8 1
7 8 2

SO i have here 8 persons(their links in coumn1&2) with relation1 as regulation and relation2 as interaction(column3).

I wrote a program which searches for the links between 3 persons in the following way:
if we consider 3 persons(a pattern) 1,2,3 then there should be a link between (1,2)(1,3)&(2,3) and the relation should be always1(regulation).Then the output should be those 3 persons(1,2,3).

*If there exists a reverselink between (2,1) and also when a link has both the relations(1&2-regulation and interaction)then the pattern should be ignored
For example in the case of 3,4,5.we have (3,4)(3,5)&(4,5) with the relation 1 and we also have a reverse regulation(5,4). In this case 3,4,5 shouldnot be counted.

Also6,7,8.Links (6,7)(6,8)&(7,8)all with relation 1 but at the lastline we also have a link (7,8)with a relation2.So it should also be ignored.

My program:

THe original file which I have used as input has around 1300 persons and almost 6000 rows(links).Computational time is too much and also the baove program gives the output which considers reverse regulation.Which shouldnot happen?

Kindly correct my code running the sample input file given above.

The output should be 1,2,3 in the above case.

Thanx in advance

[ October 10, 2005: Message edited by: sina sinchen ]
[ October 10, 2005: Message edited by: Mark Spritzler ]
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

Let's move this to Programming Diversions

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
I agree. Here's the link:
subject: Finding a particular pattern in a file
It's not a secret anymore!