[過去ログ] プログラミングのお題スレ Part16 (1002レス)
上下前次1-新
抽出解除 レス栞
このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
101(10): 2019/12/04(水)23:37 ID:h1My/is4(1) AAS
お題: 1~100までの数列の和を計算する
102: 2019/12/04(水)23:58 ID:+9nEsnh/(1) AAS
>>101 Ruby
$><<101.times.sum # => 5050
103: 2019/12/05(木)00:15 ID:5juZ/T5v(1) AAS
>>101 julia
print(sum(1:100))
115: 2019/12/05(木)14:27 ID:esMh+bxM(1/2) AAS
>>101
Kotlin script
println((1..100).sum())
120: 2019/12/05(木)20:44 ID:lop64poz(1) AAS
>>101
Cの冗談
外部リンク:ideone.com
140: 2019/12/06(金)14:03 ID:zI729h7a(1) AAS
>>101 julia
f(a,b)=(a+b)*(b-a+1)÷2
f(1,100) #-> 5050
f(50,80) #-> 2015
141: 2019/12/06(金)22:43 ID:7FicwbM7(1/2) AAS
>>101 Perl5
use feature current_sub;
print sub {$_[0] and $_[0] + __SUB__->($_[0] - 1)}->(100);
142: 2019/12/06(金)22:53 ID:7FicwbM7(2/2) AAS
>>101 Perl5
sub Y_combinator { my $f = shift;
sub { my $x = shift; $x->($x) }->(
sub { my $y = shift;
$f->(sub {$y->($y)(@_)}) }
)
}
my $series = sub {my $f = shift;
sub { my $n = shift; $n and $n + $f->($n - 1) }
};
省1
147: 2019/12/07(土)00:25 ID:7zlttp1T(1/3) AAS
>>101 Perl5
no warnings 'experimental::signatures';
use feature qw(say signatures);
sub f($n) {$n and $n + f($n - 1)};
say f(100);
sub Y($f) { sub {$f->(Y($f))->(@_)} }
say Y(sub($f) { sub($n) { $n and $n + $f->($n - 1) } })->(100);
148: 2019/12/07(土)00:44 ID:7zlttp1T(2/3) AAS
>>101 Perl5
no warnings 'experimental::signatures';
use feature qw(say signatures);
sub Y($f) { sub {$f->(Y($f))->(@_)} } # Y combinator w/ recursive
$s = sub ($n) {$n and $n + $s->($n - 1)}; # calc series recursive
say Y(sub ($f) { $s })->(100);
149: 2019/12/07(土)01:33 ID:7zlttp1T(3/3) AAS
>>101 Perl5
use List::Util 'sum';
print sum 1..100;
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.956s*