I have 2 variables x and y ,and they have to increment by 1, the tow variables start in 1, first x has to increment by 1,, until it reaches 25 and y stay at 1. Once it reaches 25, x has to go back to 1 and y increment to y=2, and the repeat (once x has reached 25 again y will increment by 1). here my implementation but isn't working...
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
int x;
int y = 1;
for (x = 1; x < 26; x++)
{
if (x == 25)
{
x = 1;
for (y = 1; y < 30; y++)
{
Console.WriteLine("X = " + x + ", Y = " + y);
}
}
}
}
}
}
It's not standard practice to manipulate x in a for loop. I assume you only want both variables going to 25 (edit: y now goes to 30 like in OP). So the trick is to put y on the outside and x on the inside.
In this case it's easiest to still use for loops instead of while loops.
Try something like this:
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
for(int y = 0; y < 30; y++) //y goes up 1 every time x goes up 25
{
for(int x = 0; x < 25; x++) //counts x to 25
{
Console.WriteLine("X=" + x + " Y=" + y);
}
}
}
}
}
You can use a little bit of recursivity for that too (just adding this for more infos ).
public static void run25(ref int x, ref int y)
{
if(x <= 25)
{
Console.WriteLine($"x = {x}");
x++;
run25(ref x, ref y);
}
if (y <= 25)
{
Console.WriteLine($" >> y = {y}");
y++;
x = 1;
run25(ref x, ref y);
}
else return ;
}
you can use that as follow :
public static void Main (string[] args)
{
int _x = 1;
int _y = 1;
run25(ref _x, ref _y); // once it's done , _x and _y values are 26 .
}
using System;
public class Program
{
public static void Main()
{
for(var y = 1; y <=30 ;y++)
{
for(var x = 1; x<=25;x++)
{
Console.WriteLine("x = {0}, y = {1}", x, y);
}
}
}
}
Related
I have this "Game" class that gets instantiated at Start and sets up the field for Minesweeper and in this process I count the adjacent Mines for each field.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Game
{
public int Width;
public int Height;
public int NumOfMines;
public Field[,] Board;
public Game(int width = 8, int height = 8, int numOfMines = 10)
{
this.Width = width;
this.Height = height;
this.NumOfMines = numOfMines;
Board = new Field[height, width];
InitializeBoard();
}
public void InitializeBoard()
{
for (int row = 0; row < Height; row++)
{
for (int column = 0; column < Width; column++)
{
Board[row, column] = new Field();
}
}
// Board.Initialize();
// foreach (var field in Board)
// {
// field.IsMine = false;
// }
var rnd = new System.Random();
for (int i = 0; i < NumOfMines; i++)
{
int mineRow = 0;
int mineColumn = 0;
do
{
mineRow = rnd.Next(Height);
mineColumn = rnd.Next(Width);
} while (Board[mineRow, mineColumn].IsMine);
Board[mineRow, mineColumn].IsMine = true;
Board[mineRow, mineColumn].NumOfAdjacentMines = null;
}
for (int row = 0; row < Height; row++)
{
for (int column = 0; column < Width; column++)
{
if (!Board[column, row].IsMine)
Board[row, column].NumOfAdjacentMines = CountAdjacentMines(new Vector2Int(column, row));
}
}
}
private int CountAdjacentMines(Vector2Int pos)
{
Debug.Log(pos);
int counter = 0;
for (int y = pos.y - 1; y <= pos.y + 1; y++)
{
for (int x = pos.x - 1; y <= pos.x + 1; x++)
{
try
{
Debug.Log($"Checking {x + ":" + y} for a mine");
if (Board[x, y].IsMine)
{
counter++;
}
}
catch (Exception ex)
{
Debug.LogError(ex + ", Pos: " + x + ":" + y);
continue;
}
}
}
return counter;
}
}
Why does Unity freeze without any notes? If I throw the exception, unity reacts normally.
(I have to write this so StackOverflow let's me post this...)
Look at the inner for loop iterating the x variable. Look closely. What is the actual condition that will end/conclude this inner for loop? Look very closely.
Basic answer to your question: Your program freezes, because the inner for loop iterating the x variable is an infinite loop that will never end. It's not Unity that freezes, it's your code getting stuck in this infinite loop. Like a hamster running in his wheel, forever...
(Re)throwing the exception will force this loop to exit, hence no freeze (because, simplified speaking, throwing the exception will abort execution of the CountAdjacentMines method).
I Write this code in c# , i use list of structure , but how can i add to list with structure,i use add to add xx,yy,size but not correct ? i need only method for add data to list of structure
public struct blocks
{
public Int32 xx;
public Int32 yy;
public Int32 size;
};
namespace test2
{
class Program
{
static List<blocks> blocks1 = new List<blocks>();
static void Main(string[] args)
{
Int32 index=0;
for (int y = 1; y < 5; y++)
for (int x = 1; x < 5; x++)
{
blocks1[index].xx +=( x * 2); // store start point (x) of block
blocks1[index].yy += (y *2); // store start point (y) of block
blocks1[index].size +=( 2); // store block size
index++;
}
}
}
}
I would use a List<blocks> blocks1 = new List<blocks>() since that is a data structure that you can just add to as needed.
You can add to it like so:
blocks newBlock = new blocks();
blocks1.Add(newBlock) ;
This is probably what you are trying to achieve but not very sure. If this is not what you need then please update your question with the information as per my comment
public struct blocks
{
public Int32 xb;
public Int32 yb;
public Int32 size;
};
namespace test
{
class Program
{
static List<blocks> blocks1;
static void Main(string[] args)
{
blocks1 = new List<blocks>();
for (int y = 1; y < 5; y++)
{
for (int x = 1; x < 5; x++)
{
blocks newBlock = new blocks();
newBlock.xb = x * 2;
newBlock.yb = y * 2;
newBlock.size = 2;
blocks1.Add(newBlock);
}
}
}
}
}
Hope this helps.
I've got the following loop:
public int multiply(int Z)
{
//Z=5
for (int i = 1; i <= Z; i++)
{
int Y=Z*i;
return Y;
//i wanna Y multiply x*4*3*2*1 all loops in one result
}
return Z;
}
What I'd like to know how to do is:
Create a new multiply int Y =Z*4*3*2*1
Result of multiply would be In Console Write Line:
("value for your loop is " +test.multiply(5));
value for your loop is 120
Can this be done by a for loop or am I wrong?
This is called factorial:
public int Factorial(int num)
{
int factorial = 1;
for (int i = 2; i <= num; i++)
{
factorial *= i;
}
return factorial;
}
Demo
You can also get factorial recursively (this is basic exercise):
public int Factorial(int num)
{
if (num <= 1)
return 1;
return num * Factorial(num - 1);
}
Demo
What I think you actually mean is that you want to calculate the factorial of Z.
public int Factorial(int Z)
{
if (Z < 0) then return 0;
int res = 1;
for (int Y = 1; Y <= Z; Y++)
{
res *= Y;
}
return res;
}
Yes:
public int multiply(int Z)
{
int Y = Z;
for (int i = Z; i > 0; i--)
{
Y *= i;
}
return Y;
}
Factorial using lambdas:
Func<int, int> factorial = null;
factorial = x => x <= 1 ? 1 : x * factorial(x-1);
var result = factorial(10);
:-)
public int multiply(int Z)
{
int result = Z;
for (int i = 1; i <= Z; i++)
{
int Z*=i;
}
return Z;
}
I have a jagged array that represents a Grid and each item of array is a Cell. The Grid have 2600 rows and 2600 columns. I need to calculate a coordinate of each Cell, create instance of Cell object and add it into array. Now the code I'm using takes about 3200-3800 ms on my computer. Is there any way to make it faster?
public GridCell[][] Cells;
private void CreateCells(int cellWidth, int cellHeight, int startX, int startY)
{
Cells = new GridCell[RowsCount][];
for (int i = 0; i < RowsCount; i++)
{
Cells[i] = new GridCell[ColumnsCount];
for (int j = 0; j < ColumnsCount; j++)
{
Point coordinate = new Point(startX + cellWidth * j, startY + cellHeight * i);
Cells[i][j] = new GridCell(cellWidth, cellHeight, coordinate);
}
}
}
Considering you are working with 6760000 objects, you have a fine performance. And the main time is probably spent constructing new objects on heap. So using structures instead of class gives you a boost, as you have observed.
If you have large CPU cache you can also try to use single array like:
public GridCell[] Cells = new GridCell[RowsCount * ColumnsCount];
with addressing, like:
Cells[i * ColumnsCount + j] = x;
Consider using Parallel.For - something like this is trivial to multithread.
As shown, while bigger initial gains can be found elsewhere if you're willing to change functionality (in this case by using structs, but allocating single array might also have some benefit) threading can still be used to increase performance.
Some simple tests:
//Single Threaded : 1701, 1825, 1495, 1606
//Multi Threaded : 1516, 1446, 1581, 1401
//Struct Single Threaded : 154, 157, 153, 151
//Struct MultiThreaded : 104, 107, 106, 103
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Benchmark("Single Threaded", () => CreateCells(1, 1, 0, 0));
Benchmark("Multi Threaded", () => CreateCellsThreaded(1, 1, 0, 0));
Benchmark("Struct Single Threaded", () => CreateStructCells(1, 1, 0, 0));
Benchmark("Struct MultiThreaded", () => CreateStructCellsThreaded(1, 1, 0, 0));
}
}
static void Benchmark(string Name, Action test)
{
var sw = Stopwatch.StartNew();
test();
UpdateResults(Name, sw.ElapsedMilliseconds.ToString());
GC.Collect();
}
static Dictionary<string, string> results = new Dictionary<string, string>();
static void UpdateResults(string key, string value)
{
value = value.PadLeft(4);
if (results.ContainsKey(key))
results[key] += ", " + value;
else
results[key] = value;
Console.Clear();
foreach (var kvp in results) Console.WriteLine(kvp.Key.PadRight(25) + ": " + kvp.Value);
}
const int RowsCount = 2600;
const int ColumnsCount = 2600;
public class Point
{
public int x;
public int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}
public class GridCell
{
public int width;
public int height;
public Point point;
public GridCell(int width, int height, Point point)
{
this.width = width;
this.height = height;
this.point = point;
}
}
public struct StructPoint
{
public int x;
public int y;
public StructPoint(int x, int y)
{
this.x = x;
this.y = y;
}
}
public struct StructGridCell
{
public int width;
public int height;
public StructPoint point;
public StructGridCell(int width, int height, StructPoint point)
{
this.width = width;
this.height = height;
this.point = point;
}
}
private static void CreateCells(int cellWidth, int cellHeight, int startX, int startY)
{
var Cells = new GridCell[RowsCount][];
for (int i = 0; i < RowsCount; i++)
{
Cells[i] = new GridCell[ColumnsCount];
for (int j = 0; j < ColumnsCount; j++)
{
Point coordinate = new Point(startX + cellWidth * j, startY + cellHeight * i);
Cells[i][j] = new GridCell(cellWidth, cellHeight, coordinate);
}
}
}
private static void CreateCellsThreaded(int cellWidth, int cellHeight, int startX, int startY)
{
var Cells = new GridCell[RowsCount][];
Parallel.For(0, RowsCount, new ParallelOptions { MaxDegreeOfParallelism = 4 }, i =>
{
Cells[i] = new GridCell[ColumnsCount];
for (int j = 0; j < ColumnsCount; j++)
{
Point coordinate = new Point(startX + cellWidth * j, startY + cellHeight * i);
Cells[i][j] = new GridCell(cellWidth, cellHeight, coordinate);
}
});
}
private static void CreateStructCells(int cellWidth, int cellHeight, int startX, int startY)
{
var Cells = new StructGridCell[RowsCount][];
for (int i = 0; i < RowsCount; i++)
{
Cells[i] = new StructGridCell[ColumnsCount];
for (int j = 0; j < ColumnsCount; j++)
{
var coordinate = new StructPoint(startX + cellWidth * j, startY + cellHeight * i);
Cells[i][j] = new StructGridCell(cellWidth, cellHeight, coordinate);
}
}
}
private static void CreateStructCellsThreaded(int cellWidth, int cellHeight, int startX, int startY)
{
var Cells = new StructGridCell[RowsCount][];
Parallel.For(0, RowsCount, i =>
{
Cells[i] = new StructGridCell[ColumnsCount];
for (int j = 0; j < ColumnsCount; j++)
{
var coordinate = new StructPoint(startX + cellWidth * j, startY + cellHeight * i);
Cells[i][j] = new StructGridCell(cellWidth, cellHeight, coordinate);
}
});
}
}
}
You mentioned in the comments that both GridCell and Point are classes. Classes are by far the most common thing to create, but if you're okay with the different semantics and they mostly hold data rather than functionality, you can turn them into structs.
A struct is almost like a class, but it's a value type rather than a reference type. This means that code like this:
Point a = new Point(0, 0);
Point b = a;
b.X = 5;
Console.WriteLine(a);
…will print 0 if it's a struct and 5 if it's a class.
These semantics allow structs to be embedded within other things, and not have to have their own space on the heap. Allocating from the heap can be expensive, so if you can allocate, say, an array of structs, only one allocation needs to be done rather than many.
What I am developing is that initially the entire sudoku board is empty.
One of the random cells(out of 81) is filled with a random value(1-9).
Now I want to fill all the remaining cells using brute force approach.
From what I came to know after googling is that we should start with the first cell and fill it with 1(if it's valid), then fill the second cell with 2(if it's valid, we will begin checking with a number greater than the last filled cell, which in this case is 1, once we reach 9, we reset it with 1).
The thing is that it's not working properly!
Can anyone link me to the exact algorithm.
Here's an implementation of the backtracking approach:
import java.util.Random;
public class Sudoku {
public static void main(String[] args) {
Random rand = new Random();
int r = rand.nextInt(9);
int c = rand.nextInt(9);
int value = rand.nextInt(9) + 1;
Board board = new Board();
board.set(r, c, value);
System.out.println(board);
solve(board, 0);
System.out.println(board);
}
private static boolean solve(Board board, int at) {
if (at == 9*9)
return true;
int r = at / 9;
int c = at % 9;
if (board.isSet(r, c))
return solve(board, at + 1);
for (int value = 1; value <= 9; value++) {
if (board.canSet(r, c, value)) {
board.set(r, c, value);
if (solve(board, at + 1))
return true;
board.unSet(r, c);
}
}
return false;
}
static class Board {
private int[][] board = new int[9][9];
private boolean[][] rs = new boolean[9][10];
private boolean[][] cs = new boolean[9][10];
private boolean[][][] bs = new boolean[3][3][10];
public Board() {}
public boolean canSet(int r, int c, int value) {
return !isSet(r, c) && !rs[r][value] && !cs[c][value] && !bs[r/3][c/3][value];
}
public boolean isSet(int r, int c) {
return board[r][c] != 0;
}
public void set(int r, int c, int value) {
if (!canSet(r, c, value))
throw new IllegalArgumentException();
board[r][c] = value;
rs[r][value] = cs[c][value] = bs[r/3][c/3][value] = true;
}
public void unSet(int r, int c) {
if (isSet(r, c)) {
int value = board[r][c];
board[r][c] = 0;
rs[r][value] = cs[c][value] = bs[r/3][c/3][value] = false;
}
}
public String toString() {
StringBuilder ret = new StringBuilder();
for (int r = 0; r < 9; r++) {
for (int c = 0; c < 9; c++)
ret.append(board[r][c]);
ret.append("\n");
}
return ret.toString();
}
}
}
I used a method without backtracing, although the while loop might be it. To quote an algorithm book I've read "Nothing in recursion can't be duplicated using iteration".
I've been using my eyes to inspect this, and since I can't wrap my head around the recursive method, even though recursion is relatively understood:
This method, I kinda wrote with some guidance, had a bug in the grid checker, when I found it, it seems to be working now. I'm positing it 'cause it's hard to find complete-and-working code. IOS SDK.
#define WIDTH 9
#define HEIGHT 9
#interface ViewController ()
//- (BOOL) numberConflicts:(int)testNum;
- (BOOL) number:(int)n conflictsWithRow:(int)r;
- (BOOL) number:(int)n conflictsWithColumn:(int)c;
- (BOOL) number:(int)n conflictsWithSquareInPointX:(int)x andPointY:(int)y;
- (BOOL) number:(int)n conflictsAtGridPointX:(int)xPoint andPointY:(int)yPoint;
- (int) incrementSudokuValue:(int)v;
#end
static int sudoku[WIDTH][HEIGHT];
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
/// Initialize it
for (int x = 0; x < WIDTH; x++)
{
for (int y = 0; y < HEIGHT; y++)
{
sudoku[x][y] = 0;
}
}
///
int tries = 0;
for (int j = 0; j < HEIGHT; j++)
{
for (int i = 0; i < WIDTH; i++)
{
int num = arc4random()%9 + 1;
while ([self number:num conflictsAtGridPointX:i andPointY:j])
{
num = [self incrementSudokuValue:num];
tries++;
if (tries > 10) { //restart the column
tries = 0;
for(int count = 0; count < WIDTH; count++)
{
sudoku[count][j] = 0;
}
i = 0;
}
}
if(sudoku[i][j] == 0)
sudoku[i][j] = num;
tries = 0;
for (int y = 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
printf("%i ", sudoku[x][y]);
}
printf("\n");
}
printf("\n");
}
}
for (int x = 0; x < WIDTH; x++)
{
for (int y = 0; y < HEIGHT; y++)
{
printf("%i ", sudoku[y][x]);
}
printf("\n"); //newline
}
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL) number:(int)n conflictsWithRow:(int)r;
{
for (int y = 0; y < HEIGHT; y++) {
if (sudoku[y][r] == n) {
return YES;
}
}
return NO;
}
- (BOOL) number:(int)n conflictsWithColumn:(int)c;
{
for (int x = 0; x < WIDTH; x++) {
if (sudoku[c][x] == n) {
return YES;
}
}
return NO;
}
- (BOOL) number:(int)n conflictsAtGridPointX:(int)xPoint andPointY:(int)yPoint;
{
if ([self number:n conflictsWithRow:yPoint])
{
return YES;
}
if ([self number:n conflictsWithColumn:xPoint])
{
return YES;
}
if ([self number:n conflictsWithSquareInPointX:xPoint andPointY:yPoint]) {
return YES;
}
return NO;
}
- (BOOL) number:(int)n conflictsWithSquareInPointX:(int)x andPointY:(int)y;
{
int leftX = x - (x % 3); //used to use int division
// leftX *= 3;
int topY = y - (y % 3);
// topY *= 3;
int rightX = leftX + 2;
int bottomY = topY + 2;
for(int subY = topY; subY <= bottomY; subY++) //bug was here, used < instead of less N equal to...
{
for ( int subX = leftX; subX <= rightX; subX++)
{
if (sudoku[subX][subY] == n) {
return YES;
}
}
}
NSLog(#"Testing grid at %i, %i", x/3, y/3);
NSLog(#"LeftX: %i TopY: %i", leftX, topY);
return NO;
}
- (int) incrementSudokuValue:(int)v;
{
if (v < 9) {
v++;
return v;
}
return 1;
}
Note: The header file is empty, paste this into iOS single View application if you desire.
Caution: might loop infinitely( and above does sometimes, but is very fast), may want another more global "tries" variable, and restart the algorithm as a safety, or give it a seed/do both
edit: the below should be safe from infinite loops, if the source grid is solvable (or nonexistant)
#define WIDTH 9
#define HEIGHT 9
#interface ViewController ()
//- (BOOL) numberConflicts:(int)testNum;
- (BOOL) number:(int)n conflictsWithRow:(int)r;
- (BOOL) number:(int)n conflictsWithColumn:(int)c;
- (BOOL) number:(int)n conflictsWithSquareInPointX:(int)x andPointY:(int)y;
- (BOOL) number:(int)n conflictsAtGridPointX:(int)xPoint andPointY:(int)yPoint;
- (int) incrementSudokuValue:(int)v;
#end
static int sudoku[WIDTH][HEIGHT];
#implementation ViewController
- (BOOL) fillGridWithNext:(int)next;
{
for (int y = 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
if (sudoku[x][y] != 0)
{
if (x == 8 && y == 8) {
return YES;
}
continue;
}
for (int count = 0; count < (HEIGHT-1); count++)
{
if ([self number:next conflictsAtGridPointX:x andPointY:y])
{
next = [self incrementSudokuValue:next];
}
else
{
sudoku[x][y] = next;
if( [self fillGridWithNext:arc4random()%9+1])
{
return YES;
}
}
}
sudoku[x][y] = 0;
return NO;
}
}
return NO;
}
- (void)viewDidLoad
{
[super viewDidLoad];
/// Initialize it
for (int x = 0; x < WIDTH; x++)
{
for (int y = 0; y < HEIGHT; y++)
{
sudoku[x][y] = 0;
}
}
sudoku[0][0]=9;
int next;
next = (arc4random()%9)+1;
if( [self fillGridWithNext:next]) //seeded
{
NSLog(#"Solved");
}
else
{
NSLog(#"No solution");
}
for (int x = 0; x < WIDTH; x++)
{
for (int y = 0; y < HEIGHT; y++)
{
printf("%i ", sudoku[y][x]);
}
printf("\n"); //newline
}
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL) number:(int)n conflictsWithRow:(int)r;
{
for (int y = 0; y < HEIGHT; y++) {
if (sudoku[y][r] == n) {
return YES;
}
}
return NO;
}
- (BOOL) number:(int)n conflictsWithColumn:(int)c;
{
for (int x = 0; x < WIDTH; x++) {
if (sudoku[c][x] == n) {
return YES;
}
}
return NO;
}
- (BOOL) number:(int)n conflictsAtGridPointX:(int)xPoint andPointY:(int)yPoint;
{
if ([self number:n conflictsWithRow:yPoint])
{
return YES;
}
if ([self number:n conflictsWithColumn:xPoint])
{
return YES;
}
if ([self number:n conflictsWithSquareInPointX:xPoint andPointY:yPoint]) {
return YES;
}
return NO;
}
- (BOOL) number:(int)n conflictsWithSquareInPointX:(int)x andPointY:(int)y;
{
int leftX = x - (x % 3); //used to use int division
// leftX *= 3;
int topY = y - (y % 3);
// topY *= 3;
int rightX = leftX + 2;
int bottomY = topY + 2;
for(int subY = topY; subY <= bottomY; subY++) //bug was here, used < instead of less N equal to...
{
for ( int subX = leftX; subX <= rightX; subX++)
{
if (sudoku[subX][subY] == n) {
return YES;
}
}
}
NSLog(#"Testing grid at %i, %i", x/3, y/3);
NSLog(#"LeftX: %i TopY: %i", leftX, topY);
return NO;
}
- (int) incrementSudokuValue:(int)v;
{
if (v < 9) {
v++;
return v;
}
return 1;
}
#end
Summary: The first version is flawed but (mostly) gets the job done. It generates every row at random, if the row is invalid, it wipes and starts over. This will wipe out source grids, and can go forever, but works most of the time.
The lower code uses recursion. I don't think it backtracks properly, but it has solved empty and semi-seeded grids on my tests. I think I need to save a "state" grid to backtrack with, but I'm not doing this. I'm posting both since they both answer "Brute force"... on my own, I should study recursion, I can't explain why the lower one works, I personally could use help with doing it.
Note: The first one finishes in a blink or so when it does finish... if speed means more than reliability to your application (somewhat counter-intuitive in this case, with the infinite looping, heh).
This simple random walk algorithm should work too (but is inefficient- use at your own risk!!!):
EDIT: - added fix for unresolvable solutions.
For each empty cell in grid
array = Get_Legal_Numbers_for_cell(row,col);
If (array is empty) {
Clear_All_cells()
} else {
number = Random_number_from(array);
Put_Number_in_Cell(number);
}
EDIT 2
If someone are interested here are described methods for solving sudoku with random-based search.