# Building a word clock with genetic algorithms

Maybe it was a language barrier he ran into, or possibly an inclination to do things the hard and smart way, but we really like [Alessio]’s take on building the display for his word clock. Instead of relying on a pre-designed word layout, he made his own word pattern with a genetic algorithm.

While looking at other word clock builds on the Internet, [Alessio] noticed all the DIY copies used the same pattern of letters as the original QLOCKTWO word clock. There are obvious reasons for this, laziness chief among them, but [Alessio] decided to do one better. Armed with JGAP, he made a 10×10 German language word clock and a 11×11 English language word clock.

[Alessio]’s algorithm takes a list of regular expressions – ‘five past four’ and ‘four five’ are both valid expressions for 4:05 – and combines solutions together for a hopefully optimal solution. One added bonus of [Alessio]’s method is the ability to generate non-square word clocks. On his project page, [Alessio] put up examples for round, triangular, and diamond-shaped word clocks.

[Alessio] ended up building a 10×10 square German language word clock with an Arduino Nano, DS1307 real-time clock, RGB LEDs, and a few shift registers. Very nice work for a custom-designed word clock.

## 22 thoughts on “Building a word clock with genetic algorithms”

1. MrX says:

“regular expressions”

I don’t think that means what you think it means.

1. Thopter says:

Take a look at his site. He does use regex:

1:00 : (.*?)(one)(.+?)(o)(.+?)(clock)(.*)
1:05 : (.*?)(one)(.+?)(five)(.*)
1:05 : (.*?)(five)(.+?)(past)(.+?)(one)(.*)

1. MrX says:

My bad, next time I promise I’ll read TFA before attempting to troll.

2. Guy says:

@MrX: The linked article gets it correct. That’s the issue you take away from this though? Not how cool the actual hack is? Give me a break.

Anyways, to Alessio: This is awesome! Great practical use of GA.

3. uC says:

Looks clever. I’ve been looking to put one of these together based on a recent kickstarter project ClockTHREE.

Alessio has definately made this much more interesting. Very clever use of the regexp to solve potential matches. I wonder if it could be used to find Vertical as well as horizontal matches.

1. Thopter says:

Just take the groupings that the program puts out, and arrange them vertically before you cut the stencil.

1. uC says:

I intended to say it would be interesting if it could arrange them BOTH horizontally and vertically.

like so:
``` t w one ```

still, tis cool

2. Thopter says:

“[Alessio] decided to do one better. Armed with JGAP, he made a 10×10 German language word clock”

He did not use JGAP.

“I just wanted to really understand the GAs and decided to program it *completely by myself*. For a real problem you would of course use one of the many GA frameworks (JGAP for example)”

4. Thopter says:

“Fourthy” and “fourty” should be changed to “forty”.

Also, I’d change the :05 times to (.+?)(o)(.+?)(five)(.*).

5. ellindsey says:

“Fourthy”? Neat idea, but I think something was lost in translation.

1. Ivan says:

I don’t know where that sample came from. But I’m glad I’m not the only one that fell for it. Try looking for “three” ;-)

I guess it’s just a picture. Hehehe

I freakin love GA,ever since the mona lisa I’ve been craving for more.Also got a 2D vehicule GA trying to climb a hill.I still have em somewhere on my computer if you want em,they are offline now.. =/

7. Andrew says:

4:05 is never “four five”, it’s “four oh-five”. If you’re an English speaker, that is.

8. Thopter says:

Has anyone else been able to get his java code to run? I’ve had no luck at all so far.

9. Thanks everybody, I corrected the “fourty” typo and changed the :05 times as suggested by Thopter and Andrew.

Whats the problem with the code? I just imported it in Eclipse and it runs without any problems….

1. Thopter says:

I figured out how to run the code. It was my fault, my first time compiling and running java code on my computer.

I redownloaded the zipped code, but it’s the same as before. What changes did you make?

1. I didn’t really change the Zip file, I’ll do that if I don’t forget it..
The only changes where in the “TimeNamesEnglish.java” where the strings for the times are generated – just have a look at it, it’s rather short.

2. Thopter says:

Yeah, I made changes in that file too. I didn’t see how to get the :05 though, without also getting “o five past three”.

3. I put the code up on github, so check it out