While working through the Advent of Code problems from 2015 in order to teach myself Snap!, I found a weird case where my answers to the day-3 problem were all off by exactly one too many. After double- and triple-checking my logic, I eventually discovered that under some circumstances (which I had managed to trigger with my project), the “uniques of (list)” block was returning an incorrect result, where there was one duplicate still left in the list. E.g. in a list of coordinates that I used for testing where (0,0) was repeated several times, the correct result would have been the list ( (0,0),(1,0),(0,1) ) but under some circumstances the uniques block was producing the list ( (0,0),(0,0),(1,0),(0,1) ) where two occurrences of (0,0) were appearing instead of just one.
This project was using only integer math (and only addition of positive or negative numbers, no multiplication or division) so there was no chance of this being a case of “one of those numbers looks like 0 but is really 0 + some tiny fraction, due to floating-point rounding errors”.
The project was on my local computer, not online, so I’ll need to upload the XML file in order to share it. If the forum software doesn’t allow that, well, I’ve uploaded the XML file (trimmed down to the bare minimum needed to reproduce the incorrect result) to the Github issue report here: Incorrect result from "uniques of list" in certain specific circumstances (repro attached) · Issue #3489 · jmoenig/Snap · GitHub
A sample of what’s going wrong:
Here we can see that the result variable contains a six-item list where the coordinates (0,0) appear four times. The uniques block should trim that down and leave only a single (0,0) in what it reports.

Here we can see that if we call uniques on a list that is equal to what is in the result variable, the result from uniques is correct: a list of the three unique coordinates, in which (0,0) only appears once.

Here we can see proof that what’s in the result block is equal to that list of six coordinates.
And here we can see the bug being demonstrated: even though uniques produces the right result when called with a list that’s equal to whatever is in result, when it’s called with the value that is actually in result then it somehow misses one duplicate, and leaves (0,0) in the list twice, for reasons I have not yet managed to figure out.





