jLife: the last son of my mental illness

May 20, 2008

Do you know the Conway’s Game of Life? Well for them who don’t…

The Game of Life is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is the best-known example of a cellular automaton.

The “game” is actually a zero-player game, meaning that its evolution is determined by its initial state, needing no input from human players. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. A variant exists where two players compete.

Yesterday I read an article about it ad I felt an insane necessity of developing a little java version of this useless game (of course it is not the first implementation of the life game… but it was just for my fun)!

Here you can download it:

Here you can find bit different version… the world-loop one. In the previous version the world was a 100×100 bordered matrix, in this version instead it is a 100×100 infinite-loop matrix (each border is connected to the opposite one creating an infinite loop).


Java String Class: hot water discovered!

April 9, 2008

Yesterday, working on my graduation project, I discovered the String class in Java has a method that allow to compare it with a regular expression passed as argument. I was really amazed, it was about 2 hours I was working on an algorithm that it was supposed to check if a string matched to a SQL RegEx (a regular expression that use % and _) to implement the SQL LIKE “function”  in my project when I discovered the “matches()” method of the String class.

Since I was far from finishing my algorithm this discovery made me save much time (yes… I know a better knowledge of Java would have me allowed to save also the first 2 hours but no one is born learned).

For example:

//String I want to check
String myString = "Freedom";

/*Next is SQL regular expression that say "the 3rd
and the 4th characters are 'e' and the last one is 'm'*/
String regEx = "__ee%m";

//trasform SQL RegEx to a Java one
String javaRegEx = regEx.replace("_", ".").replace("%", ".*");

/*The method return TRUE 'cause "Freedom" matches the RegEx*/
myString.matches(javaRegEx);

 

Actually I know all this is nothing special… and to many of you may be a “hot water discovery”… but I really wanted to share it!