# Jens Klausen's programs page.

Created April 15, 1998.
Last updated May 15, 2012.

I have to come up with ideas that I can complete on my own. Genetic and physics research probably is more important and in these fields I am running BOINC and Folding@Home.

I will appreciate donations. (Not required though, for the free software). ## Programs that I have created.

### Android phones

#### Compute pi and e

This application generates up to 10000 digits of the mathematical constants π / pi (the ratio of any circle's circumference to its diameter) and e (Euler's number).

π is calculated using the Chudnovsky algorithm, which is very similar to some of Srinivasa Ramanujan's formulae involving π.

e is calculated using the formula:
e = 1/0! + 1/1! + 1/2! + 1/3! + 1/4! + 1/5! + 1/6! + ....

This is how pi is calculatedin the application:
```		private BigDecimal generatePi(int nrOfDigits){

BigDecimal cPi = new BigDecimal("0");
BigInteger fct = new BigInteger("1");
BigInteger fct3 = new BigInteger("1");
BigInteger fct6 = new BigInteger("1");
BigInteger nominator = new BigInteger("0");
BigInteger someOfDenominator = new BigInteger("0");
BigDecimal oldVal = new BigDecimal("0");
BigDecimal newVal = new BigDecimal("0");
int k = 1;
BigInteger sign = new BigInteger("1");
BigInteger pSign = new BigInteger("1");
BigInteger nSign = new BigInteger("-1");
BigInteger bD13591409 = new BigInteger("13591409");
BigInteger bD545140134 = new BigInteger("545140134");
BigInteger bD640320 = new BigInteger("640320");

nrOfDigits +=10;

BigDecimal sqrtBD640320 = BigSqrt(new BigDecimal(bD640320), nrOfDigits);
nominator = bD13591409;
someOfDenominator = bD640320;
newVal = (new BigDecimal(nominator)).divide(new BigDecimal(someOfDenominator), nrOfDigits, BigDecimal.ROUND_HALF_EVEN);
do {
if (this.isCancelled()){
return new BigDecimal("0");
}

if ((k % 2) == 0){
sign = pSign;
}else{
sign = nSign;
}
oldVal = newVal;
fct = fct.multiply(mulRange(k, k));

fct3 = fct3.multiply(mulRange(3*(k-1)+1, 3*k));
fct6 = fct6.multiply(mulRange(6*(k-1)+1, 6*k));

someOfDenominator = fct3.multiply(fct.pow(3)).multiply(bD640320.pow(3*k+1));

newVal = oldVal.add((new BigDecimal(nominator)).divide((new BigDecimal(someOfDenominator)), nrOfDigits, BigDecimal.ROUND_HALF_EVEN));
k++;
} while (newVal.compareTo(oldVal) != 0);
newVal = newVal.divide(sqrtBD640320, nrOfDigits, BigDecimal.ROUND_HALF_EVEN);
BigDecimal bD12 = new BigDecimal("12");
BigDecimal bD1 = new BigDecimal("1");
cPi = bD12.multiply(newVal);
nrOfDigits -= 10;
cPi = bD1.divide(cPi, nrOfDigits-1, BigDecimal.ROUND_DOWN);
return cPi;
}```

#### Collatz conjecture

This Java class that calculates the tables in the program: classCalculateTable.txt Explore the 3x+1, x/2 number sequences and make tables of the longest sequences.

Take any positive integer and make a sequence following the rule:
xn=xn-1/2 for xn-1 even
xn=3xn-1+1 for xn-1 odd
and repeat until xn = 1

For instance starting with 7 gives the sequence: 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 in 16 steps.
There has never been found a number where the sequence does not eventually reach 1 4 2 1 4 2 ........
Collatz conjecture states that any sequence as the above will eventually reach 1 but that has never been proven.
Is it not intriguing that many centuries of development in mathematics can not resolve a problem so easily formulated?

The Android application uses a hash table to speed up a little the calculation of tables revealing longer and longer sequences.

### Java

It can be demoralizing to loose to a computer program. If that also happens to you I can tell you that the programs I make plays better than myself.

#### Chess

I now want to begin to work more with Java that runs on many platforms including Windows, Linux and Mac OS, so I have now begun to work with NetBeans from Sun Microsystems. Initially I tried eclipse but I think things works smoother in NetBeans. I have now made a chess program in Java. I have gotten some experience in making board games, making the nine men's morris program, which makes it a little easier to structure the task better from the beginning.

Here are 3 links I find helpful in making board game programs and that I have used to make my programs:

Chess Programming Wiki

ICS 180, Winter 1997: Strategy and board game programming
Under Hashing and Move Ordering I replace this:
if (hashtable[x].checksum == y && hashtable[x].depth >= depth) with this:
if (hashtable[x].checksum == y && hashtable[x].depth == depth)

I have not made any hashtable in the Chess program yet, but I may do that later.

