Skip to content

Instantly share code, notes, and snippets.

@jadiunr
Last active May 7, 2019 02:05
Show Gist options
  • Save jadiunr/b92314d92afe952c31d4c47ad1534c59 to your computer and use it in GitHub Desktop.
Save jadiunr/b92314d92afe952c31d4c47ad1534c59 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use feature 'say';
my ($num1,$num2) = (1,1);
for my $i (1..(shift(@ARGV) or 1000)) {
say "[$i]: ", 1 and next if grep {$_ == $i} (1,2);
say "[$i]: ", $num1 = $num1 + $num2 if $i % 2 == 0;
say "[$i]: ", $num2 = $num1 + $num2 if $i % 2 == 1;
}
=encoding utf8
=head1 NAME
フィボナッチ数列出力プログラム
=head1 USAGE
perl fibonacci.pl <num>
引数が無い場合は1000番目のフィボナッチ数まで出力される
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment