Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,56 @@
' version 13-04-2017
' compile with: fbc -s console
Dim Shared As ULong count, c()
Sub n_queens(row As ULong, n As ULong, show As ULong = 0)
Dim As ULong x, y
For x = 1 To n
For y = 1 To row -1
If c(y) = x OrElse ((row - y) - Abs(x - c(y))) = 0 Then
Continue For, For
End If
Next
c(row) = x
If row < n Then
n_queens(row +1 , n, show)
Else
count += 1
If show <> 0 Then
For y = 1 To n
Print Using "###"; c(y);
Next
Print
End If
End If
Next
End Sub
' ------=< MAIN >=------
Dim As ULong n = 5
ReDim c(n)
' n_queens(1, n, show = 0 only show total | show <> 0 show every solution
n_queens(1, n, 1)
Print Using "## x ## board, ##### solutions"; n; n; count
Print
For n = 1 To 14
ReDim c(n)
count = 0
n_queens(1, n)
Print Using "A ## x ## board has ######## solutions"; n; n; count
Next
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End

View file

@ -0,0 +1,41 @@
Sub aux(n As Integer, i As Integer, a() As Integer, _
u() As Integer, v() As Integer, ByRef m As LongInt)
Dim As Integer j, k, p, q
If i > n Then
m += 1
For k = 1 To n : Print a(k); : Next : Print
Else
For j = i To n
k = a(j)
p = i - k + n
q = i + k - 1
If u(p) And v(q) Then
u(p) = 0 : v(q) = 0
a(j) = a(i) : a(i) = k
aux(n, i + 1, a(), u(), v(), m)
u(p) = 1 : v(q) = 1
a(i) = a(j) : a(j) = k
End If
Next
End If
End Sub
Dim As Integer n, i
Dim m As LongInt = 1
If Command(1) <> "" Then
n = CInt(Command(1))
ReDim a(1 To n) As Integer
ReDim u(1 To 2 * n - 1) As Integer
ReDim v(1 To 2 * n - 1) As Integer
For i = 1 To n
a(i) = i
Next
For i = 1 To 2 * n - 1
u(i) = 1
v(i) = 1
Next
m = 0
aux(n, 1, a(), u(), v(), m)
Print m
End If

View file

@ -0,0 +1,43 @@
Dim As Integer n, i, j, k, p, q
Dim m As LongInt = 0
If Command(1) <> "" Then
n = CInt(Command(1))
ReDim a(1 To n) As Integer
ReDim s(1 To n) As Integer
ReDim u(1 To 2 * n - 1) As Integer
ReDim v(1 To 2 * n - 1) As Integer
For i = 1 To n
a(i) = i
Next
For i = 1 To 2 * n - 1
u(i) = 1
v(i) = 1
Next
m = 0
i = 1
L1: If i > n Then
m += 1
For k = 1 To n : Print a(k); : Next : Print
Goto L4
End If
j = i
L2: k = a(j)
p = i - k + n
q = i + k - 1
If u(p) And v(q) Then
u(p) = 0 : v(q) = 0
a(j) = a(i) : a(i) = k
s(i) = j
i += 1
Goto L1
End If
L3: j += 1 : If j <= n Goto L2
L4: i -= 1 : If i = 0 Then Print m : End
j = s(i)
k = a(i) : a(i) = a(j) : a(j) = k
p = i - k + n
q = i + k - 1
u(p) = 1 : v(q) = 1
Goto L3
End If