PHP Competition Results - Third Place

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Third Place - To Karol Grecki

The third place winner is… drumroll please.. Karol Grecki. Now you will notice by looking down at the scores that I gave Karol a 6. I will give a full explanation on why but first congratulations for a job well done.

I was really impressed with Karol’s entry and if it was not for the fact that it did not ‘run out of the box’ it would have been a close cut thing to be the winner. The fact is that because it was a pain to get running the two other judges only gave it 1 point each.

Entry Nick Stuart Cal Evans Total
1st. ?????? 4 6 6 16
2nd. ?????? 1 3 4 8
3rd. Karol Grecki 6 1 1 8
4th. JB 2 2 3 7
5th. Maurice Fonk 3 4 0 7
6th. Rob Haynes 0 0 2 2


I decided to be a little more pragmatic about its foibles and excepting that fact I loved the code itself. Karol has implemented a very clean solution, maybe not the fastest or the prettiest but it has been constructed with great thought. It also contains unit tests for most of the internal functionality.

Here is a sample test method for checking that the parsing correctly filters out unwanted characters.

public function testParseWordsFile()
{
	$this->words->parseWords('foo;bar,aaa/bbb');
	$all = $this->words->getAll();
	$this->assertEquals(array('AAA', 'BAR', 'BBB', 'FOO'), $all);
}

And this tests given a simple dictionary that the internal solver works correctly (very neat).

public function testIsSolution()
{
	$dictionary = array('BOND', 'FOND', 'FOOD', 'BAND');
	$solver = new Words_Solver($dictionary, 'FOOT', 'HAND');
	$success = $solver->solve();
	$this->assertTrue($success);
 
	$solution = $solver->getSolution();
	$this->assertEquals(array('FOOT', 'FOOD', 'FOND', 'BOND', 'BAND', 'HAND'), $solution);
}

Karol also used the Zend Framework to great effect. The application made good use of the framework making simple use of the built in MVC. Karol split the overall functionality into four seperate sections.

Views/ & Controllers/

  • Ajax
  • Error
  • Index
  • Words

Each of the controllers had views that mirrored the controllers and overall naming and execution was good. We then have the guts of the application built upon two models that dealt with the words themselves and the solving of the puzzle.

Models/

  • List - Storage for the supplied words
  • Solver - What solves the puzzle

Here is one method from the list model that parses the words and makes use of the built into Zend Validate class. (I have removed all comments from the code to reduce its size)

public function parseWords($source)
{
	$words = preg_split('/\W+/', $source);
	$validatorChain = new Zend_Validate();
	$validatorChain->addValidator(new Zend_Validate_StringLength(3))
	               ->addValidator(new Zend_Validate_Alpha());
	$filtered = array();
	foreach ($words as $word) {
		if ($validatorChain->isValid($word)) {
			$filtered[] = strtoupper($word);
		}
	}
	if(count($filtered) < 3) {
		throw new Words_UserException('least 3 valid words');
	}
	sort($filtered);
	$this->_words = array_unique($filtered);
	$this->_wordCount = count($this->_words);
}

If you wish to see Karol’s entry running you can go here. I have also uploaded the source code for everyone else to inspect if they wish (and argue with me about its merits) download the code here

So that is third place covered, tomorrow I will announce second place.

