First of all I would like to THANK YOU to all who participated in the first issue of our Weekend Programming Challenge!
Secondly as we did this challenge rules quickly, I greatly underestimated how difficult would be to judge which code is best🙂
I admit that I never expected such interest, so many submissions giving the short time we put to solve the problem.
The best long terms benefit for running this challenge is that it will be great source to learn new and interesting things looking at the submitted codes and solutions.
For instance I never have hear that GNU/Octave exist, and I never have seen code made in Scala language, same for the other colleges here at Olimex.
So we think we are under-qualified to comment or decide if the code for solution-10 and solution-19 is good or bad as we can’t🙂
What we very liked to see in the submitted solutions is that some authors make control of their inputs and check for different situations, this way optimizing their code, in case of the line to be vertical or horizontal no need to make divisions or sqrt(). This should optimize the speed as “if” is faster than */sqrt().
Also we like the control of the input and the verification if A=B although it’s subject to interpretation as the problem says A and B define Line, it’s always better if you check for ANY situation which may occur trather to count that A and B will be always different points. Do not get us wrong, the solutions which do not check if A=B also are correct in the spirit of the problem, but incomplete in our point of view.
This one line solution-18 is one of my personal favourites (although not optimized as always will do math even if the line is vertical or horizontal):
def d(A, B, C):
(a, b, c) = (P(A), P(B), P(C))
return (((c.x * (b.y – a.y) + c.y * (a.x – b.x) – a.x * b.y + b.x * a.y) ** 2 / ((a.x – b.x) ** 2 + (a.y – b.y) ** 2)) ** 0.5 if A != B else None)
Solutions: 1,2,3,5,6,7,8,9,10,12,13,15,16,20 have possible problem with division by zero as do not check their input.
We ask ourselves what happens if A==B in Solution 8 and 9.
Solution 4 check for horizontal line but forgot to check for vertical line.
Solution 11 is one of the best and offers two different way to complete the job with 2D geometry (first part) and with vectors (second part).
Same is for Solution 14,17,18 they do everything correctly.
Solution 10 and Solution 19 are impossible to be commented by us as we are out of knowledge🙂
From the very beginning we stated that this competition will be just for the sake of the challenge and for fun.
There will be no material prize intentionally – to keep away the overheating discussions which always supports competition with material prizes.
I see this challenge as something which may help us to improve our knowledge and see how different persons can see on one even simple problem from different angles, using different tools, and this way to make our own horizons wider🙂
So if we have to select winner for this round, they should be few and I would give winner badge to:
4,11,14,17,18 + eventually (10,19)🙂
Thanks again to all who submitted their solutions! Looking forward to see you again next Friday.