18 March 2012
One of the easiest things to get tripped up on is the syntax for creating regular expressions (regex) in Java using the Pattern class. The tl;dr version of how to do things is that you must use double-backslashes in the regular expression Strings you use to create a Pattern object; so something like \b would have to be written as "\\b". Read on for a more thorough explanation.
Continued
12 February 2012
I have had a side interest in emergent behaviour ever since reading about various forms in nature, so when a co-worker sent me a link to Conway’s Game of Life, I was immediately intrigued.
Long story short, I just had to implement it (albeit a simple version) in JavaScript. The result is available on my website and I suggest you give it a try; a good pattern to start out with is the F-pentomino.
The reason I find emergence so interesting is that it provides a possible framework or explanation for the complexity and order seen in our universe, based on a fairly simple or rudimentary set of rules.
Continued
5 February 2012
Quick, how do you write code that shuffles a collection of objects? In the real world, it’s fairly easy to see how a deck of cards is shuffled – but how would you do that in code? Obviously, you would have to use some sort of random number generator, but beyond that it’s not straightforward. Furthermore, how do you ensure that the shuffling is fair; that is, all permutations appear with equal probability?
The astute among you will know that one way is by implementing the Fisher-Yates shuffle algorithm. But, let’s investigate what happens when other, seemingly adequate solutions, are used instead.
Continued