コードゴルフ⛳の
すすめ

@hakatashi

2019年6月28日 pixiv社内勉強会 LT

自己紹介

@hakatashi (博多市)

  • 最近ハマってるもの
    • 百合
    • 炊飯
  • 最近おすすめの百合漫画
    • ふたりべや
    • ななしのアステリズム
  • 最近おすすめの炊飯漫画
    • 特になし

コードゴルフ⛳

ご存知ですか?

プログラムを
1文字でも短く書く競技

その言語の機能を
余すこと無く利用する

例題

入力された文字列から空行をすべて削除する

hoge

fuga



hoge

p
i
y

o
hoge
fuga
hoge
p
i
y
o

普通に書いたら

while text = gets
  puts text unless text.chop.length == 0
end

62 bytes

インデント削除

while text = gets
puts text unless text.chop.length == 0
end

60 bytes

変数名を短縮

while t = gets
puts t unless t.chop.length == 0
end

51 bytes

空行判定を最適化

while t = gets
puts t unless t == "\n"
end

42 bytes

unlessをifに修正

while t = gets
puts t if t != "\n"
end

38 bytes

特殊変数$_を導入

while gets
puts $_ if $_ != "\n"
end

36 bytes

空白を省略

while gets
puts$_ if$_!="\n"
end

32 bytes

後置whileを利用

puts$_ if$_!="\n"while gets

27 bytes

shebangによる引数渡しを利用

#!ruby -p
$_=""if$_=="\n"

25 bytes

Rubyゴルフのプロの回答

$><<[*$<]-[$/]

12 bytes

(Code Golf - SlideShare より引用)

 

私事ですが

私事ですが

コードゴルフの大会を運営してます

  • チーム戦
  • 1マス1言語に対応
  • 一番短いコードを提出したチームの色に染まる
  • 隣接したマスのみ提出可能

変なプログラミング言語 (?) を
たくさん実装

  • Brainfuck
  • Befunge
  • Hexagony
  • Piet
  • jq
  • sed
  • awk
  • なでしこ
  • Whitespace
  • プロデル
  • قلب‬
  • எழில்
  • LibreOffice Calc
  • SQLite3
  • Emojicode
  • ⋯⋯など、計160言語

前回大会のお題

言語別「短さ」ランキング

  • 1. Vim, 11 bytes
  • 2. MATL, 22 bytes
  • 2. gs2, 22 bytes
  • 4. Japt, 25 bytes
  • 5. 05AB1E, 27 bytes

VimGolf

  • 入力を「編集前のファイル」、
    出力を「編集後のファイル」と定義して、
    目的の出力に整形するまでの
    キーストローク数を競う
  • 保存コマンド
  • vimgolf.comという専用競技サイトも存在する

デモ

コードゴルフで遊べるサイト

ZZ

(おしまい)

Made with Slides.com