Skyline puzzle

One of my colleagues brought the following puzzle to work:

Skyline puzzle

The puzzle is called Skyline and it’s a packing puzzle. The objective is to place the metal rod in one of the holes in the base and place the nine wooden pieces around it. It was designed by Jean Claude Constantin. When solved, the puzzle looks something like this:

Skyline solution

Sometimes with these kinds of puzzles it’s quicker to write a program that finds a solution than trying to solve it by hand. Check out this github repository for a Prolog program that finds solutions for a given rod location.

To use this program open the file in your favorite Prolog interpreter (e.g. SWI-Prolog) and execute the following:

You can press ; to find alternative solutions. The pos(X,Y) part refers to the location of the metal rod.

MLP in C++11

In this post I present my Christmas gift to the world: A multilayer perceptron written in C++11.

I mainly wrote this to get some practice with some of the new C++11 features such as variadic templates and lambda functions. It uses template metaprogramming to construct (but not train) the neural network at compile time. You can download the code from its github repository. It’s lacking proper documentation, but I’ve included two examples that should get you started: the xor problem and Fisher’s Iris data set.

Happy Holidays.

Statisticians are evil

I’ve made it my life’s goal to replace all statisticians with cute little robot bunnies. Watch the following video for a demo of my first prototype.

I developed a server in Prolog for the Nabaztag:tag bunny and hooked it up with a dialogue system I created during my masters. It uses an unofficial Google API for speech recognition and generation. It’s quite slow sometimes because of the poor Wi-Fi connection, the inefficient polling of the Nabaztag and the speech recognition. I have some ideas though for improving its speed. Read on for a transcript of the dialogue with comments.

Continue reading

Self-organizing bookcase

This is what my bookcase looked like before:

Books unsorted

And this is what it looks like now:

Books sorted

Much better!

So how does a geek organize his books? He uses a technique called self-organizing maps (SOM).

I basically took a high resolution photo of my bookcase (the first picture shown) and then cut out all the book spines and saved them as separate images. After doing that I had 347 little images. I used the ImageMagick command-line tool to resize all these images to a 1×1 picture. I figured that the single pixel in these images would more or less approximate the average spine color. The RGB values of these pixels were then used to train a 1 dimensional SOM. After training, the best-matching unit on the SOM for each bookspine was determined telling me how I should reorder my books.

And yes, I realize that there are easier ways to sort books by color 😉

Checkers game

Long, long time ago, when I was still a full time student, I once became first in a checkers cup with a program I wrote. Alas, those days of glory are over. Looking back, the program was pretty simple. Choosing an efficient board representation made generating the moves a piece of cake and my program didn’t make use of any opening libraries or endgame strategies. It just implemented minimax search with alpha-beta pruning. Although it wasn’t really sophisticated, I still think the program was pretty sweet and I felt disappointed when I realized I had lost the source code. That’s why I decided to implement this game again only this time in Java (the original was written in C++). I fired up NetBeans and this is the result.

Victim of the Brain

Since I first read ‘Gödel, Escher, Bach: An Eternal Golden Braid’, I’ve been a fan of Douglas R. Hofstadter’s work. This work is a must-read for anyone interested in the philosophy of mind. It touches upon many themes like logic, paradoxes, music, art, computers and thinking which makes the book appealing to a wide audience and is the reason why I picked it up in the first place. Later I also read ‘The Mind’s I: Fantasies and Reflections on Self and Soul’ which he co-authored with Daniel C. Dennet. And a few months ago I got myself the book ‘I Am a Strange Loop’.

I knew there existed a movie called ‘Victim of the Brain’ created by the Dutch director Piet Hoenderdos about the ideas of Hofstadter but I couldn’t find a copy anywhere. Until yesterday that is when I discovered that somebody uploaded it. Enjoy!


Prolog solution to Einstein’s riddle

The following puzzle is said to be invented by Einstein. Supposedly, he also claimed that only 2% of the world’s population would be smart enough to solve it.

There are 5 houses in 5 different colors in a row. In each house lives a person with a different nationality. These 5 owners drink a certain drink, smoke a certain brand of cigar, and keep a certain pet. No owners have the same pet, smoke the same brand of cigar or drink the same drink.

The question is: WHO OWNS THE FISH?


  • the Brit lives in the red house
  • the Swede keeps dogs as pets
  • the Dane drinks tea
  • the green house is on the immediate left of the white house
  • the green house owner drinks coffee
  • the person who smokes Pall Mall rears birds
  • the owner of the yellow house smokes Dunhill
  • the man living in the house right in the center drinks milk
  • the Norwegian lives in the first house
  • the man who smokes blends lives next to the one who keeps cats
  • the man who keeps horses lives next to the one who smokes Dunhill
  • the owner who smokes Bluemaster drinks beer
  • the German smokes prince
  • the Norwegian lives next to the blue house
  • the man who smokes blends has a neighbor who drinks water

Working out the solution with nothing more that a pen and some paper is certainly doable by, I suspect hope, a larger percentage of people than the 2 % mentioned above. But as an example of how to solve these kinds of logic puzzles using Prolog, I wrote this code.

Sudoku solver

It’s pretty straightforward to make a Sudoku solver in Prolog especially when applying CLP (Constraint Logic Programming).

Here is how to use my program:

Then you can enter the known numbers one by one.

When complete, the program determines and prints the solution.



By pressing ; over and over again, you could enumerate all 6,670,903,752,021,072,936,960 possible Sudoku solution grids, but this might take a while..

It shouldn’t be too hard to extend this program to actually create new puzzles. If anyone does, let me know.

The prolog environment I used here is SWI-Prolog.