Results 1 to 3 of 3
  1. #1
    Bryan_James is offline Member
    Join Date
    Jul 2015
    Location
    Philippines
    Posts
    2
    Rep Power
    0

    Question Generate 1's and 0's in a grid without consecutives

    Hi! I would like to create a program that creates a grid of one and zeroes with no three consecutive (one or zero, both vertical and horizontal). The program should generate random arrangement of grid every time it is called. The program should generate equal amount of one and zeroes in each row and column. I already prepared a two dimensional array of integer where zeroes and ones will be stored. I also prepared a random number generator. My problem is how do I do this without consecutives? Thanks in advance!
    Last edited by Bryan_James; 02-21-2016 at 08:48 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Generate 1's and 0's in a grid without consecutives

    tip: make that grid a two dimensional array of booleans: boolean grid[][]; do you know how to traverse a two dim array horizontally or vertically, starting at a certain coordinate (x,y)? b.t.w. A Random object can generate pseudo random booleans as well (see the API documentation for the Random class).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Generate 1's and 0's in a grid without consecutives

    how do I do this without consecutives?
    Test if the next value to be added will make 3 consecutives and change its value.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. java set grid GUI
    By Ericyue in forum New To Java
    Replies: 1
    Last Post: 11-07-2012, 05:45 PM
  2. Grid help
    By lolmister in forum Java 2D
    Replies: 1
    Last Post: 05-24-2012, 06:35 AM
  3. Open Grid Scheduler/Grid Engine
    By java software in forum Java Software
    Replies: 0
    Last Post: 03-27-2012, 08:00 PM
  4. 2D grid
    By ranss41 in forum New To Java
    Replies: 0
    Last Post: 01-06-2012, 05:41 PM
  5. How can I square(^2) the pic in the grid
    By racewithferrari in forum New To Java
    Replies: 2
    Last Post: 11-03-2009, 06:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •