Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 889617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:35:45+00:00 2026-05-15T13:35:45+00:00

mBlocks is a 2-dimensional array of Block objects. Every time my application runs, it

  • 0

mBlocks is a 2-dimensional array of Block objects. Every time my application runs, it runs the InitGridNumbers function. Sometimes, it will get stuck in an infinite loop. Other times, it builds and runs without issues.

  public function InitGridNumbers():void
  {
   var tempRow:Array;
   var tempColumn:Array;
   var tempNum:int;
   for (var i:int = 0; i < mNumRows; i++)
   {
    tempRow = GetRow(i);
    for (var j:int = 0; j < mNumColumns; j++)
    {
     // if number is unassigned
     if (tempRow[j] == 0)
     {
      var cantMoveOn:Boolean = true;
      while (cantMoveOn)
      {
       tempNum = Math.random() * mNumColumns + 1;
       if (!CheckRow(i, tempNum) && !CheckColumn(j, tempNum))
        cantMoveOn = false;
      }
      mBlocks[i][j].SetNumber(tempNum);     
     }
    }
   }
  } 

  public function CheckRow(rowNum:int, checkNum:int):Boolean
  {
   var tempRow:Array = GetRow(rowNum);
   for (var i:int = 0; i < mNumColumns; i++)
   {
    if (checkNum == tempRow[i])
     return true;
   }
   return false;
  }

  public function CheckColumn(columnNum:int, checkNum:int):Boolean
  {
   var tempColumn:Array = GetColumn(columnNum);
   for (var i:int = 0; i < mNumColumns; i++)
   {
    if (checkNum == tempColumn[i])
     return true;
   }
   return false;
  }

  public function GetRow(rowNum:int):Array
  {
   var rowArray:Array = new Array(mNumRows);
   for (var i:int = 0; i < mNumRows; i++)
    rowArray[i] = mBlocks[rowNum][i].mNumber;

   return rowArray;
  }

  public function GetColumn(columnNum:int):Array
  {
   var columnArray:Array = new Array(mNumColumns);
   for (var i:int = 0; i < mNumColumns; i++)
    columnArray[i] = mBlocks[i][columnNum].mNumber;
   return columnArray;
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:35:46+00:00Added an answer on May 15, 2026 at 1:35 pm

    To begin with, checkColumn, getColumn and getRow methods are wrong. To get a row, you should copy numColumns items and to get a column, you should copy numRows items. In other words, if there are r rows and c columns, there would be c items per each row and r items per each column.

    public function checkColumn(columnNum:int, checkNum:int):Boolean
    {
      var tempColumn:Array = getColumn(columnNum);
      for (var i:int = 0; i < mNumRows; i++)
      {
        if (checkNum == tempColumn[i])
          return true;
      }
      return false;
    }
    
    public function getRow(rowNum:int):Array
    {
      var rowArray:Array = new Array();//needn't specify length in advance.
      for (var i:int = 0; i < mNumColumns; i++)
        rowArray[i] = mBlocks[rowNum][i].mNumber;
    
      return rowArray;
    }
    public function getColumn(columnNum:int):Array
    {
      var columnArray:Array = new Array();
      for (var i:int = 0; i < mNumRows; i++)
        columnArray[i] = mBlocks[i][columnNum].mNumber;
      return columnArray;
    }
    

    while (cantMoveOn)
    {
      //call Math.floor
      tempNum = Math.floor(Math.random() * mNumColumns) + 1;
      if (!checkRow(i, tempNum) && !checkColumn(j, tempNum))
        cantMoveOn = false;
    }
    

    It looks like you’re checking for a number that is not present in the current row and column. It’s hard to say without knowing more details, but can you think of a scenario where this would be impossible?

    For example, if there are four columns and five rows, the tempNum would always be between one and four. Now if the number of rows is five and the corresponding column already has all numbers up to four, the if statement would never evaluate to true and hence you’d end up in an infinite loop

    0 1 2 3
    1
    2
    3
    4
    

    in case grid is a square, how about this:

    0 1 2 3
    4
    0
    0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using .get(0) to grab the actual element to be… May 15, 2026 at 3:10 pm
  • Editorial Team
    Editorial Team added an answer To start, the following exception com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure can… May 15, 2026 at 3:10 pm
  • Editorial Team
    Editorial Team added an answer By default gitk does the same thing as the --cc… May 15, 2026 at 3:10 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.