Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) 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!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (10)
    As of 2014-09-21 16:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (172 votes), past polls