Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,59 +0,0 @@
|
|||
function PlaceQueen ( [ref]$Board, $Row, $N )
|
||||
{
|
||||
# For the current row, start with the first column
|
||||
$Board.Value[$Row] = 0
|
||||
|
||||
# While haven't exhausted all columns in the current row...
|
||||
While ( $Board.Value[$Row] -lt $N )
|
||||
{
|
||||
# If not the first row, check for conflicts
|
||||
$Conflict = $Row -and
|
||||
( (0..($Row-1)).Where{ $Board.Value[$_] -eq $Board.Value[$Row] }.Count -or
|
||||
(0..($Row-1)).Where{ $Board.Value[$_] -eq $Board.Value[$Row] - $Row + $_ }.Count -or
|
||||
(0..($Row-1)).Where{ $Board.Value[$_] -eq $Board.Value[$Row] + $Row - $_ }.Count )
|
||||
|
||||
# If no conflicts and the current column is a valid column...
|
||||
If ( -not $Conflict -and $Board.Value[$Row] -lt $N )
|
||||
{
|
||||
|
||||
# If this is the last row
|
||||
# Board completed successfully
|
||||
If ( $Row -eq ( $N - 1 ) )
|
||||
{
|
||||
return $True
|
||||
}
|
||||
|
||||
# Recurse
|
||||
# If all nested recursions were successful
|
||||
# Board completed successfully
|
||||
If ( PlaceQueen $Board ( $Row + 1 ) $N )
|
||||
{
|
||||
return $True
|
||||
}
|
||||
}
|
||||
|
||||
# Try the next column
|
||||
$Board.Value[$Row]++
|
||||
}
|
||||
|
||||
# Everything was tried, nothing worked
|
||||
Return $False
|
||||
}
|
||||
|
||||
function Get-NQueensBoard ( $N )
|
||||
{
|
||||
# Start with a default board (array of column positions for each row)
|
||||
$Board = @( 0 ) * $N
|
||||
|
||||
# Place queens on board
|
||||
# If successful...
|
||||
If ( PlaceQueen -Board ([ref]$Board) -Row 0 -N $N )
|
||||
{
|
||||
# Convert board to strings for display
|
||||
$Board | ForEach { ( @( "" ) + @(" ") * $_ + "Q" + @(" ") * ( $N - $_ ) ) -join "|" }
|
||||
}
|
||||
Else
|
||||
{
|
||||
"There is no solution for N = $N"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
Get-NQueensBoard 8
|
||||
''
|
||||
Get-NQueensBoard 3
|
||||
''
|
||||
Get-NQueensBoard 4
|
||||
''
|
||||
Get-NQueensBoard 14
|
||||
Loading…
Add table
Add a link
Reference in a new issue