métier

Hundred doors kata

Publié par Éric Le Merdy

Name : Hundred doors

Type : Algorithm

Subject : https://github.com/ericlemerdy/one-kata-per-day/tree/master/hundred-doors

What I have learned :

  • Creating some code just for test is not bad or waste, it is just necessary

    ex: the constructor Row(int i) or the method countDoors()

  • Default values for production

    ex: the constructor Row() creates 100 doors

  • Algorithm discovery through simple to complex cases. Implementation are generalized to make the duplication visible and for the loop to emerge.

  • If I am confident with tests up to row 4, I am not going to test the production case (row 100) because the point is to find the answer.

    A concise toString to visualize has been produced before the end to provide visual feedback of the algorithm trace. And it is beautiful :)

    ex: the execution trace for a Row(5):

    ▯▮▮▮▮
    ▯▯▮▮▮
    ▯▯▯▮▮
    ▯▯▯▯▮
    ▯▯▯▯▯
    ▯▮▯▯▯
    ▯▮▯▮▯
    ▯▮▮▮▯
    ▯▮▮▯▯
    ▯▮▮▯▮
    ▯▮▮▯▮
    2 open door(s)
    3 closed door(s)