awk で ppencode もどき

ppencode というものを Lightwight Language Day and Night で竹追さんが披露され、Perl 界隈に広まったことがありました。JavaScript のデモも有名になりました。 Perl では関数名や変数名だけで括弧や演算子を使わないというものでしたが、さすがに awk では無理があるので、可能な範囲で対応してみました。

とりあえず、以下のようなものです。

BEGIN{while(i++ < int(int(exp(cos(length))) cos(length)))c=c"%c";printf c,
int(cos(length) length substr(sqrt(substr(sqrt(exp(exp(cos(length)))),
cos(length),cos(length)) length),substr(sqrt(exp(exp(cos(length)))),
cos(length),cos(length)),cos(length))),int(cos(length) length \
int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))))),
int(sqrt(substr(log(substr(sqrt(exp(exp(cos(length)))),cos(length),
cos(length))),int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length)))),
cos(length)) cos(length)) int(sqrt(int(exp(cos(length))) \
substr(log(int(exp(cos(length)))),substr(sqrt(exp(exp(cos(length)))),
cos(length),cos(length)),cos(length))))),int(cos(length) cos(length) \
int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))))),
int(sqrt(substr(log(substr(sqrt(exp(exp(cos(length)))),cos(length),
cos(length))),int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length)))),
cos(length)) cos(length)) int(exp(int(exp(cos(length)))))),int(cos(length) \
length int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))))),
int(cos(length) cos(length) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))),
int(cos(length) cos(length) cos(length)),int(substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length)) \
substr(sqrt(substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)) \
length),substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),
cos(length))),int(cos(length) int(exp(cos(length))) cos(length)),
int(cos(length) length int(exp(int(exp(cos(length)))))),
int(substr(sqrt(substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)) \
length),substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),
cos(length)) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))),
int(cos(length) cos(length) substr(sqrt(substr(sqrt(exp(exp(cos(length)))),
cos(length),cos(length)) length),substr(sqrt(exp(exp(cos(length)))),
cos(length),cos(length)),cos(length))),int(cos(length) length \
int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))))),
int(cos(length) length sqrt(substr(log(substr(sqrt(exp(exp(cos(length)))),
cos(length),cos(length))),int(sqrt(int(exp(cos(length))) \
substr(log(int(exp(cos(length)))),substr(sqrt(exp(exp(cos(length)))),
cos(length),cos(length)),cos(length)))),cos(length)) cos(length))),
int(substr(sqrt(substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)) \
length),substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),
cos(length)) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))),
int(cos(length) cos(length) cos(length)),int(cos(length) cos(length) \
substr(sqrt(substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)) \
length),substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),
cos(length))),int(substr(sqrt(substr(sqrt(exp(exp(cos(length)))),cos(length),
cos(length)) length),substr(sqrt(exp(exp(cos(length)))),cos(length),
cos(length)),cos(length)) substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))),
int(cos(length) length substr(log(int(exp(cos(length)))),
substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))),
int(cos(length) cos(length) int(exp(cos(length))))}

微妙に一部に演算子が入っていますが、while 文を回すことだけに使っていて本質ではありません。 実際に実行してみましょう。

$ nawk -f mail_address.awk
hi_saito@yk.rim.or.jp

個人的にはもう少し短く表現したかったのですが、長くなってしまいました。

さて、いろいろな方法で同じことを行うことはできますが、ここでは以下のように 1 から 9 までの数字を用意しました。

0 : length
1 : cos(length)
2 : int(exp(cos(length)))
3 : substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length))
4 : substr(sqrt(substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)) \
    length),substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),
    cos(length))
5 : int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
    substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),cos(length))))
6 : substr(log(int(exp(cos(length)))),substr(sqrt(exp(exp(cos(length)))),
    cos(length),cos(length)),cos(length))
7 : int(exp(int(exp(cos(length)))))
8 : substr(log(substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length))),
    int(sqrt(int(exp(cos(length))) substr(log(int(exp(cos(length)))),
    substr(sqrt(exp(exp(cos(length)))),cos(length),cos(length)),
   cos(length)))),cos(length))
9 : sqrt(substr(log(substr(sqrt(exp(exp(cos(length)))),cos(length),
    cos(length))),int(sqrt(int(exp(cos(length))) \
    substr(log(int(exp(cos(length)))),substr(sqrt(exp(exp(cos(length)))),
    cos(length),cos(length)),cos(length)))),cos(length)) cos(length))

これを使って 10 進数で表示しているだけです。ASCII の 10 進数表記はこのあたりを参考にしています。

tag_nawk.pngtag_nawk.pngtag_nawk.pngtag_nawk.png