P is for Practical PerlMonks

### Comment on

 Need Help??

Hello thmsdrew,

I agree with tye — this is cool! And I’m impressed with the speed at which the calculations are done; this calculation:

```zeck(1019377012345) = 956722026041 + 53316291173 + 7778742049 + 113490
+3170 + 267914296 + 102334155 + 39088169 + 14930352 + 514229 + 196418
++ 46368 + 17711 + 6765 + 987 + 377 + 55 + 21 + 8 + 1

(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:

```my @zeck = zeck(\$ARGV[0]);
print 'zeck(',  \$ARGV[0], ') = ', join(' + ', @zeck), "\n";

sub zeck
{
return \$_[0] if is_fibonnacci(\$_[0]);

my \$count = 0;
my \$prev  = 0;
my \$curr  = 0;

while ((\$curr = fibonnacci(\$count)) < \$_[0])
{
\$prev = \$curr;
\$count++;
}

return (\$prev, zeck(\$_[0] - \$prev));
}

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

In reply to Re: Zeckendorf representation by Athanasius
in thread Zeckendorf representation by thmsdrew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2018-05-28 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (198 votes). Check out past polls.

Notices?