I have programmed the chess rules using bitboards. There is quiescent search to take care of piece exchanges, the program counts the mobility, use piece-square tables and adds small random addition to the evaluation so that the program plays more varied. Now there is also a hash table. There is no king protection and pawn structure evaluation. Adding better pruning of moves and king protection is ideas I have to make the program stronger, this could maybe be done using neural networks and genetic algorithms, which also maybe would attain other tactical advantages. The program is not nearly as good as the best chess programs, maybe its rating is around 1400. Click on the picture to download the zipped Java file, the newest is version 0.28. Unzip the content in the desired folder and run the SimpleChess.jar file to see the result.

Because the program is coded in Java it should run on Windows, Linux, Mac OS and other platforms if the Java runtime is installed. The program is free.

My software is also listed other places like on Brothersoft: Jens Klausen software free download

If anyone would like to take a look at some of the code, here is the largest class in the program that has 26 java classes in all: GenerateMoves.java

#### Sudoku

I have been working on a sudoku program in Java. It has solved all sudokus I have tested it with and can also generate new sudokus where one can put a limit on the number of initial clues, choose among non or 4 symmetries, determine the difficulty and use a template to fix the positions of the clues. To solve the sudoku I use a recursive algorithm inspired from the minimax algorithm known in chess. It is called analyseNextLevel in this Java file from the program: SudokuBoard.java

### Microsoft Visual C++ .net Standard Version 2008

#### Nine Men's Morris

Software.informer.com have made a video demonstration of SlideMills:

I have made a game of Nine Men's Morris. Below is a screen capture of the game. I was going to make the game using a genetic algorithm to find a good fully connected feed forward neural network with 2 hidden layers. It turned out to give a very low playing strength. I have now instead made an implementation using the traditional alpha-beta pruning algorithm and now it plays better, beating most human players including myself. There is also hash table support but no multi processor support. The latest version has updates in the GUI and the pieces can now slide across the board, the user can change the colours of the game as well. The link is to an installation file and Microsoft .NET framework version 3.5 is a requirement for the program to run.

### Microsoft Visual Basic 6.0 Learning Edition SP3

#### Mancala

This Program is Freeware. You are welcome to download it. It is possible to play a game of mancala against the computer on a difficult level if you set the level accordingly.

 Screen capture from Mancala mancala.zip from Yahoo Geocities. mancala.zip 1.950 KB. With this freeware program. You are able to play a beta version of Mancala. Not compiled to native code however.
If you already have the necessary Visual Basic files installed on your computer, you need only to download the zipped exe file. That's only 37 KB:

mancalaexe.zip from Yahoo Geocities

I some time ago found this link on the internet: Cooper's Visual Basic Tips Resizing Controls at Run-Time in Visual Basic

### Turbo C

#### A wobling cube in a bigger Cube

 Screen capture from Cube.exe Cube.zip 90 KB. The program displays an elastic cube moving around in a bigger solid cube. It's possible to change some parameters on the run. Programming tip: To synchronize the program with the screen raster the following lines are included in the C source code: while( (inp(0x03da) & 0x08)= =0x08); while( (inp(0x03da) & 0x08)!=0x08); VGA input status #1 register has port address 0x03da for color mode. Bit 3 in this register is 0 during the monitors display phase and 1 during the vertical retrace phase.

### Java

This Java section is about 10 years old.

Programming tips:
1. If you want to develop in Java you can download free software from Sun here: Products & APIs.
2. If your compiled Java applet program consists of name\$x.class files that produces a "Permission denied. (Filename ((accept))" error trying to upload, you can use the JAR program, described in The JavaTM Tutorial, to create a nameable jar archive containing the files.

#### Prime and 3*n+1 Numbers

Proposition: There are infinite many prime numbers.
Proof: Suppose there is only a finite number p1, p2, p3,....,pn of primes.
Then a pi that divides N+1=(p1*p2*p3*...*pn)+1 must exist among them.
We then have (((N+1)/pi)-(N/pi))=1/pi. But it is absurd that pi divides 1.
So our list of primes cannot have been complete.

It is however a little more difficult to prove that there are an infinite number of prime number twins. 2 prime numbers pn and pm are twins if pm-pn=2. It has not yet been proven whether there is an infinite or only a finite number of prime number twins.

Here is a prime number link: The Prime Page (An Index of Information on Prime Numbers)

This Java applet is made in 1.1 code if it doesn't run it might do on a newer web browser.
The program tests if 2 or an odd number smaller than or equal to the square root of the number divides.

The 3n+1 problem is to prove or disprove that if a number sequence is generated by
na+1=na/2 if na MOD 2 = 0 and
na+1=na*3+1 if na MOD 2 <> 0
Then no matter what positive integer is taken as the seed number. The sequence will always end up like 1 4 2 1 4 2 1 4 .....

The 3*n - 1 number sequences can end up in more than one way.

If you want to put this on your page: Copy the primfact.class and the Getbuttonpress.class to your html directory and put the line:

`  <applet code=primfact.class width=725 height=525></applet> `
Since May 17, 2009 this page has had an access count of: 