mathematicaでgolf
TRANSCRIPT
@aomoriringo
ゴルフ◦ 少ない打数でカップにボール入れる
Code Golf◦ 少ない文字数で目的の出力をする
ショートコーディングのサイトhttp://golf.shinh.org/
83の言語に対応(Mathematicaは当然未対応)
言語別の文字数ランキングも閲覧可
Mathematicaで勝手にランキング1位を目指してみよう
“Hello, world!” と出力せよ。
Input◦ なし
Output◦ Hello, world!
Hello, world! (13byte)
“Hello, world!” (15byte)
“Hello, world!”(15 byte)
Rank Lang Size1 goruby 12 bash 113 Zsh 124 PHP
m4fishA+sed
13
5 RubyPerlUniversal Lambda
14
1から100までの整数を出力せよ。ただし 3の倍数のときは”Fizz”,
5の倍数のときは”Buzz”,15の倍数のときは”FizzBuzz”,
と数字の代わりに出力せよ。
Output1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 . . .
Rank Lang Size1 FlogScript 362 GolfScript 373 Bash 414 Perl6 445 J 456 goruby 467 Vi 478 Perl 489 Z80 4910 Postscript
Ruby50
自然定数eを100桁表示せよ。
Input◦ なし
Output◦ 27182818284590452353602874713526624977
572470936999595749669676277240766303535475945713821785251664274
N[E,101]
2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
27182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
N[E,101]
2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
ToString[N[E,101]]
“2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274”
StringSplit[ToString[N[E,101]],”.”]
{“2”,”7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274”}
“”<>StringSplit[ToString[N[E,101]],”.”]
“2718281828459045235360287471352662497757247093699959574966967627724076
6303535475945713821785251664274”
“”<>ToString[E~N~101]~StringSplit~”.”
“2718281828459045235360287471352662497757247093699959574966967627724076
6303535475945713821785251664274”
“”<>ToString[E~N~101]~StringSplit~”.”
37 byte
Rank Lang Size1 GolfScript 172 J 213 bc 274 goruby 305 Ruby 326 Perl 337 Bash
Zsh37
8 Groovydc
38
9 fish 4010 Python 41
f(1)=1, f(2)=1, f(x)=f(x-1)+f(x-2)とする.f(1)からf(46)を出力せよ.
Output 1, 1, 2, 3, 5, 8, 13, 21, . . .
Fibonacci[n]
n番目のFibonacci数を出力する
Array[f,5]
{f[1],f[2],f[3],f[4],f[5]}
Array[Fibonacci,5]
{1,1,2,3,5}
Array[Fibonacci,46]
Array[Fibonacci,46]
Fibonacci~Array~46
Array[Fibonacci,46]
Fibonacci~Array~46
18byte
Rank Lang Size1 FlogScript 122 GolfScript 133 PostScript 174 Minus
J18
5 dc 196 goruby
Perl621
7 vi 228 Ruby
bc24
9 A+Bashfish
25
Code Golf コワイ
皆さんもお好きな言語でお試しください