Arguably the thing that tripped me up for the majority of the time was latching on to the fact that == and === are different, and trying to _always_ satisfy the two conditions, rather than just spotting that I can change the reference to b from within the first valueOf call. I'm not sure how much I'd read into the "if I was more of a mathematician and less of a dumb programmer this would have been solved trivially" argument.
nmrm|12 years ago
In other words, it would never even occur to a mathematician to make your mistake...
More to the point, a mathematician wouldn't assume that some arbitrary predicate that you are allowed to define at will behaves the same way as a system-defined equivalence operator.
Edit: Added last paragraph and readability changes. Also, ~ is another symbol for equality, this time equality over binary relations.