Microsoft Small Basic

Program Listing:
Embed this in your website
startover:
TextWindow.WriteLine("Enter your configuraion as a serial number from left of the board to the right of the board(The nth character of your serial number represents the row at which the nth queen is located): ")
config = TextWindow.Read()
length = Text.GetLength (config)

If length<>8 Then
  TextWindow.ForegroundColor = "red"
TextWindow.WriteLine("There are supposed to be 8 queens, but your serial number has "+length+ " characters")
TextWindow.ForegroundColor = "White"
Goto startover
EndIf

For i=1 To length
    t[i] = Text.GetSubText(config, i, 1)
  EndFor

  For i=1 To length
    t2[i] = t[i]
  EndFor

validity = "true"

For i=1 To length
 For j=1 To length
   If t[i] = t2[j] And i<>j Then
     TextWindow.ForegroundColor = "Red"
     TextWindow.WriteLine("THIS IS NOT A VALID CONFIGURATION. The "+i+"th and the " +j+ "th queens threaten each other horizontally")
     TextWindow.WriteLine("")

     validity = "false"
     TextWindow.ForegroundColor = "White"
     Goto end
   EndIf
  EndFor

EndFor




If validity<>"false" Then


For i=1 To length
 For j=1 To length
   If ((t[i] = t2[j] - (i-j)) Or (t[i] = t2[j] - (j-i))) And i<>j Then
     TextWindow.ForegroundColor = "Red"
     TextWindow.WriteLine("THIS IS NOT A VALID CONFIGURATION. The queen at the "+t[i]+"th row and "+i+"th column threatens the queen at the " +t2[j]+"th row and the "+j+"th column.")
     TextWindow.WriteLine("")

     validity = "false"
     TextWindow.ForegroundColor = "White"
     Goto end
   EndIf
  EndFor

EndFor


EndIf


end:
If validity =  "true" Then
  TextWindow.ForegroundColor = "Red"
  TextWindow.WriteLine("It is valid configuration. Congratulations!")
  TextWindow.WriteLine("")

TextWindow.ForegroundColor = "White"
EndIf

Goto startover



Copyright (c) Microsoft Corporation. All rights reserved.