Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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
Author

Create grid with starting value in center

M Bryan
Ranch Hand

Joined: Jun 15, 2011
Posts: 64
Hi,

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
Bartender

Joined: Oct 02, 2003
Posts: 11448
    
  16

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: http://aspose.com/file-tools
 
subject: Create grid with starting value in center