写一个传统的方法
Global $count = 0
Global $map[9]
Local $output
local $time=TimerInit()
solution(0, 0, 0)
MsgBox(0,TimerDiff($time),$output &@CRLF&$count)
Func solution($big, $small, $level)
$count += 1
If ($small * 4 > $big Or ($small + 3) * 4 < $big) Then Return 0
If $level == 4 Then
If $small * 4 == $big Then
$output &= $big &" ======> "&$small&@CRLF
EndIf
Return 0
EndIf
Local $i = 0, $j = 0
For $i = 2 To 8
If $level = 0 Then
If $i < 4 Then ContinueLoop
$map[$i] = 1
solution($i, 1, $level + 1)
$map[$i] = 0
Else
For $j = 2 To 8
If $map[$i] = 0 And $map[$j] = 0 And $i <> $j Then
$map[$i] = 1
$map[$j] = 1
solution($big * 10 + $i, $small * 10 + $j, $level + 1)
$map[$i] = 0
$map[$j] = 0
EndIf
Next
EndIf
Next
Return 0
EndFunc
|