@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

Size

2

bash

11

4

PHP
m4
fish
A+
sed

13

1

3

5

goruby

Zsh

Ruby
Perl
Universal Lambda

1

12

14




1から100までの整数を出力せよ。
ただし 3の倍数のときは”Fizz”,
5の倍数のときは”Buzz”,
15の倍数のときは”FizzBuzz”,
と数字の代わりに出力せよ。
Output
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13
14 FizzBuzz 16 17 . . .
Rank

Lang

2

GolfScript

1
3

4
5

6
7
8
9

10

Size

FlogScript

36

Bash

41

Perl6
J

goruby
Vi

Perl

Z80

Postscript
Ruby

37

44
45
46
47
48
49
50


自然定数eを100桁表示せよ。



Input



Output

◦ なし

◦ 27182818284590452353602874713526624977
57247093699959574966967627724076630353
5475945713821785251664274
N[E,101]


2.71828182845904523536028747135266
2497757247093699959574966967627724
0766303535475945713821785251664274




2.71828182845904523536028747135266
2497757247093699959574966967627724
0766303535475945713821785251664274

2718281828459045235360287471352662
4977572470936999595749669676277240
766303535475945713821785251664274
N[E,101]
2.718281828459045235360287471352662
4977572470936999595749669676277240
766303535475945713821785251664274
ToString[N[E,101]]
“2.718281828459045235360287471352662
4977572470936999595749669676277240
766303535475945713821785251664274”
StringSplit[ToString[N[E,101]],”.”]

{“2”,”71828182845904523536028747135266
24977572470936999595749669676277240
766303535475945713821785251664274”}
“”<>StringSplit[ToString[N[E,101]],”.”]

“27182818284590452353602874713526624
97757247093699959574966967627724076
6303535475945713821785251664274”
“”<>ToString[E~N~101]~StringSplit~”.”

“27182818284590452353602874713526624
97757247093699959574966967627724076
6303535475945713821785251664274”
“”<>ToString[E~N~101]~StringSplit~”.”

37 byte
Rank

Lang

2

J

1

3

4
5
6
7
8
9

10

Size

GolfScript

17

bc

27

goruby
Ruby
Perl

Bash
Zsh

21
30
32
33
37

Groovy
dc

38

Python

41

fish

40





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

2

GolfScript

1
3

4
5
6
7
8
9

Size

FlogScript

12

PostScript

17

Minus
J

13
18

dc

19

vi

22

A+
Bash
fish

25

goruby
Perl6
Ruby
bc

21

24
Code Golf コワイ
皆さんもお好きな言語で
お試しください

Mathematicaでgolf