Name: Anonymous 2010-03-21 7:39
So, I recently read about the collatz conjecture on xkcd.
Of course I had read my SICP that day (like every day), so I was
certain, I could easily implement it in Scheme. Like this:
When i call
me all the numbers, until it throws an error when it reaches 1:
procedure application: expected procedure, given: #<void>; arguments were: #<void> 1
How do I do it right?
Of course I had read my SICP that day (like every day), so I was
certain, I could easily implement it in Scheme. Like this:
(define (collatz n)
((display n)
(newline)
(if (> n 1)
(if (odd? n) (collatz (+ (* 3 n) 1))
(collatz (/ n 2)))
1)))When i call
(collatz 10), for instance, PLT Scheme givesme all the numbers, until it throws an error when it reaches 1:
procedure application: expected procedure, given: #<void>; arguments were: #<void> 1
How do I do it right?