On Thu, Oct 7, 2010 at 12:29 PM, Jarl Haggerty <fictivela...@gmail.com> wrote: > I'm using clojure 1.2
OK, I stand corrected. Stuart's right. The problem is that you're getting mixed numeric types. When you do (collatz 113383) the sequence eventually hits 2482111348 which is a Long, not an Integer. When you divide by 2, (/ 249211348 2) you should get back an Integer, but instead, you get back a Long. This continues until eventually you're bouncing back and forth between 1, 2, and 4 which are Longs rather than Integers, and thus aren't being found in your hash map. My understanding is that Clojure 1.2 is supposed to auto-reduce all arithmetic operations specifically to avoid situations like this. Therefore, I believe it is a bug that (/ 249211348 2) returns a Long rather than an Integer. Unfortunately, I don't know whether anyone is likely to fix it, since Clojure 1.3 is pursuing an entirely different arithmetic strategy. The quickest fix for your particular situation is to use quot (quotient) rather than /, since quot properly auto-reduces. Another workaround (for example, if you don't know in advance that the first operand is divisible by the second) is to call clojure.lang.Numbers/reduce after each division. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en