Click here to Skip to main content
15,887,477 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: input Pin
Richard MacCutchan21-Jan-12 2:34
mveRichard MacCutchan21-Jan-12 2:34 
AnswerRe: input Pin
BillWoodruff29-Jan-12 13:08
professionalBillWoodruff29-Jan-12 13:08 
QuestionnQueens algorithm Pin
PIEBALDconsult31-Dec-11 4:02
mvePIEBALDconsult31-Dec-11 4:02 
AnswerRe: nQueens algorithm Pin
DaveAuld31-Dec-11 4:49
professionalDaveAuld31-Dec-11 4:49 
GeneralRe: nQueens algorithm Pin
PIEBALDconsult31-Dec-11 15:08
mvePIEBALDconsult31-Dec-11 15:08 
GeneralRe: nQueens algorithm Pin
Member 41945931-Jan-12 13:20
Member 41945931-Jan-12 13:20 
GeneralRe: nQueens algorithm Pin
PIEBALDconsult1-Jan-12 16:14
mvePIEBALDconsult1-Jan-12 16:14 
GeneralRe: nQueens algorithm Pin
PIEBALDconsult9-Jan-12 13:15
mvePIEBALDconsult9-Jan-12 13:15 
The book arrove today. My code is very much like the code they show on page 338 with two main differences:

0) They have the test in a separate function and therefore a global array.
(Which also has a needless call to ABS.)

1) They have an extra while loop.


public static System.Collections.Generic.IEnumerable<System.Collections.Generic.IList<int>>
nQueens
(
  int HowMany
)
{
  int[] board = new int [ HowMany ] ;
  int   row   = 0 ;

  board [ row ] = -1 ;

  while ( row >= 0 )
  {
    board [ row ]++ ;

    if ( board [ row ] == HowMany )
    {
      row-- ;
    }
    else
    {
      int i ;

      for ( i = 0 ; i < row ; i++ )
      {
        int diff = board [ row ] - board [ i ] ;

        if ( ( diff == 0 ) || ( System.Math.Abs ( diff ) == ( row - i ) ) )
        {
          break ;
        }
      }

      if ( i == row )
      {
        row++ ;

        if ( row == HowMany )
        {
          yield return ( System.Array.AsReadOnly ( board ) ) ;

          row-- ;
        }
        else
        {
          board [ row ] = -1 ;
        }
      }
    }
  }

  yield break ;
}

GeneralRe: nQueens algorithm Pin
Member 419459311-Jan-12 8:25
Member 419459311-Jan-12 8:25 
GeneralRe: nQueens algorithm Pin
PIEBALDconsult11-Jan-12 9:35
mvePIEBALDconsult11-Jan-12 9:35 
GeneralRe: nQueens algorithm Pin
Member 419459311-Jan-12 10:01
Member 419459311-Jan-12 10:01 
GeneralRe: nQueens algorithm Pin
PIEBALDconsult11-Jan-12 10:22
mvePIEBALDconsult11-Jan-12 10:22 
GeneralRe: nQueens algorithm Pin
Member 419459311-Jan-12 10:42
Member 419459311-Jan-12 10:42 
GeneralRe: nQueens algorithm Pin
PIEBALDconsult11-Jan-12 11:16
mvePIEBALDconsult11-Jan-12 11:16 
QuestionTuring Machine Simulator witch greedy algorithm Pin
nasser moradbeiki27-Dec-11 2:59
nasser moradbeiki27-Dec-11 2:59 
AnswerRe: Turing Machine Simulator witch greedy algorithm Pin
Richard MacCutchan27-Dec-11 4:49
mveRichard MacCutchan27-Dec-11 4:49 
AnswerRe: Turing Machine Simulator witch greedy algorithm Pin
PIEBALDconsult30-Dec-11 8:33
mvePIEBALDconsult30-Dec-11 8:33 
QuestionIs "Day.Month DayOfWeek" an Unique Date Time? Pin
Henning Dieterichs22-Dec-11 12:02
Henning Dieterichs22-Dec-11 12:02 
AnswerRe: Is "Day.Month DayOfWeek" an Unique Date Time? Pin
Luc Pattyn22-Dec-11 12:18
sitebuilderLuc Pattyn22-Dec-11 12:18 
GeneralA more effective way to find the number of points with a given distance between them on a line? Pin
Erik Rude19-Dec-11 22:32
Erik Rude19-Dec-11 22:32 
GeneralRe: A more effective way to find the number of points with a given distance between them on a line? Pin
Richard Andrew x6420-Dec-11 6:49
professionalRichard Andrew x6420-Dec-11 6:49 
GeneralRe: A more effective way to find the number of points with a given distance between them on a line? Pin
IdUnknown21-Dec-11 6:39
IdUnknown21-Dec-11 6:39 
AnswerRe: A more effective way to find the number of points with a given distance between them on a line? Pin
Luc Pattyn21-Dec-11 8:23
sitebuilderLuc Pattyn21-Dec-11 8:23 
GeneralWholesale Sources Pin
Andrew Dudley16-Dec-11 19:46
Andrew Dudley16-Dec-11 19:46 
NewsDiscover How FX Brokers Can Earn On Forex Trading Pin
forex platform30-Nov-11 21:09
forex platform30-Nov-11 21:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.