>
> This is not implementing expt as it is usually known, it looks more like
>> repeated squaring to me.
>>
>
> Agreed. There's a certain irony that the OP declares the code pure,
> simple, and beautiful, when it isn't correct code. Seems to me that if you
> can't tell at a glance what a 3-line program is doing, there's something
> wrong :)
>
True. There are much better/more efficient implementations like:
(define (even? n)
(= (remainder n 2) 0))
(define (fast-expt b n)
(cond ((= n 0) 1)
((even? n) (square (fast-expt b (/ n 2)))) ;even O(log(n))
(else (* b (fast-expt b (- n 1)))))) ;odd O(n)
Sorry for the apparently awful examples in the original post. :/
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.