XP is just a number PerlMonks

### Comment on

 Need Help??

The following script employs Zeckendorf's_theorem and prints the Zeckendorf representation for a given number.

```#!/usr/bin/perl

use strict;
use warnings;

zeck(\$ARGV[0]);

sub zeck {
if (is_fibonnacci(\$_[0])) {
print "\$_[0]\n";
exit;
}
my \$count = 0;
my \$prev = 0;
my \$curr = 0;
while ((\$curr = fibonnacci(\$count)) < \$_[0]) {
\$prev = \$curr;
\$count++;
}
print "\$prev\n";
zeck(\$_[0] - \$prev);
}

sub fibonnacci {
my \$a = 0;
my \$b = 1;
for (0..\$_[0]) {
my \$c = \$a;
\$a = \$b;
\$b = \$c + \$b;
}
return \$a;
}

sub is_fibonnacci {
my \$plus = (5 * \$_[0] * \$_[0]) + 4;
my \$mins = (5 * \$_[0] * \$_[0]) - 4;
return is_perfect_square(\$plus) || is_perfect_square(\$mins);
}

sub is_perfect_square {
my \$sqrt = int(sqrt(\$_[0]));
return \$sqrt * \$sqrt == \$_[0];
}

In reply to 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?
 [shmem]: discovered a fuel tank leakage at my second hand motorbike. Some bloke drove a screw too long through the fairing [shmem]: hard to fix, and plans wrecked. And more... won't tell. [shmem]: the leakage has been "fixed" with a piece of bycicle tube. Bleargh. [karlgoethebier]: shmem: yes. my first ride tomorrow is questionable because of lumbago. shit [shmem]: But! the bloke wasn't me, at least. [shmem]: karlgoethebier: isn't bike riding a way of fixing lumbago? [karlgoethebier]: shmem: scheiss technik

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2017-06-25 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (570 votes). Check out past polls.