Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: How would one attempt to create an algorithm for this?

1. ## How would one attempt to create an algorithm for this?

Say you have a grid with a compound. (size differs)

Let's just say our compound is HOH.

***OHH***
*H******H
****HH***
****O****

Clearly in this grid there are two HOH compounds considering the explanation below.

In this grid how would create an algorithm to find the combinations of HOH compound.

Combinations exist if they are neighbors in the grid, above, below, to the left or to the right. Atoms that are only neighbors diagonally do not count.

So these are examples of compounds.

**HH**
**O***

**H***
**O***
**H***

This is not a compound.

*HH***
***O**

How would you attempt to do this?

2. ## Re: How would one attempt to create an algorithm for this?

Are they neighbours if they aren't directly above? I don't see the two compounds in the 1st example.

3. ## Re: How would one attempt to create an algorithm for this?

Originally Posted by Starstreak
Are they neighbours if they aren't directly above? I don't see the two compounds in the 1st example.
They are neighbours if they aren't directly above. They can be either above below to the right or to the left..