Solving Sudoku with Assembly Code

Posted: February 4th, 2009 | Author: | Filed under: My Little Projects, Programming | Tags: , , | 2 Comments »

Who wants to solve the popular sudoku game with assembly code while there are lots of high level languages? Yes, I did. This was one of my home experiment and I wanted to make post about it. Actually assembly code is quite error prone language if you are not careful enough, but with some simple principals and being awake while coding you can create really effective algorithms. The solution does not include backtracking, and able to solve sudokus which don’t require backtrackings.

Here is how the algorithm works;

As you might already know in a sudoku board every cell has 9 possible values from 1 to 9. So while the algorithm traverses the sudoku grid (which is 9×9 matrix) it considers that every single cell has initially 9 possible values, and traverses the 3×3 grid of cell in evaluation and removes the existing values from possibility array. Does the same thing for row and column of the cell. At the and if there is only one possible value it puts the value to the cell, if not continues searching/traversing.

Consider the following example, there are cell that their value is certain. Check the left up most cell of the grid. There is only one possible value which is 2. By the time it puts values to the cells the puzzle gets easier.

Sudoku_example_2

And for this board here is the output of the algorithm;

image

And one last thing to mention; algorithm is assembly function which can be called in from C++ with the help of most compilers;

image

Here is the code!


For C# “typeof”, “GetType()”, “is” explained

Posted: February 2nd, 2009 | Author: | Filed under: Programming | Tags: , , , | No Comments »

So what is the difference between typeof and object.GetType() in .NET C#?

Type myType = typeof(Foo);
 
Type myType = foo.GetType();

Results of both are exactly the same. To be able use GetType() you need an instance of the class, however typeof can be used by the name of class. So GetType() is resolved in run-time while typeof is resolved in compile-time, which is an important difference.

And what about when there is inheritence?

class Bar : Foo
{
  .....
}
 
static void Main()
{
   Foo c = new Bar();
   c.GetType(); // returns typeof(Bar)
}

 

In the example above c.GetType() returns the type of Bar since the real instance is created using Bar() and handle is not important.

So here is how -is- behaves:

Bar bar = new Bar();
 
// false, even though bar is a child of foo.
if (bar.GetType() == typeof(Foo))
 
// However this is true
if (bar is Foo)

Prepend & Append to Methods in batch selectively

Posted: January 12th, 2009 | Author: | Filed under: My Little Projects, Programming | Tags: , , , | 1 Comment »

A tool that finds all C# methods in a cs file and lets you put any code block to the beginning of the method and to the end of the methods. Simply you can prepend or append code blocks to any method that you select in a source code file. Since it detects method signatures with a regular expression that lays in a config file, practically you can use the tool for any programming language.

 

here is the project page;

http://code.google.com/p/prependappendtomethods/