It was a great fun. I’ve learnt a lot. And it tickled my ego a little bit as I still consider myself a noob, so it was nice to prove myself. And this wasn’t typical golf challenge where they want you to code fizz buzz or Fibonacci numbers. This was a bit more challenging.
There was yet another success on my side. When I was writing it I’ve found out that example was wrong. I’ve checked my code multiple times and even did a dry run on piece of paper. And was sure my code was correct and example wasn’t. So I’ve informed the author of this competition, he confirmed I was right and updated the examples.
Here’s original example:
$ ./task 2 25H0,32S0,46R1,63H1,76S1 ........ ........ ........ ....S.H. ...H.... ........ ....R..S ........
$ ./task 3 25H0,32S0,46R1,63H1,76S1 ........ ........ ....S... ......H. ..H..... ........ ....R..S ........
After second iteration there should be only one healthy individual, but as you can see above there are two.
Another thing I’ve noticed, however I’ve not informed author directly this time, was “R - Recovered person, can be infected”. If person who recovered from sickness can be infected why according to the algorithm it never does. It’s been changed to “cannot be infected”.
I’ve also learnt that I know nothing about coding golf. And treated it as any other programming challenge. But here, the shorter the code the better, not the cleaner one, that’s why me second JS entry was scored higher. Of course I could’ve read the rules of code golf first and minify my code upon the first entry, but oh well. This is what happens when you’re so eager to start coding you don’t consume full specification. Another lesson learnt;) It sounds like I want to justify the fact that I’ve eventually lost this competition, but really, I was only focused on solving the problem which I’ve found interesting.
Probably the best thing from this experience was that I could cooperate with other programmer, whom I value a lot. And that I could reach out and exchange my findings with the author. As I work alone it’s really great that I had opportunity to communicate with humans, especially such smart ones.
I also have a confession to make, I haven’t solved it fully. My code for finding the neighbours isn’t complete. Because people move like Pacman (through the walls) when a person is in top left corner, for instance, it can be infected by the person who is in bottom right corner. My code doesn’t cover such possibility. So I was able to complete the competition by brute forcing it. Not very proud of it, but I didn’t want to invest more time in it, especially that I’ve known I won’t win. You can check the code here and here.