Four Seasons challenge

Julia.Fischer.Vivaldi

It’s fun to see how fast you can learn to discern between all twelve movements in Antonio Vivaldi’s Four Seasons. I made a web app in Javascript to make it easy to explore the music and challenge yourself with a graded test. To get an A you need to listen and figure out the correct season and movement for 13 out of 16 music excerpts. Click on the picture above to try it out.

 

Efficient recursive maze algorithm

screenshot

I made a recursive bisecting maze algorithm in just eight lines of code. (click on above image to see it in action)

codeshot

The efficiency of the algorithm comes at the cost of a fairly low entropy. It means that the randomness of the maze is limited. A high entropy algorithm could ideally produce a maze where you had to traverse every room in the labyrinth in order to move from the room in the bottom left corner to the room to it’s immediate right. This could never be the case with the above listed bisecting algorithm where internal access between rooms within the same bisection is always guarantied.

Use Game of Life to Generate 256 bit Hash

game.of.life.256.bit.hash

One of the most fascinating aspects of Game of Life is that it illustrates so well how a completely deterministic process can be so unpredictable. Use a fixed starting pattern and run. Watch the result. Use the same starting pattern but change a single cell somewhere. The new result can be as different from the old as night and day.

Absolute determinism plus unpredictability are precisely the two things you look for in a hash algorithm. When you store passwords on a server you don’t store the passwords themselves but their hashes, calculated using some hash algorithm like for example MD5, SHA-256 or Whirlpool.

A user authenticating himself on the server inputs his password and the server hashes the password to see if the hash corresponds to the hash stored on the server.

For a hacker getting hold of the stored hashes, or for the system administrator, there is no way to run the hash algorithms backwards to retrieve the real passwords. The only way to break a hash is to systematically hash every possible password (out of zillions) and see if the hash matches.

I made this Javascript application to illustrate the idea of using Game of Life to generate hash values. The application is not using Conways standard B3/S23-rules but instead B23/S23-rules.

Try to hash different words or sentences differing only by a single letter adjacent in the alphabet and watch how the hash value changes. You can also try to hash some text but before you click on the ”Run 200 steps” click somewhere on the gird with the mouse pointer to change a single bit.

Game of Life with B345/S45 rules

A lot of people are familiar with British mathematician John Horton Conway’s ”Game of Life” – an algorithm to simulate cellular growth and decay, first published in Scientific American in 1970.

The concept is simple. Imagine an infinite grid of empty squares. Each of these squares can either be empty or occupied by a ”cell”. The are only two rules. One rule for empty squares (the birth rule) and one rule for squares occupied by a cell (the survival rule).

Birth: If an empty square has exactly three neighboring cells a new cell is born in that square.
Survival: An existing cell will only survive if it has either two or three neighbors.

These two rules implies a time axis along which the grid will project forward in discrete phases.

But why do we have these specific rules? Why is exactly three neighbors required to give birth to a new cell?

Conway’s classical rules are sometimes abbreviated to the code B3/S23.

The reason for these particular rules to have become so popular isn’t that strange. Anyone who has experimented with a simulation engine using these rules knows that they often create very complex and interesting situations.

But this being a fact doesn’t exclude the possibility of other rules also having the potential of creating complex and interesting scenarios.

Conway himself and others have explored a lot of other possible rules for Birth and Survival.

I played around two days ago with my own javascript-powered game of life engine where I can chose any set of rules for birth and survival. I wanted to explore an idea I had to use the game of life cellular automaton concept to create a cryptographic hashing algorithm. So, by a mere coincidence, I tried the B345/S45 rules and was fascinated by the way that an initial small colony of cells transformed during hundreds of phases only to later die out. This was almost always the fate that awaited small colonies occupying an initial eight times eight square. I tried out new random shaped colonies, one after another and very seldom a shape would pop up that wouldn’t die out but instead grow and grow and never stop growing. How come, I wondered?

I dealt with this question systematically and found out that there are only 36 symmetrical shapes out of a total of 37888 that will grow indefinitely. All the other symmetrical 8×8-shapes will eventually be either totally annihilated or get stuck in small for ever repeating loops of shapes (so called pulsars).

Here is the total set of miracle seeds – the smallest possible symmetrical shapes that I found that will grow forever. All the tens of thousands of others are destined to perish or stagnate.

smallest.possible.symmetrical

I have shown that there exist no smaller symmetrical shapes, for example 7×7-shapes or 6×6-shapes, that will grow indefinitely.

Add or remove a single pixel anywhere and they will die – that’s how sensitive they are (try it out for yourself).

So these are the symmetrical ones. What about the asymmetrical ones?

I don’t know, but I guess that you can’t find an asymmetrical shape smaller that 8×8 that will grow indefinitely.

It could be tested systematically but the number of all shapes that occupy a maximum space of 8 times 8 squares are much larger than just the symmetrical ones.

Click on this link or on the picture above to go to my B345/S45 simulation engine.

Update: July 28 2015

Amazing news. After seventeen hours of automatic testing of random shaped populations eight different asymmetric 8×7 indefinite growers presented themselves!

8x7 grower 8x7 grower 2 8x7 grower 3 8x7 grower 4 8x7 grower 5 8x7 grower 6 8x7 grower 7 8x7 grower 8

I  also found three shapes that lasted a long time but in the end didn’t quite make it.

8x7 lasted 539 8x7 lasted 542 8x7 lasted 716

They lasted 539, 542 and 716 (!) rounds respectively.

Coding Sheep Intelligence

Foxes vs Sheep

For the last couple of days I’ve been working with javascript to develop sheep intelligence in the classic and ancient Scandinavian board game ”rävspelet” (sometimes identified with the old norse ”halatafl” and closely related to the English board game ”Fox and Geese”)

I’m very pleased with the result because I think they play really well. You play the foxes and you can chose to face sheep of four levels of difficulty. It’s not that hard to beat them at the two easier ”lamb-levels” but try to beat them on any of the two more advanced levels. Can you do that? Click on [this link] or on the picture above to play!