When a programmer deals with mathematics, one of the most common routines added to his/her math library is matrix inversion. The following code implements a very efficient in-situ matrix inversion (meaning that no memory is allocated for another matrix to hold the result; the inverse of the matrix is built gradually in the matrix itself!). The code is based on an algorithm published in Numerical Recipes.
Today I stumbled on an program I had written years ago. During a hot summer I used to spend my time solving Sudoku puzzles at the beach - which is quite fun if you are in a must-not-work mode. Of course, very soon I found myself on my laptop, writing a program for creating and solving Sudoku puzzles. The algorithm for the creation of new puzzles is interesting, although probably not the most efficient, and surely someone else has thought it before me. In any case, I am sharing:
I have been involved lately in a soon-to-be-huge project about accounting, invoices, etc.
When printing some invoices I noticed some inconsistencies in the sums; one or two cents difference with respect to the result I obtain when checking the numbers by hand. A little digging and the problem was isolated; it was the Math.Round() function.