awesome! it's been so long since I wrote this I'd completely forgotten about it. thanks for adding Python (one of my favorites)!
The expected result should be 0.2. The affinity, for this exercise, considers both values and their indices.
yonax, you uncovered a nasty bug. I have fixed it and added the test cases discussed above to the kata.
This was due to an issue in my logic for solving the problem. It has been corrected, and the kata has been republished.
vector_affinity([None], ) == 0.0 => True
I am republishing the kata now, with this issue resolved.
Yes, I will file this as an issue.
The problem is that the solution is looking for equality in the terms of each vector.
Comparing None to a non-existent value will equate to True since they are both NoneType.
This comment is hidden because it contains spoiler information about the solution
no real reason. probably still mentally stuck in if/else syntax from other languages. if I were to write the solution again, I would likely use if
easy enough, but then shouldn't i also add:
test.assert_equals(vector_affinity([None], [None, None, None, None]), .25)
test.assert_equals(vector_affinity([None], [None, None, None, None, None]), .5)
test.assert_equals(vector_affinity([None], [None, None, None, None, None, None, None, None, None, None]), .10)
To me knowing that:
vector_affinity([None], [None]) == 1.0
vector_affinity([None], ) == 0.0
should be enough to deduce that None is also a value that counts, and that [None]/[None, None] gets a .5 affinity.
again, it's easy enough to add the test case, but unless that test case addresses a specific flaw in the instructions or problem, i'm hesitant to do so.
had to unpublish, save, then re-publish. the provided tests should be working properly now.
Sorry, I've been trying to update that all day, but every time I try to "re-publish" the kata with the corrected test cases, it never finishes, just sitting at about 99% for as long as I'm willing to let it go.
I am working on getting that fixed.
I think the ratio/float thing is trivial enough. The point of the kata is to return a float that indicates how similar two vectors are. In practical application, if a ratio were needed, it wouldn't be an issue to remove the float conversion.
mtthw123, after typing that bit a few times, and feeling like it was giving too much away, I ended up adding a couple more example test cases, one in which the vectors were not same-length, then mention that it holds a clue to the correct solution (or a correct solution).
(= (vector-affinity [6 6 6 6 6 6] ) (float (/ 1 6))
Just since here obviously the second vector is shorter, and the equality to (float (/ 1 6)) illustrates that the larger of the two is used as the denominator.
What are you thoughts on that?