File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Create grid with starting value in center Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Create grid with starting value in center" Watch "Create grid with starting value in center" New topic

Create grid with starting value in center

M Bryan
Ranch Hand

Joined: Jun 15, 2011
Posts: 64

I want to create a grid with (partially) random values. Lets say the grid looks like this:

The other values should evolve from the values around them, whereas one value is fixed, like this:

The change in value from one field to another should not be bigger than one, but should be randomly. E.g., in the bottom right field there is a 7. The field above has a 6, so it could be 5, 6 or 7. The field to the left has a 7, so the value could be 6, 7 or 8. Since 6 and 7 appear in both list, the value has to be either 6 or 7.

Has anybody a good idea, how i could program this logic?

Thank you!
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

The first steps are always the same.

forget about computers, programming, data structures, etc.

Pretend you have a piece of paper with the above initial grid on it.

How would you tell a child how to do what you want? What steps should they follow?

You LITERALLY need to write this down. Writing it forces you to think through the problem.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Create grid with starting value in center
It's not a secret anymore!