ズンドコキヨシ Quine with Ruby

## ズンドコキヨシ Quine

[あなたの知らない超絶技巧プログラミングの世界](http://www.amazon.co.jp/dp/B015R0GNXK/?tag=wwwhanachin-22)を読んだら書けた。

```zun.rb
f=30;eval$s=%w(s=%(eval$s=%w(#  {$s} )*""  );z="I24142@_M=>
_M=>_M=?_M?<_0:?E=_0:?E<_07>_             04BMB_02H8S_02
J6Q_<6<4O_<6<4M_<FI";d=">2414             2M_B=M_B=M_B=M
_B=M_B=M_BN<_LD<_BN<_B=M_B=M_             B=M_B=M_B=M_B=M
_B=M";k="06:_D3H28_D3H28_D3H4               8_06:C<_06:C
          <48=8_D3H48=8_D                     3H68;8_D3HE<_
          06:C<C>_06:C<2M                     _06:7H2K_06:
       7H2I_06:7H2E";
    sp=0x20.chr;f=(f<<                             1&31)+rand(2);aa=p
  roc{|t|t.split('_').map{        |l|l.chars.map{|x|x.ord-0x30}.map.w
  ith_index{|x,i|(i.even?)?(      '#'*x):(sp*x)}.join}.join($/);};c
d=aa[[z,d][f      &1]].gsub('1    2','#'+sp).gsub('#'){c=s.slice!
(0,1);c==''?      '#':c};puts(    "f=#{f};#{cd}");puts;puts(aa[
k]+$/*2)&&ex                      it()if(f==1);;)*""#######
```

```doko.rb
f=31;eval$s=%w(s=%(  eval $s=%  w(#{$s})*"");z="I24142@_M=>_M
=>_M=?_M?<_0:?E=_0             :?E<_07>_04BMB_02H8S_02J6Q_<6
<4O_<6<4M_<FI";d="             >24142M_B=M_B=M_B=M_B=M_B=M_B
N<_LD<_BN<_B=M_B=M             _B=M_B=M_B=M_B=M_B=M";k="06:_
D3H28_D3H28_D3H48_             06:C<_06:C<48=8_D3H48=8_D3H68
;8_D3HE<_06:C<C>_0             6:C<2M_06:7H2K_06:7H2I_06:7H2
E";sp=0x20.chr;f=(                              f<<1&31)+ran
d(2);aa=proc{|t|t.split('_')                    .map{|l|l.ch
ars.map{|x|x.ord-0                              x30}.map.wit
h_index{|x,i|(i.ev             en?)?('#'*x):(sp*x)}.join}.jo
in($/);};cd=aa[[z,             d][f&1]].gsub('12','#'+sp).gs
ub('#'){c=s.slice!             (0,1);c==''?'#':c};puts("f=#{
f};#{cd}");puts;pu             ts(aa[k]+$/*2)&&exit()if(f==1
);;)*""###########             #############################
##################             #############################
##################             #############################
```

## 実行例

```console
   _╰╰,   /ﾊﾞｼｮ % ~/tmp
  _/o ŏｧ  / ﾀｲﾁｮｰ% ﾔﾊﾞｲ
∈ミ;ﾉ,ﾉ   ＼ｺﾏﾝﾄﾞ% ruby doko.rb | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr | ruby | tee /dev/stderr
f=31;eval$s=%w(s=%(  eval $s=%  w(#{$s})*"");z="I24142@_M=>_M
=>_M=?_M?<_0:?E=_0             :?E<_07>_04BMB_02H8S_02J6Q_<6
<4O_<6<4M_<FI";d="             >24142M_B=M_B=M_B=M_B=M_B=M_B
N<_LD<_BN<_B=M_B=M             _B=M_B=M_B=M_B=M_B=M";k="06:_
D3H28_D3H28_D3H48_             06:C<_06:C<48=8_D3H48=8_D3H68
;8_D3HE<_06:C<C>_0             6:C<2M_06:7H2K_06:7H2I_06:7H2
E";sp=0x20.chr;f=(                              f<<1&31)+ran
d(2);aa=proc{|t|t.split('_')                    .map{|l|l.ch
ars.map{|x|x.ord-0                              x30}.map.wit
h_index{|x,i|(i.ev             en?)?('#'*x):(sp*x)}.join}.jo
in($/);};cd=aa[[z,             d][f&1]].gsub('12','#'+sp).gs
ub('#'){c=s.slice!             (0,1);c==''?'#':c};puts("f=#{
f};#{cd}");puts;pu             ts(aa[k]+$/*2)&&exit()if(f==1
);;)*""###########             #############################
##################             #############################
##################             #############################

f=31;eval$s=%w(s=%(  eval $s=%  w(#{$s})*"");z="I24142@_M=>_M
=>_M=?_M?<_0:?E=_0             :?E<_07>_04BMB_02H8S_02J6Q_<6
<4O_<6<4M_<FI";d="             >24142M_B=M_B=M_B=M_B=M_B=M_B
N<_LD<_BN<_B=M_B=M             _B=M_B=M_B=M_B=M_B=M";k="06:_
D3H28_D3H28_D3H48_             06:C<_06:C<48=8_D3H48=8_D3H68
;8_D3HE<_06:C<C>_0             6:C<2M_06:7H2K_06:7H2I_06:7H2
E";sp=0x20.chr;f=(                              f<<1&31)+ran
d(2);aa=proc{|t|t.split('_')                    .map{|l|l.ch
ars.map{|x|x.ord-0                              x30}.map.wit
h_index{|x,i|(i.ev             en?)?('#'*x):(sp*x)}.join}.jo
in($/);};cd=aa[[z,             d][f&1]].gsub('12','#'+sp).gs
ub('#'){c=s.slice!             (0,1);c==''?'#':c};puts("f=#{
f};#{cd}");puts;pu             ts(aa[k]+$/*2)&&exit()if(f==1
);;)*""###########             #############################
##################             #############################
##################             #############################

f=30;eval$s=%w(s=%(eval$s=%w(#  {$s} )*""  );z="I24142@_M=>
_M=>_M=?_M?<_0:?E=_0:?E<_07>_             04BMB_02H8S_02
J6Q_<6<4O_<6<4M_<FI";d=">2414             2M_B=M_B=M_B=M
_B=M_B=M_BN<_LD<_BN<_B=M_B=M_             B=M_B=M_B=M_B=M
_B=M";k="06:_D3H28_D3H28_D3H4               8_06:C<_06:C
          <48=8_D3H48=8_D                     3H68;8_D3HE<_
          06:C<C>_06:C<2M                     _06:7H2K_06:
       7H2I_06:7H2E";
    sp=0x20.chr;f=(f<<                             1&31)+rand(2);aa=p
  roc{|t|t.split('_').map{        |l|l.chars.map{|x|x.ord-0x30}.map.w
  ith_index{|x,i|(i.even?)?(      '#'*x):(sp*x)}.join}.join($/);};c
d=aa[[z,d][f      &1]].gsub('1    2','#'+sp).gsub('#'){c=s.slice!
(0,1);c==''?      '#':c};puts(    "f=#{f};#{cd}");puts;puts(aa[
k]+$/*2)&&ex                      it()if(f==1);;)*""#######

f=28;eval$s=%w(s=%(eval$s=%w(#  {$s} )*""  );z="I24142@_M=>
_M=>_M=?_M?<_0:?E=_0:?E<_07>_             04BMB_02H8S_02
J6Q_<6<4O_<6<4M_<FI";d=">2414             2M_B=M_B=M_B=M
_B=M_B=M_BN<_LD<_BN<_B=M_B=M_             B=M_B=M_B=M_B=M
_B=M";k="06:_D3H28_D3H28_D3H4               8_06:C<_06:C
          <48=8_D3H48=8_D                     3H68;8_D3HE<_
          06:C<C>_06:C<2M                     _06:7H2K_06:
       7H2I_06:7H2E";
    sp=0x20.chr;f=(f<<                             1&31)+rand(2);aa=p
  roc{|t|t.split('_').map{        |l|l.chars.map{|x|x.ord-0x30}.map.w
  ith_index{|x,i|(i.even?)?(      '#'*x):(sp*x)}.join}.join($/);};c
d=aa[[z,d][f      &1]].gsub('1    2','#'+sp).gsub('#'){c=s.slice!
(0,1);c==''?      '#':c};puts(    "f=#{f};#{cd}");puts;puts(aa[
k]+$/*2)&&ex                      it()if(f==1);;)*""#######

f=24;eval$s=%w(s=%(eval$s=%w(#  {$s} )*""  );z="I24142@_M=>
_M=>_M=?_M?<_0:?E=_0:?E<_07>_             04BMB_02H8S_02
J6Q_<6<4O_<6<4M_<FI";d=">2414             2M_B=M_B=M_B=M
_B=M_B=M_BN<_LD<_BN<_B=M_B=M_             B=M_B=M_B=M_B=M
_B=M";k="06:_D3H28_D3H28_D3H4               8_06:C<_06:C
          <48=8_D3H48=8_D                     3H68;8_D3HE<_
          06:C<C>_06:C<2M                     _06:7H2K_06:
       7H2I_06:7H2E";
    sp=0x20.chr;f=(f<<                             1&31)+rand(2);aa=p
  roc{|t|t.split('_').map{        |l|l.chars.map{|x|x.ord-0x30}.map.w
  ith_index{|x,i|(i.even?)?(      '#'*x):(sp*x)}.join}.join($/);};c
d=aa[[z,d][f      &1]].gsub('1    2','#'+sp).gsub('#'){c=s.slice!
(0,1);c==''?      '#':c};puts(    "f=#{f};#{cd}");puts;puts(aa[
k]+$/*2)&&ex                      it()if(f==1);;)*""#######

f=16;eval$s=%w(s=%(eval$s=%w(#  {$s} )*""  );z="I24142@_M=>
_M=>_M=?_M?<_0:?E=_0:?E<_07>_             04BMB_02H8S_02
J6Q_<6<4O_<6<4M_<FI";d=">2414             2M_B=M_B=M_B=M
_B=M_B=M_BN<_LD<_BN<_B=M_B=M_             B=M_B=M_B=M_B=M
_B=M";k="06:_D3H28_D3H28_D3H4               8_06:C<_06:C
          <48=8_D3H48=8_D                     3H68;8_D3HE<_
          06:C<C>_06:C<2M                     _06:7H2K_06:
       7H2I_06:7H2E";
    sp=0x20.chr;f=(f<<                             1&31)+rand(2);aa=p
  roc{|t|t.split('_').map{        |l|l.chars.map{|x|x.ord-0x30}.map.w
  ith_index{|x,i|(i.even?)?(      '#'*x):(sp*x)}.join}.join($/);};c
d=aa[[z,d][f      &1]].gsub('1    2','#'+sp).gsub('#'){c=s.slice!
(0,1);c==''?      '#':c};puts(    "f=#{f};#{cd}");puts;puts(aa[
k]+$/*2)&&ex                      it()if(f==1);;)*""#######

f=1;eval$s=%w(s=%(  eval $s=%  w(#{$s})*"");z="I24142@_M=>_M
=>_M=?_M?<_0:?E=_0             :?E<_07>_04BMB_02H8S_02J6Q_<6
<4O_<6<4M_<FI";d="             >24142M_B=M_B=M_B=M_B=M_B=M_B
N<_LD<_BN<_B=M_B=M             _B=M_B=M_B=M_B=M_B=M";k="06:_
D3H28_D3H28_D3H48_             06:C<_06:C<48=8_D3H48=8_D3H68
;8_D3HE<_06:C<C>_0             6:C<2M_06:7H2K_06:7H2I_06:7H2
E";sp=0x20.chr;f=(                              f<<1&31)+ran
d(2);aa=proc{|t|t.split('_')                    .map{|l|l.ch
ars.map{|x|x.ord-0                              x30}.map.wit
h_index{|x,i|(i.ev             en?)?('#'*x):(sp*x)}.join}.jo
in($/);};cd=aa[[z,             d][f&1]].gsub('12','#'+sp).gs
ub('#'){c=s.slice!             (0,1);c==''?'#':c};puts("f=#{
f};#{cd}");puts;pu             ts(aa[k]+$/*2)&&exit()if(f==1
);;)*""###########             #############################
##################             #############################
##################             #############################

      ##########
####################   ########################  ########
####################   ########################  ########
####################   ########################    ########
      ##########                   ############
      ##########                   ############    ########             ########
####################   ########################    ########             ########
####################   ########################      ########           ########
####################   ########################                     ############
      ##########                   ############                   ##############
      ##########                   ############  #############################
      ##########       ########################  ###########################
      ##########       ########################  #########################
      ##########       ########################  #####################

f=2;eval$s=%w(s=%(eval$s=%w(#  {$s} )*""  );z="I24142@_M=>
_M=>_M=?_M?<_0:?E=_0:?E<_07>_             04BMB_02H8S_02
J6Q_<6<4O_<6<4M_<FI";d=">2414             2M_B=M_B=M_B=M
_B=M_B=M_BN<_LD<_BN<_B=M_B=M_             B=M_B=M_B=M_B=M
_B=M";k="06:_D3H28_D3H28_D3H4               8_06:C<_06:C
          <48=8_D3H48=8_D                     3H68;8_D3HE<_
          06:C<C>_06:C<2M                     _06:7H2K_06:
       7H2I_06:7H2E";
    sp=0x20.chr;f=(f<<                             1&31)+rand(2);aa=p
  roc{|t|t.split('_').map{        |l|l.chars.map{|x|x.ord-0x30}.map.w
  ith_index{|x,i|(i.even?)?(      '#'*x):(sp*x)}.join}.join($/);};c
d=aa[[z,d][f      &1]].gsub('1    2','#'+sp).gsub('#'){c=s.slice!
(0,1);c==''?      '#':c};puts(    "f=#{f};#{cd}");puts;puts(aa[
k]+$/*2)&&ex                      it()if(f==1);;)*""#######

f=5;eval$s=%w(s=%(  eval $s=%  w(#{$s})*"");z="I24142@_M=>_M
=>_M=?_M?<_0:?E=_0             :?E<_07>_04BMB_02H8S_02J6Q_<6
<4O_<6<4M_<FI";d="             >24142M_B=M_B=M_B=M_B=M_B=M_B
N<_LD<_BN<_B=M_B=M             _B=M_B=M_B=M_B=M_B=M";k="06:_
D3H28_D3H28_D3H48_             06:C<_06:C<48=8_D3H48=8_D3H68
;8_D3HE<_06:C<C>_0             6:C<2M_06:7H2K_06:7H2I_06:7H2
E";sp=0x20.chr;f=(                              f<<1&31)+ran
d(2);aa=proc{|t|t.split('_')                    .map{|l|l.ch
ars.map{|x|x.ord-0                              x30}.map.wit
h_index{|x,i|(i.ev             en?)?('#'*x):(sp*x)}.join}.jo
in($/);};cd=aa[[z,             d][f&1]].gsub('12','#'+sp).gs
ub('#'){c=s.slice!             (0,1);c==''?'#':c};puts("f=#{
f};#{cd}");puts;pu             ts(aa[k]+$/*2)&&exit()if(f==1
);;)*""###########             #############################
##################             #############################
##################             #############################

(略)
```

## その他のキヨシ

- [歌うズンドコキヨシ with Ruby](http://qiita.com/hanachin_/items/a4547d88e9008d390f58)
- [ズンドコキヨシオートマトン with Ruby](http://qiita.com/hanachin_/items/2242c7bd33af39cc6cab)
- [ズンドコキヨシマシーン with Ruby](http://qiita.com/hanachin_/items/b037b2e602c0bdee6a89)
- [ズンドコキヨシワンライナー with Ruby](http://qiita.com/hanachin_/items/bad105e11ab707fbaf4c)
- [ズンドコキヨシ物語 with Ruby](http://qiita.com/hanachin_/items/055881be542afceca9d9)