There Are 23 Responses So Far. »

  1. Hm, I specifically tested this code on windows box with your php.ini settings to make sure it works out of the box. I don’t really get how someone could have problems setting it up, were other judges developers themselves? ;)

  2. Karol: Your entry broke the rules. Rule 6 clearly states “Code must run where extracted as is with no server modifications required”. Your entry required changes to the server configuration in order to run therefore it did not “run out of the box”.

  3. I guess you didin’t have mod_rewrite enabled. Before I started work I asked for it.
    ” Nick Halstead, 21. June 2007, 21:02 mod_rewrite is fine. document root is fine. Please include the ZF within project. ”

    It was basically the only requirement I needed for ZendFramework.

  4. Mod_rewrite was enabled on my test server because that’s what the competition stated would be enabled. However, I extracted your code into a directory named karol_grecki, pointed my browser at that folder and got an error. I took a closer look and saw a directory in your code called document_root so I pointed my browser at that and it still didn’t work. I then read your README.TXT file that told me I needed to change the server configuration thus breaking rule 6. It’s really quite simple.

  5. I will not get drawn into an argument about this and this is my final word on it.

    Karol your entry included a README with the following instructions.

    “Point vhost/root at words/document_root or set RewriteBase”

    This goes beyond ‘copying files into a directory and it working’ we allowed full use of any overrides within .htaccess files, but this was your responsability to make work. It did not work without modification as stated by Stuart and was therefore penalised by the other judges.

  6. Fair enough, I could chose unsafe approach and put all code under document_root to make it easy for you. I broke a rule by trying to make things the right way ;)
    But no hard fillings, it was just for fun anyway and Nick’s comments about my code are fair.

  7. Nice, Karol. I don’t have a chance to test the speed.
    I input a dictionary over 41000 words into your site(because that’s how I test mine..)… and the Ajax loading takes forever(load the entire dictionary… O.o). Won’t it be nice if the user don’t select the words but input the words? because it’s ok to assume user going to import a dictionary of all the common words.

  8. I didn’t really focus on scalability, I was more interested with other aspects. It came to my attention that it doesn’t work quite well if you throw large dictionary at it, but it was to late for me to change it. I guess it is kind of lame for me not to think about it.
    I’ve seen some people focused on the algorithm and did some great job there. I decided to play with Zend Framework and Ajax.
    I just treated it as a web development, not computer science contest. Trying to show that you can write nice, clean and maintainable code in PHP and learn something new in the process.
    It was great fun, despite the fact that my effort was not appreciated by some of the judges.

  9. Karol: You came 3rd out of over 40 entries. If you feel that means your effort was not appreciated then there’s not a lot we can do about that.

    I’m not going to apologise for requiring that the rules were followed, and if I’d have been in charge you would not have made it into the results at all purely on the basis that you did not adhere to the specification provided. In my opinion that’s paramount to being considered good at anything nevermind programming.

  10. I don’t expect any apologies, I’m quite happy how things turned out. I did get some coverage, I got some fair comments from contest organizer and I value his opinion.
    I can just add that contest rules and requirements were pretty vague, just look at number of questions in the original thread. I also asked to be notified if there were any problems with setting it up and I hosted it myself just in case, even knowing that is dead easy to set up. I also tested it on Windows with provided ini settigns and on IE which I don’t normally use. I would said I made quite an effort to make it work for you guys.
    I missed something, fair enough. Just one thing I have to ask you. Was this contest about how well you follow the rules or how good application can you create? Actually don’t answer that. The case is closed. It was your call, you decided and I accept that. No point in arguing.

  11. A wise man once said: “An application that’s not to spec is a broken promise.”

  12. …and a broken promise is worse than no promise at all.

  13. Well Scott, seeing some of the people care so much about spec I decided to check something. My application actually works without any server modification (as long as mod_rewrite is enabled). The confusion was that all files except bootrap were outside of document root.
    You just unpack it into the parent directory and change the document_root folder into whatever your server is using by default.
    In case of Ubuntu, unpack to /var and change document_root of my app to http://www.
    Works fine. No server modification. You just need think, or ask for help, that’s what good developers do, instead of fallowing rules. But I guess it was too much of an effort for some people.

  14. Karol, the other judges worked on this for no reward at all. They may gain a little extra coverage by being associated with the competition but that certainly does not make up for the massive amount of work this has been for them. They did it because they wanted to support me (thanks guys!) and because it interested them.

    You may have spent considerable time writing your entry, but each Judge has had to go through 6 entries, looking at every file, testing every application with different data sets, checking if they worked if you missed different values, plus then writing them up for me in detail. This is a *considerable* undertaking.

    So when I wrote the rules stating that ‘out of the box’ was required, I was doing it in the hope it would make their lives (and mine) easier, so saying ‘too much effort for some people’ is slapping them in face for the free work they did and that is totally unfair to them, and it upsets me because they do not deserve it.

  15. I’d assume the common interpretation of “out of the box” would be that it is synonymous with “no changes required”. Those who accept this interpretation would judge that an entry that required directories to be renamed did not work “out of the box”.

    A wise man once said: “Take the shame.”

  16. Well Nick, I feel slapped in the face too by last comments from Stuart.
    He judged my work, now I judge his as a judge. And I just proved him wrong.
    I know that he was faced with a difficult task, but there’s no reason to be arrogant.
    Let’s get the facts straight. My app didn’t required server changes. Could be set up in seconds. There was a minor issue it with, easily solvable, if he didn’t know how, he could ask you or me, no wasting time required.

    Scott: read the requirements please, don’t make up your own.

  17. Sorry you’re right, there is no use of that phrase in the original description.

    I assume this is what you are referring me to?

    “6. Code must run where extracted as is with no server modifications required”

  18. Changing the apache conf or the name of a directory, that is a server change is it not?

  19. Karol: Why do you insist on continuing this?

    “In case of Ubuntu, unpack to /var and change document_root of my app to www” - explain to me how that meets the requirement “Code must run where extracted as is with no server modifications required”. The key phrase in there is “where extracted”. Whether the fix was simple or not is irrelevant. Your entry did not meet this requirement, end of story.

    That will be my last comment on your entry because continuing to argue about it serves no purpose.

  20. “That will be my last comment on your entry because continuing to argue about it serves no purpose.”

    It has a certain entertainment value.

  21. Well, I meant the config, but nevermind, let’s end this. This is not what this contest was about. I believe you did your job the best you could. Sorry to anyone who might feel offended.

  22. This is definitely entertaining:) I can’t wait to see the comments for winners #2 and #1! By the way I think it’s important to acknowledge the judges like Nick mentioned, for volunteering their time free of charge. These kinds of activities are fun and engaging and wouldn’t be possible without the work of people like the judges involved. Hopefully the overall sense of this contest was that it was a success and we will see more in the future because of that. Kudos on a good event Nick, it’s kept me riveted for the last couple weeks:D

  23. Karol rulezzz!
    lol

Post a Response