Just Another Ruby/Python Hacker,
実行すると
Just Another Ruby/Python Hacker,
と表示されます。cygwinで確認しました。
なお、このRubyワンライナーを作るにあたってRubyのある風景 - rrencodeのてくにかるいしゅーが非常に参考になりました。というかRubyは詳しくないので自力では無理でした。
なお「どのへんがPythonなんだ」と思う方は実行されたコマンドの最後と下の「このRubyスクリプトを作るのに使ったPythonスクリプト」の最初の方を読むとわかるかも知れません。
__ 使う記号の種類を限定してさらにひどいものにしてみました。「<<」を文字列の結合とシフト演算の両方に使ったり、「?)-?(」(イコール1)を多用するようにしたり、という嫌らしいことをしてあります。?(や?)のせいで、ただでさえ括弧を頼りにして読むことが難しいのに、括弧を必要以上につけてあるのでさらに読みづらくなっています。でもなんかきれい。
ruby -e "_=%?%?<<?!+?!+?!;$><<_%((((?)-?())+(?%+(?%<<?)-?())))<<_%((?%+(?)+?+))) <<_%(((?%+(?+<<?(-?)))<<?)-?())<<_%((?%+(?-+(?-<<?(-?)))))<<_%((?%+(?%<<?)-?())) <<_%(((?%+(?%<<?(-?)))<<?)-?())<<_%((?%-(?--?()))<<_%(?-)<<_%((?%+(?(+(?-<<?(-?) ))))<<_%((?%-(?--?()))<<_%((?%-(?(-?%)))<<_%((((?)-?())+(?%+(?%<<?)-?())))<<_%(( ?%+(?%+?()))<<_%((?(+(?++(?-<<?(-?)))))<<_%(((?%+(?%<<?(-?)))<<?)-?())<<_%(((?%+ (?+<<?(-?)))<<?)-?())<<_%((?%-(?--?()))<<_%((?(-((?)-?())))<<_%((?%<<?)-?())<<_% ((?%+(?(<<?)-?()))<<_%((?%+(?%+?))))<<_%(((?%+(?+<<?(-?)))<<?)-?())<<_%((?%-(?-- ?()))<<_%((?++(?-<<?(-?))))<<_%(((?%+(?%<<?(-?)))<<?)-?())<<_%((?%+(?%<<?)-?())) <<_%(((?%+(?+<<?(-?)))<<?)-?())<<_%((?%+(?-+(?-<<?(-?)))))<<_%((?%+(?++(?+<<?(-? )))))<<_%((?%+(?%+?()))<<_%((?%-(?--?()))<<_%((?)<<?)-?())<<_%((?%+(?(<<?)-?())) <<_%(((?)+(?--?%))<<?)-?())<<_%((?%+(?)+?+)))<<_%((((?)-?())+(((?)-?())+?-)))<<_ %((?(<<?)-?())<<_%((?%+(?)+?+)))<<_%(((?%+(?+<<?(-?)))<<?)-?())<<_%((?%+(?-+(?-< <?(-?)))))<<_%((?%+(?%<<?)-?()))<<_%(((?%+(?%<<?(-?)))<<?)-?())<<_%((?%-(?--?()) )<<_%(((?%-((?)-?()))<<?)-?())<<_%((?%+(?(+(?(<<?(-?)))))<<_%((?%+(?(+(?-<<?(-?) ))))<<_%((?(+(?-+(?-<<?(-?)))))<<_%((?%+(?++(?+<<?(-?)))))<<_%((?%+(?%+?()))<<_% ((((?)-?())+?+))<<_%((?(-((?)-?())))<<_%((?%-(?(-?%)))" | sh
シンプルに「Just Another Ruby Hacker,」と表示するスクリプトは下のようになります。
ruby -e "_=%?%?<<?!+?!+?!;$><<_%((?%<<?)-?())<<_%((?%+(?(<<?)-?()))<<_%((?%+(?%+ ?))))<<_%(((?%+(?+<<?(-?)))<<?)-?())<<_%((?%-(?--?()))<<_%((?++(?-<<?(-?))))<<_% (((?%+(?%<<?(-?)))<<?)-?())<<_%((?%+(?%<<?)-?()))<<_%(((?%+(?+<<?(-?)))<<?)-?()) <<_%((?%+(?-+(?-<<?(-?)))))<<_%((?%+(?++(?+<<?(-?)))))<<_%((?%+(?%+?()))<<_%((?% -(?--?()))<<_%((?)<<?)-?())<<_%((?%+(?(<<?)-?()))<<_%(((?)+(?--?%))<<?)-?())<<_% ((?%+(?)+?+)))<<_%((?%-(?--?()))<<_%(((?%-((?)-?()))<<?)-?())<<_%((?%+(?(+(?(<<? (-?)))))<<_%((?%+(?(+(?-<<?(-?)))))<<_%((?(+(?-+(?-<<?(-?)))))<<_%((?%+(?++(?+<< ?(-?)))))<<_%((?%+(?%+?()))<<_%((((?)-?())+?+))"
これらのコードを出力したPythonスクリプトは下記。
import sets
targetStr = "python -c \"print 'Just Another Ruby/Python Hacker,'\""
#targetStr = "Just Another Ruby Hacker,"
target = sets.Set([ord(x) for x in targetStr])
#mark = "!\"#$%&'()*+,-./:;<=>@[\\]^_`{|}~"
mark = "()+-%"
caches = []
levels = {}
cache = {}
for m in mark:
v = ord(m)
cache[v] = "?" + m
levels[v] = 0
if v in target:
target.remove(v)
cache[1] = "((?)-?())"
levels[1] = 0
caches.append(cache)
for level in range(1, 10):
print level
cache = {}
i = level - 1
for x in caches[i]:
# *2
v = x * 2
if not(levels.has_key(v)):
cache[v] = "(" + caches[i][x] + "<<?)-?()"
levels[v] = level
# /2
v = x / 2
if not(levels.has_key(v)):
cache[v] = "(" + caches[i][x] + "<<?(-?))"
levels[v] = level
for i in range(level):
j = level - i - 1
for x in caches[i]:
for y in caches[j]:
# add
v = x + y
if not(levels.has_key(v)):
cache[v] = "(" + caches[i][x] + "+" + caches[j][y] + ")"
levels[v] = level
# sub
v = x - y
if not(levels.has_key(v)):
cache[v] = "(" + caches[i][x] + "-" + caches[j][y] + ")"
levels[v] = level
caches.append(cache)
for v in cache:
if v in target:
target.remove(v)
if len(target) == 0:
break
result = "_=%?%?<<?!+?!+?!;$>"
for line in [caches[levels[ord(x)]][ord(x)] for x in targetStr]:
result += "<<_%(" + line + ")"
print result