0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【備忘録】フィボナッチ数列について

Posted at

フィボナッチ数列について

直接的な言語で出てくることがあるのかは、今後に任せるとして…
このような数列があるということだけは覚えておきたい。

1,1,2,3,5,8,13,21,34...

n番目の数(n-1)番目と(n-2)番目の数の和からなっている数列。
この数列を覚えるというよりは、算出するときの考え方・頭の柔らかい使い方を覚えておきたい。

$a = 1;
$b = 0;
// 以下部分をwhile文だったりfor文だったりでループさせる。
$s = $a + $b; // この値をechoで出力したりする。そしてこの後の考え方が重要だと思った。
$a = $b;
$b = $s; // $aに$bを、$bに$sを入れていくことで、n-1番目とn-2番目を表現していくことができる。

とても素敵な考え方だと思った。
覚えておきたい考え方…多いなぁ…

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?