[過去ログ] プログラミングのお題スレ Part13 (1002レス)
前次1-
抽出解除 レス栞

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
673
(6): 2019/03/14(木)18:58 ID:dvZ8z+Z0(2/2)調 AAS
お題:フィボナッチ数列を最初の10個表示せよ

ruby
https://ideone.com/ewyP50

perl6
https://ideone.com/O3tVZj
689: 2019/03/15(金)00:10 ID:27sSd34q(2/2)調 AAS
>>673 Perl5

@f = (0, 1);
push @f, $f[-2] + $f[-1] while @f < 10;
print "@f\n";

実行結果
~ $ perl 13_673_fib10.pl
0 1 1 2 3 5 8 13 21 34

Prel6、いいな…
694: 2019/03/15(金)01:15 ID:T0clmjRI(1)調 AAS
>>673 Squeak Smalltalk

| fibGen |
fibGen := [:a :b | Generator on: [:g | [g yield: a. b := a + b. a := b - a] repeat]].
(fibGen value: 0 value: 1) next: 10.

"=> an OrderedCollection(0 1 1 2 3 5 8 13 21 34) "
696
(1): 2019/03/15(金)01:51 ID:Fj/79Ht+(1)調 AAS
>>673 javascript
const take = n => function*(iterable) {
const iterator = iterable[Symbol.iterator]();
for (let i = 0; i < n; i++) {
const {value, done} = iterator.next();
if (done) break;
yield value;
}
};
const fibo = function*() {
const memo = [0n, 1n];
const fib = n => n in memo ? memo[n] : memo[n] = fib(n - 2) + fib(n - 1);
for(let i = 0; ; i++) yield fib(i);
}();

console.log([...take(10)(fibo)]);
結果:
[0n, 1n, 1n, 2n, 3n, 5n, 8n, 13n, 21n, 34n]
697: 2019/03/15(金)08:40 ID:VdqhZ9XO(1)調 AAS
>>673 Common Lisp
https://ideone.com/fbbBbx
700: 2019/03/15(金)10:54 ID:EVqxIhVf(1)調 AAS
>>673

Haskell

main = (print.take 10) fibs
where fibs = 0:1:zipWith (+) fibs (tail fibs)
708: 673 2019/03/15(金)19:08 ID:3zDqFokC(1)調 AAS
>>673 java
https://ideone.com/vNVR4y

>>673 c
https://ideone.com/P6eqTd
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.034s