"be consistent" 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?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-06-21 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (118 votes). Check out past polls.

Notices?