Frame 1
maskpanel = attachMovie("board", "mask", this.getNextHighestDepth(), {_x:30, _y:30});
var board = new SudokuBoard();
board.paint(true, maskpanel, 4, 2, 27.7, 27.7);
maskpanel._visible = true;
Frame 2
maskpanel._visible = true;
stop();
Frame 3
board.showSolution();
stop();
Frame 4
maskpanel._visible = false;
stop();
Symbol 27 Button
on (release) {
this.gotoAndStop("4");
}
Symbol 29 Button
on (release) {
this.gotoAndStop("3");
}
Symbol 37 MovieClip [__Packages.SudokuBoard] Frame 0
class SudokuBoard
{
function SudokuBoard () {
var _local4 = new Square();
var _local3;
var _local2;
var _local5 = Square.getZeroSquare();
_local3 = 0;
while (_local3 < dimension) {
board[_local3] = new Array(dimension);
mask[_local3] = new Array(dimension);
_local2 = 0;
while (_local2 < dimension) {
mask[_local3][_local2] = _local5.clone();
board[_local3][_local2] = _local4.clone();
_local4.scrollUp();
_local2++;
}
_local4.scrollRight();
_local3++;
}
mask[0][0].board[0][1] = 1;
mask[0][0].board[0][2] = 1;
mask[0][0].board[1][0] = 1;
mask[0][1].board[1][0] = 1;
mask[0][1].board[1][1] = 1;
mask[0][1].board[2][2] = 1;
mask[0][2].board[1][1] = 1;
mask[0][2].board[2][0] = 1;
mask[0][2].board[2][2] = 1;
mask[1][0].board[0][0] = 1;
mask[1][0].board[0][1] = 1;
mask[1][0].board[2][1] = 1;
mask[1][1].board[0][1] = 1;
mask[1][1].board[1][1] = 1;
mask[1][1].board[2][0] = 1;
mask[1][1].board[2][2] = 1;
mask[1][2].board[1][1] = 1;
mask[1][2].board[2][1] = 1;
mask[2][0].board[1][1] = 1;
mask[2][0].board[2][0] = 1;
mask[2][0].board[2][1] = 1;
mask[2][1].board[0][1] = 1;
mask[2][1].board[0][2] = 1;
mask[2][1].board[2][2] = 1;
mask[2][2].board[0][1] = 1;
mask[2][2].board[1][0] = 1;
mask[2][2].board[2][1] = 1;
mask[2][2].board[2][2] = 1;
permuteInside();
if (Maths.lucky()) {
exchangeColumns(1, 0, 1);
}
if (Maths.lucky()) {
exchangeColumns(1, 1, 2);
}
if (Maths.lucky()) {
exchangeColumns(1, 0, 2);
}
if (Maths.lucky()) {
exchangeColumns(2, 0, 1);
}
if (Maths.lucky()) {
exchangeColumns(2, 1, 2);
}
if (Maths.lucky()) {
exchangeColumns(2, 0, 2);
}
if (Maths.lucky()) {
exchangeRows(1, 0, 1);
}
if (Maths.lucky()) {
exchangeRows(1, 1, 2);
}
if (Maths.lucky()) {
exchangeRows(1, 0, 2);
}
if (Maths.lucky()) {
exchangeRows(2, 0, 1);
}
if (Maths.lucky()) {
exchangeRows(2, 1, 2);
}
if (Maths.lucky()) {
exchangeRows(2, 0, 2);
}
if (Maths.lucky()) {
exchangeHBlock(0, 1);
}
if (Maths.lucky()) {
exchangeHBlock(0, 2);
}
if (Maths.lucky()) {
exchangeHBlock(1, 2);
}
if (Maths.lucky()) {
exchangeVBlock(0, 1);
}
if (Maths.lucky()) {
exchangeVBlock(0, 2);
}
if (Maths.lucky()) {
exchangeVBlock(1, 2);
}
}
function exchangeVBlock(origin, target) {
var _local3;
var _local2 = 0;
while (_local2 < dimension) {
_local3 = board[target][_local2];
board[target][_local2] = board[origin][_local2];
board[origin][_local2] = _local3;
_local3 = mask[target][_local2];
mask[target][_local2] = mask[origin][_local2];
mask[origin][_local2] = _local3;
_local2++;
}
}
function exchangeHBlock(origin, target) {
var _local3;
var _local2 = 0;
while (_local2 < dimension) {
_local3 = board[_local2][target];
board[_local2][target] = board[_local2][origin];
board[_local2][origin] = _local3;
_local3 = mask[_local2][target];
mask[_local2][target] = mask[_local2][origin];
mask[_local2][origin] = _local3;
_local2++;
}
}
function exchangeColumns(block, origin, target) {
var _local2 = 0;
while (_local2 < dimension) {
board[_local2][block].exchangeColumns(origin, target);
mask[_local2][block].exchangeColumns(origin, target);
_local2++;
}
}
function exchangeRows(block, origin, target) {
var _local2 = 0;
while (_local2 < dimension) {
board[block][_local2].exchangeRows(origin, target);
mask[block][_local2].exchangeRows(origin, target);
_local2++;
}
}
function permuteInside() {
var _local3 = 0;
while (_local3 < dimension) {
var _local4 = Square.getVerticalPermutation();
var _local2 = 0;
while (_local2 < dimension) {
board[_local3][_local2].transposeHorizontal(_local4);
_local2++;
}
_local3++;
}
_local3 = 0;
while (_local3 < dimension) {
var _local4 = Square.getHorizontalPermutation();
var _local2 = 0;
while (_local2 < dimension) {
board[_local2][_local3].transposeVertical(_local4);
_local2++;
}
_local3++;
}
}
function paint(maskFlag, panel, nx, ny, dx, dy) {
var _local10 = board[0][0].getDimension();
var _local3;
var _local2;
var my_fmt = new TextFormat();
my_fmt.color = 255;
my_fmt.size = 20;
my_fmt.font = "Arial";
var my_fmt2 = new TextFormat();
my_fmt2.color = 255;
my_fmt2.size = 10;
my_fmt2.font = "Arial";
var my_fmt3 = new TextFormat();
my_fmt3.color = 255;
my_fmt3.size = 7;
my_fmt3.font = "Arial";
_local3 = 0;
while (_local3 < (dimension * _local10)) {
textFields[_local3] = new Array(dimension);
_local2 = 0;
while (_local2 < (dimension * _local10)) {
if (maskFlag && (getValue(_local3, _local2, true) == 0)) {
textFields[_local3][_local2] = panel.createTextField("t" + getValue(_local3, _local2), panel.getNextHighestDepth(), (nx + (_local2 * dx)) + 1, (ny + (_local3 * dy)) - 1, dx - 2, dy - 2);
textFields[_local3][_local2].maxChars = 3;
textFields[_local3][_local2].setNewTextFormat(my_fmt);
textFields[_local3][_local2].type = "input";
textFields[_local3][_local2].autoSize = true;
textFields[_local3][_local2].onChanged = function (textfield_txt) {
if (textfield_txt.length < 2) {
textfield_txt.setTextFormat(my_fmt);
textfield_txt.setNewTextFormat(my_fmt);
} else if (textfield_txt.length < 3) {
textfield_txt.setTextFormat(my_fmt2);
textfield_txt.setNewTextFormat(my_fmt2);
} else {
textfield_txt.setTextFormat(my_fmt3);
textfield_txt.setNewTextFormat(my_fmt3);
}
};
} else {
var _local4 = panel.attachMovie("d" + getValue(_local3, _local2), (("d" + _local3) + "-") + _local2, panel.getNextHighestDepth());
_local4._x = nx + (_local2 * dx);
_local4._y = ny + (_local3 * dy);
}
_local2++;
}
_local3++;
}
}
function showSolution() {
var _local6 = board[0][0].getDimension();
var _local7 = new TextFormat();
_local7.color = 16711680 /* 0xFF0000 */;
_local7.size = 20;
_local7.font = "Arial";
var _local3 = 0;
while (_local3 < (dimension * _local6)) {
var _local2 = 0;
while (_local2 < (dimension * _local6)) {
var _local5 = getValue(_local3, _local2, true);
var _local4 = getValue(_local3, _local2, false);
if ((_local5 == 0) && (textFields[_local3][_local2].text != _local4)) {
textFields[_local3][_local2].setNewTextFormat(_local7);
textFields[_local3][_local2].text = _local4;
}
_local2++;
}
_local3++;
}
}
function getValue(i, j, maskFlag) {
var _local2 = 0;
if (!(maskFlag && (mask[Math.floor(i / dimension)][Math.floor(j / dimension)].getValue(i % dimension, j % dimension) == 0))) {
var _local5 = board[Math.floor(i / dimension)][Math.floor(j / dimension)];
_local2 = _local5.getValue(i % dimension, j % dimension);
}
return(_local2);
}
var dimension = 3;
var board = new Array(SudokuBoard.prototype.dimension);
var mask = new Array(SudokuBoard.prototype.dimension);
var textFields = new Array(SudokuBoard.prototype.dimension);
}
Symbol 38 MovieClip [__Packages.Square] Frame 0
class Square
{
var board;
function Square () {
board = new Array(dimension);
var _local2;
var _local3;
var _local4 = 0;
var _local5 = new Array();
_local2 = 0;
while (_local2 < (dimension * dimension)) {
_local5[_local2] = _local2 + 1;
_local2++;
}
_local5 = Maths.getPermutation(_local5, true);
_local2 = 0;
while (_local2 < dimension) {
board[_local2] = new Array(dimension);
_local3 = 0;
while (_local3 < dimension) {
board[_local2][_local3] = _local5[_local4];
_local4++;
_local3++;
}
_local2++;
}
}
static function getZeroSquare() {
var _local3 = new Square();
var _local2;
var _local1;
_local2 = 0;
while (_local2 < dimension) {
_local1 = 0;
while (_local1 < dimension) {
_local3.board[_local2][_local1] = 0;
_local1++;
}
_local2++;
}
return(_local3);
}
static function getVerticalPermutation() {
var _local1 = getZeroSquare();
_local1.board[0][0] = 1;
_local1.board[1][0] = 1;
_local1.board[1][2] = 1;
_local1.board[2][2] = 1;
return(_local1);
}
static function getHorizontalPermutation() {
var _local1 = getZeroSquare();
_local1.board[0][1] = 1;
_local1.board[0][2] = 1;
_local1.board[2][0] = 1;
_local1.board[2][1] = 1;
return(_local1);
}
function transposeVertical(mask) {
var _local5 = -1;
var _local4 = -1;
var _local3 = 0;
while (_local3 < dimension) {
_local5 = -1;
_local4 = -1;
var _local2 = 0;
while (_local2 < dimension) {
if (mask.board[_local3][_local2] > 0) {
if (_local4 < 0) {
_local5 = board[_local3][_local2];
_local4 = _local2;
} else {
board[_local3][_local4] = board[_local3][_local2];
board[_local3][_local2] = _local5;
}
}
_local2++;
}
_local3++;
}
}
function transposeHorizontal(mask) {
var _local5 = -1;
var _local4 = -1;
var _local3 = 0;
while (_local3 < dimension) {
_local4 = -1;
_local5 = -1;
var _local2 = 0;
while (_local2 < dimension) {
if (mask.board[_local2][_local3] > 0) {
if (_local4 < 0) {
_local5 = board[_local2][_local3];
_local4 = _local2;
} else {
board[_local4][_local3] = board[_local2][_local3];
board[_local2][_local3] = _local5;
_local4 = -1;
}
}
_local2++;
}
_local3++;
}
}
function clone() {
var _local4 = new Square();
var _local3;
var _local2;
_local3 = 0;
while (_local3 < dimension) {
_local4.board[_local3] = new Array(dimension);
_local2 = 0;
while (_local2 < dimension) {
_local4.board[_local3][_local2] = board[_local3][_local2];
_local2++;
}
_local3++;
}
return(_local4);
}
function getDimension() {
return(dimension);
}
function getValue(i, j) {
var _local2 = 0;
if ((((i < dimension) && (i >= 0)) && (j < dimension)) && (j >= 0)) {
_local2 = board[i][j];
}
return(_local2);
}
function exchangeRows(origin, target) {
var _local3;
var _local2 = 0;
while (_local2 < dimension) {
_local3 = board[target][_local2];
board[target][_local2] = board[origin][_local2];
board[origin][_local2] = _local3;
_local2++;
}
}
function exchangeColumns(origin, target) {
var _local3;
var _local2 = 0;
while (_local2 < dimension) {
_local3 = board[_local2][target];
board[_local2][target] = board[_local2][origin];
board[_local2][origin] = _local3;
_local2++;
}
}
function scrollUp() {
var _local2 = 0;
while (_local2 < (dimension - 1)) {
exchangeRows(_local2, (_local2 + 1) % dimension);
_local2++;
}
}
function scrollRight() {
exchangeColumns(0, dimension - 1);
var _local2 = dimension - 1;
while (_local2 > 1) {
exchangeColumns(_local2, _local2 - 1);
_local2--;
}
}
function scrollLeft() {
var _local2 = 0;
while (_local2 < (dimension - 1)) {
exchangeColumns(_local2, (_local2 + 1) % dimension);
_local2++;
}
}
static var dimension = 3;
}
Symbol 39 MovieClip [__Packages.Maths] Frame 0
class Maths
{
function Maths () {
}
static function randRange(min, max) {
var _local1 = Math.floor(Math.random() * ((max - min) + 1)) + min;
return(_local1);
}
static function lucky() {
return(randRange(0, 1) == 1);
}
static function getPermutation(inset, trivialOK) {
var _local4 = inset.length;
var _local5 = new Array(_local4);
var _local7 = new Array(_local4);
var _local8 = true;
var _local2 = 0;
while (_local2 < _local4) {
_local5[_local2] = inset[_local2];
_local2++;
}
_local2 = 0;
while (_local2 < _local4) {
var _local3 = randRange(0, (_local4 - _local2) - 1);
var _local1 = 0;
while ((_local1 <= _local4) && (_local3 >= 0)) {
if (_local5[_local1] > 0) {
_local3--;
}
_local1++;
}
if (_local2 != (_local1 - 1)) {
_local8 = false;
}
_local7[_local2] = inset[_local1 - 1];
_local5[_local1 - 1] = -1;
_local2++;
}
if (_local8 && (!trivialOK)) {
_local7 = getPermutation(inset, false);
}
return(_local7);
}
static function scrollRight(inset) {
var _local2 = inset.length;
var _local3 = new Array(_local2);
var _local1 = 1;
while (_local1 < _local2) {
_local3[_local1] = inset[_local1 - 1];
_local1++;
}
_local3[0] = inset[_local2 - 1];
return(_local3);
}
}
Symbol 32 Button
on (release) {
removeMovieClip(boardpanel);
removeMovieClip(maskpanel);
this.clear();
this.gotoAndStop("1");
}
Symbol 35 Button
on (release) {
this.gotoAndStop("2");
}