Posts Tagged ‘coding dojo’

Kata cron

May 3rd, 2009

I’m currently in search for new ideas of programming katas for the coding dojo.

A small feature really impressed me in Google App Engine: the new cron feature uses plain english to define the frequency of cron jobs. Have you ever add to decode standard crontab syntax?

"0 0 12 * * ?" means "Fire at 12pm (noon) every day".
"0 15 10 ? * 6L" means "Fire at 10:15am on the last Friday of every month"

Which syntax do you prefer?

So here are two dojo ideas that I will try to develop using Ioke:

  • Easiest: translate “* * * * *” syntax to plain english
  • Harder: translate plain english to cron syntax

Blog , ,

MasterMind Kata in Ioke

April 28th, 2009

Ioke is a new language that I’ve been wanting to learn for a few weeks. I like the vision statement for this language: “Make it as expressive as possible. Period“. Ola Bini, its author, doesn’t want to focus on performances early because it would break expressiveness. Take a look a primitives types versus plain Objects in Java to understand why.

However I had no idea of what interesting code to use it on. Difficult to learn a programming language when you don’t know what to program.

So, as I try to go to the Coding Dojo every Monday, I felt that Ioke could be used to prepare the MasterMind Kata (link in French).

Here is the code, reworked after the Dojo to make it clearer:

countCorrectColorAndPosition = method(secret, guess,
  secret zip(guess) count(equals?)

countCorrectColorWrongPosition = method(secret, guess,
  pairsWithWrongPosition = secret zip(guess) filter(different?)

  secret distinct map(color,
    countWrongPositionForOneColor(pairsWithWrongPosition, color)) sum

countWrongPositionForOneColor = method(pairsWithWrongPosition, color,
  [pairsWithWrongPosition count(first == color),
    pairsWithWrongPosition count(second == color)] min
Mixins Enumerable sum = method(self inject(+))
Mixins Enumerable distinct = method(set(*self))
Mixins Enumerable equals? = method(self inject(==))
Mixins Enumerable different? = method(self inject(!=))

  it("should recognize when no peg is correct position or color",
        ["N","N","N","N"]) should == 0
  it("should recognize when one peg is correct position and color",
        ["B","N","N","N"]) should == 1
  it("should recognize when all pegs are correct positions and colors",
        ["B","B","B","B"]) should == 4

  it("should recognize when no peg is correct color",
        ["N","N","N","N"]) should == 0
  it("should recognize when a peg is correct color and wrong position",
        ["N","V","N","N"]) should == 1
  it("should recognize when there are more pegs of a given color in the guess than in the secret, and ignore these pegs",
        ["N","V","V","N"]) should == 1
  it("should ignore pegs with correct position and color",
        ["V","V","N","N"]) should == 1
  it("should recognize when pegs are correct colors for multiple colors",
        ["R","V","N","N"]) should == 2

(For a better reading).

First part is the code itself.
Second part, I had to write a few Mixins that could be included in standard Ioke library (remember it’s a very young language)
Last part are the unit tests, BDD style. I’m more used to TDD so forgive me if it’s not pure BDD.

Hope this will make you either want to practice Ioke or come to the Dojo.

Blog , ,