Learning Languages with 543

When learning a new programming language, I like the idea of having a familiar program or algorithm to reimplement in the new language. My personal favorite is a little game that I prosaically call 543. I have no idea if there is an actual name for this game as it was taught to me in a bar. 543 is a two-player deterministic board game with very simple rules. It is perfect for the minimax algorithm - there’s enough complexity in minimax to use a fair amount of a language, but it can be written in a few hours if so motivated.

The Rules of 543

  • There are three rows of pieces. The first row has 5 pieces, the second has 4 pieces, the third has 3 pieces.
  • Each player takes turns removing pieces from the board. The player is only allowed to remove one or more pieces from a single row.
  • The player that is left with the last piece on the board is the loser.

The rules above are for the basic version, but the number of pieces and the number of rows are variable. This makes for interesting optimizations, such as alpha-beta pruning. All languages handle the basic 12 piece board easily, but as we increase the number of pieces, the number of moves grows exponentially. I’m interested to see how Ruby, JavaScript, Java, and Scala all scale upward. I’ll try to provide some data there too.

Ruby

Ruby Code on Github

Java

Java Code on Github

JavaScript (React)

JavaScript Code on Github

Running version of React App

Crystal

Crystal Code on Github

Scala

Coming soon