|Keep It Simple, Stupid|
Re: Zeckendorf representationby Athanasius (Prior)
|on Aug 25, 2012 at 04:30 UTC||Need Help??|
I agree with tye — this is cool! And I’m impressed with the speed at which the calculations are done; this calculation:
(see code below) takes less than a second on my machine!
My only quibble is with the design of the zeck subroutine. A sub containing exit is a red flag for me, and even print statements are better deferred to the caller. To my mind, zeck should return the sum as a list of Fibonacci numbers. And in Perl, this is surprisingly easy to do:
Note that by restricting sub zeck to a single responsibility, the code becomes both more flexible and shorter.
Again, thanks for a cool demo!
P.S. I actually find jwkrahn’s one-line version of sub is_perfect_square to be clearer than the original. I guess clarity is in the eye of the beholder!
Athanasius <°(((>< contra mundum