Anonymous user
Sudoku: Difference between revisions
m
→{{header|AutoHotkey}}: Fixed iterations, added readable indentation, minor display adjustments & bugfixes
m (→{{header|AutoHotkey}}: Fixed iterations, added readable indentation, minor display adjustments & bugfixes) |
|||
Line 4:
=={{header|AutoHotkey}}==
<lang AutoHotkey>#SingleInstance,
SetBatchLines, -1
SetTitleMatchMode, 3
Loop 9 {
r := A_Index, y := r*17-8 + (A_Index >= 7 ? 4 : A_Index >= 4 ? 2 : 0)
Loop 9 {▼
c := A_Index, x := c*17+5 + (A_Index >= 7 ? 4 : A_Index >= 4 ? 2 : 0)
Gui, Add, Edit, x%x% y%y% w17 h17 v%r%_%c% Center Number Limit1 gNext
}▼
}
▲ }
Gui, Add,
Gui,
Gui, Show,, Sudoku Solver
Return
Solve:
Gui, Submit, NoHide
Loop 9
r := A_Index
Loop 9
If (%r%_%A_Index% = "")
puzzle .= "@"
Else
puzzle .= %r%_%A_Index%
s := A_TickCount
answer := Sudoku(puzzle)
iterations := ErrorLevel
e := A_TickCount
seconds := (e-s)/1000
StringSplit, a, answer, |
r := A_Index
▲ Loop 9
b := (r*9)+A_Index-9
GuiControl,, %r%%A_Index%, % a%b%▼
GuiControl,
▲ }
}
}
GuiControl,, Msg, Solved! Time: %seconds%▼
if answer
GuiControl,, Button, Close▼
GuiControl, +gClose, Button▼
else
GuiControl,, Msg, Failed! :(`nTime: %seconds%s`nIterations: %iterations%
return
GuiClose:
ExitApp▼
▲ExitApp
Again:
Reload
#IfWinActive, Sudoku Solver
~*Enter::GoSub % GetKeyState( "Shift", "P" ) ? "~Up" : "~Down"
~Up::
GuiControlGet, f, focus
StringTrimLeft, f, f, 4
f := ((f >= 1 && f <= 9) ? f+72 : f-9)
GuiControl, Focus, Edit%f%
return
~Down::
GuiControlGet, f, focus
StringTrimLeft, f, f, 4
f := ((f >= 73 && f <= 81) ? f-72 : f + 9)
GuiControl, Focus, Edit%f%
return
~Left::
GuiControlGet, f, focus
StringTrimLeft, f, f, 4
f := Mod(f + 79, 81) + 1▼
GuiControl, Focus, Edit%f%▼
▲GuiControl, Focus, Edit%f%
return
Next:
~Right::
GuiControlGet, f, focus
StringTrimLeft, f, f, 4
GuiControl, Focus, Edit%f%▼
▲f := Mod(f, 81)
▲GuiControl, Focus, Edit%f%
return
#IfWinActive
; Functions Start here
Sudoku( p ) { ;ErrorLevel contains the number of iterations
}
Line 103 ⟶ 107:
; returns: 81 char string with non-givens replaced with valid solution
;
}
Sudoku_Constraints( ByRef p, d ) {
; returns a string of the constraints for a particular position
}
Sudoku_Display( p ) {
}</lang>
|