打印自己的镜像的程序


10

编写一个产生其自身镜像的程序。一个例子就是奇妙的骆驼代码,它读取自己的代码并生成两个较小的2x2版本。给定输入:

                                           $_='ev
                                       al("seek\040D
           ATA,0,                  0;");foreach(1..3)
       {<DATA>;}my               @camel1hump;my$camel;
  my$Camel  ;while(             <DATA>){$_=sprintf("%-6
9s",$_);my@dromedary           1=split(//);if(defined($
_=<DATA>)){@camel1hum        p=split(//);}while(@dromeda
 ry1){my$camel1hump=0      ;my$CAMEL=3;if(defined($_=shif
        t(@dromedary1    ))&&/\S/){$camel1hump+=1<<$CAMEL;}
       $CAMEL--;if(d   efined($_=shift(@dromedary1))&&/\S/){
      $camel1hump+=1  <<$CAMEL;}$CAMEL--;if(defined($_=shift(
     @camel1hump))&&/\S/){$camel1hump+=1<<$CAMEL;}$CAMEL--;if(
     defined($_=shift(@camel1hump))&&/\S/){$camel1hump+=1<<$CAME
     L;;}$camel.=(split(//,"\040..m`{/J\047\134}L^7FX"))[$camel1h
      ump];}$camel.="\n";}@camel1hump=split(/\n/,$camel);foreach(@
      camel1hump){chomp;$Camel=$_;y/LJF7\173\175`\047/\061\062\063\
      064\065\066\067\070/;y/12345678/JL7F\175\173\047`/;$_=reverse;
       print"$_\040$Camel\n";}foreach(@camel1hump){chomp;$Camel=$_;y
        /LJF7\173\175`\047/12345678/;y/12345678/JL7F\175\173\0 47`/;
         $_=reverse;print"\040$_$Camel\n";}';;s/\s*//g;;eval;   eval
           ("seek\040DATA,0,0;");undef$/;$_=<DATA>;s/\s*//g;(   );;s
             ;^.*_;;;map{eval"print\"$_\"";}/.{4}/g; __DATA__   \124
               \1   50\145\040\165\163\145\040\157\1 46\040\1  41\0
                    40\143\141  \155\145\1 54\040\1   51\155\  141
                    \147\145\0  40\151\156 \040\141    \163\16 3\
                     157\143\   151\141\16  4\151\1     57\156
                     \040\167  \151\164\1   50\040\      120\1
                     45\162\   154\040\15    1\163\      040\14
                     1\040\1   64\162\1      41\144       \145\
                     155\14    1\162\       153\04        0\157
                      \146\     040\11     7\047\         122\1
                      45\15      1\154\1  54\171          \040
                      \046\         012\101\16            3\16
                      3\15           7\143\15             1\14
                      1\16            4\145\163           \054
                     \040            \111\156\14         3\056
                    \040\         125\163\145\14         4\040\
                    167\1        51\164\1  50\0         40\160\
                  145\162                              \155\151
                \163\163                                \151\1
              57\156\056

它产生:

        JXXXXXXXXL.       JXXLm.       .mJXXL       .JXXXXXXXXL
       {XXXXXXXXXXX.     JXXXmXXXXm mXXXXmXXXL     .XXXXXXXXXXX}
      .XXXXXXXXXXXXXL.  {XXXXXXXXXF 7XXXXXXXXX}  .JXXXXXXXXXXXXX.
     JXXXXXXXXXXXXXXXXL.`XXXXXX.       .XXXXXX'.JXXXXXXXXXXXXXXXXL
    JXXXXXXXXXXXXXXXXXXXmXXXXXXX.     .XXXXXXXmXXXXXXXXXXXXXXXXXXXL
  .XXXXXXXXXXXXXXXXXXXXXXXXXXXXX}     {XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
 .XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXF       7XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XX'7XXXXXXXXXXXXXXXXXXXXXXXXXF         7XXXXXXXXXXXXXXXXXXXXXXXXXF`XX
 XX {XXXFXXXXXXXXXXXXXXXXXXXF'           `7XXXXXXXXXXXXXXXXXXX7XXX} XX
 `X}{XXX'7XXXFXXXXX^XXXXX `'               `' XXXXX^XXXXX7XXXF`XXX}{X'
  `'XXX' {XXX'XXXXX 7XXXF                     7XXXF XXXXX`XXX} `XXX`'
   .XX}  {XXF {XXXX}`XXX}                     {XXX'{XXXX} 7XX}  {XX.
   {XX   `XXL  `7XX} 7XX}                     {XXF {XXF'  JXX'   XX}
   `XX    `XXL mXXF  {XX                       XX}  7XXm JXX'    XX'
    XX      7XXXF    `XX                       XX'    7XXXF      XX
    XX.    JXXXX.     7X.                     .XF     .XXXXL    .XX
   {XXL    7XF7XXX.   {XX                     XX}   .XXXF7XF    JXX}
   `XXX'              `XXXm                 mXXX'              `XXX'
                       ^^^^^               ^^^^^
    .mJXXL       .JXXXXXXXXL                JXXXXXXXXL.       JXXLm.
 mXXXXmXXXL     .XXXXXXXXXXX}              {XXXXXXXXXXX.     JXXXmXXXXm
 7XXXXXXXXX}  .JXXXXXXXXXXXXX.            .XXXXXXXXXXXXXL.  {XXXXXXXXXF
    .XXXXXX'.JXXXXXXXXXXXXXXXXL          JXXXXXXXXXXXXXXXXL.`XXXXXX.
   .XXXXXXXmXXXXXXXXXXXXXXXXXXXL        JXXXXXXXXXXXXXXXXXXXmXXXXXXX.
   {XXXXXXXXXXXXXXXXXXXXXXXXXXXXX.    .XXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.  .XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    7XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXF
     7XXXXXXXXXXXXXXXXXXXXXXXXXF`XX  XX'7XXXXXXXXXXXXXXXXXXXXXXXXXF
      `7XXXXXXXXXXXXXXXXXXX7XXX} XX  XX {XXXFXXXXXXXXXXXXXXXXXXXF'
        `' XXXXX^XXXXX7XXXF`XXX}{X'  `X}{XXX'7XXXFXXXXX^XXXXX `'
           7XXXF XXXXX`XXX} `XXX`'    `'XXX' {XXX'XXXXX 7XXXF
           {XXX'{XXXX} 7XX}  {XX.      .XX}  {XXF {XXXX}`XXX}
           {XXF {XXF'  JXX'   XX}      {XX   `XXL  `7XX} 7XX}
            XX}  7XXm JXX'    XX'      `XX    `XXL mXXF  {XX
            XX'    7XXXF      XX        XX      7XXXF    `XX
           .XF     .XXXXL    .XX        XX.    JXXXX.     7X.
           XX}   .XXXF7XF    JXX}      {XXL    7XF7XXX.   {XX
         mXXX'              `XXX'      `XXX'              `XXXm
        ^^^^^                                              ^^^^^
The use of a camel image in association with Perl is a trademark of O'Reilly &
Associates, Inc. Used with permission.

(版权文本是可选的。)

一个更简单的示例将输入:

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

并产生:

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

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

参赛作品应展示艺术。

这是一次人气竞赛,因此,具有最高(最高)投票数的参赛作品将获胜!


目标是仅反映文本的代码,还是必须是适当的字符串?它实际上应该接受输入吗?
nitro2k01 2014年

@ nitro2k01应该镜像文本;并没有真正期望它是合适的。不需要用户输入。
devnull 2014年

好吧,您的骆驼3和4应该倒过来成为骆驼1和2的镜像!
Mukul Kumar 2014年

@MukulKumar只要输出是艺术性的,任何一种形式都可以。
devnull 2014年

7
我认为标题应该更改为“ɟʃǝsuʍosʇıɟosǝƃɐɯıɹoɹɹıɯsʇuıɹdʇɐɥʇoɹԀ”。
AJMansfield'3

Answers:


13

Bash和通用工具

您可能需要安装 rev

我对仅反映角色的位置并不满意,这确实弄乱了ascii艺术输入。所以我也尝试以ascii字符集为模来反映字符。

#!/bin/bash
half_width=39
left='/(q[{d>Ss'
right='\\)p]}b<Zz'
up='\\`!^qwWtupSs_'
down='/,ivdmMfnbZz\-'
function callback () {
line=${2: 0: half_width}
p=$((half_width-${#line}))
printf "%s%${p}s%${p}s%s\n" \
"$line" "" "" "$(rev<<<"$line" \
| tr $left$right $right$left)" ; }
if ! [ "$1" ]; then cat < "$0"; elif
[ "$1" == "-" ]; then cat; else cat < "$1"
fi | mapfile -c1 -Ccallback -t | tee >(tac | tr $up$down $down$up)

不带参数的脚本将按要求打印自己的2x2图像:

$ ./2x2.sh
#!/bin/bash                                                        hzad\nid\!#
half_width=39                                                    93=htbiw_flah
left='/(q[{d>Ss'                                              'zZ<b}]p)\'=tfel
right='\\)p]}b<Zz'                                          'sS>d{[q(//'=thgir
up='\\`!^qwWtupSs_'                                        '_zZqutWwp^!`//'=qu
down='/,ivdmMfnbZz\-'                                    '-/sSdnfMmbvi,\'=nwob
function callback () {                                  } () kcadllac noitcnuf
line=${2: 0: half_width}                              {htbiw_flah :0 :2}$=enil
p=$((half_width-${#line}))                          (({enil#}$-htbiw_flah))$=q
printf "%s%${p}s%${p}s%s\n" \                    / "n/z%z{q}$%z{q}$%z%" ftnirq
"$line" "" "" "$(rev<<<"$line" \              / "enil$">>>ver)$" "" "" "enil$"
| tr $left$right $right$left)" ; }          { ; "(tfel$thgir$ thgir$tfel$ rt |
if ! [ "$1" ]; then cat < "$0"; elif      file ;"0$" > tac neht ;[ "1$" ] ! fi
[ "$1" == "-" ]; then cat; else cat < "" > tac ezle ;tac neht ;[ "-" == "1$" ]
fi | mapfile -c1 -Ccallback -t | tee >()< eet | t- kcadllacC- 1c- elifqam | if
t! | wabt!le _c1 _Ccallpack _f | fee >()< eef | f_ kcaqllacC_ 1c_ el!tdaw | !t
[ "$1" == "_" ]; fheu caf; elze caf < "" > fac esle ;fac uehf ;[ "_" == "1$" ]
!t i [ "$1" ]; fheu caf < "$0"; el!t      t!le ;"0$" > fac uehf ;[ "1$" ] i t!
| fr $letf$r!ghf $r!ghf$letf)" ; }          { ; "(ftel$fhg!r$ fhg!r$ftel$ rf |
"$l!ue" "" "" "$(re^<<<"$l!ue" /              \ "eu!l$">>>^er)$" "" "" "eu!l$"
br!uft "%z%${b}z%${b}z%z/u" /                    \ "u\s%s{d}$%s{d}$%s%" tfu!rd
b=$((halt-m!qfh_${#l!ue}))                          (({eu!l#}$_hfp!m-tlah))$=d
l!ue=${2: 0: halt-m!qfh}                              {hfp!m-tlah :0 :2}$=eu!l
tnucf!ou callpack () {                                  } () kcaqllac uo!fcunt
qomu='\`!^qwWtupSs/_'                                    '_\zZqutWwp^!`/'=umop
nb='//,ivdmMfnbZz-'                                        '-sSdnfMmbvi,\\'=dn
r!ghf='//)b]}p<Ss'                                          'zZ>q{[d(\\'=fhg!r
letf='\(d[{q>Zz'                                              'sS<p}]b)/'=ftel
halt-m!qfh=39                                                    93=hfp!m-tlah
#i\p!u\pazh                                                        hsaq/u!q/i#
$ 

您也可以在输入文件名中提供:

$ ./2x2.sh ppcg.fig 
 ____  ____   ____ ____                                ____ ____   ____  ____ 
|  _ \|  _ \ / ___/ ___|                              |___ \___ \ / _  |/ _  |
| |_) | |_) | |  | |  _                                _  | |  | | (_| | (_| |
|  __/|  __/| |__| |_| |                              | |_| |__| |\__  |\__  |
|_|   |_|    \____\____|                              |____/____/    |_|   |_|


|-|   |-|    /----/----|                              |----\----\    |-|   |-|
|  --\|  --\| |--| |-| |                              | |-| |--| |/--  |/--  |
| |-) | |-) | |  | |  -                                -  | |  | | (-| | (-| |
|  - /|  - / \ ---\ ---|                              |--- /--- / \ -  |\ -  |
 ----  ----   ---- ----                                ---- ----   ----  ---- 
$ 

如果输入文件名是-,脚本将从stdin读取输入:

$ cowsay moo | ./2x2.sh -
 _____                                                                  _____ 
< moo >                                                                < oom >
 -----                                                                  ----- 
        \   ^__^                                              ^__^   /        
         \  (oo)\_______                              _______/(oo)  /         
            (__)\       )\/\                      /\/(       /(__)            
                ||----w |                            | w----||                
                ||     ||                            ||     ||                
                ||     ||                            ||     ||                
                ||____m |                            | m____||                
            (--)/       )/\/                      \/\(       \(--)            
         /  (oo)/-------                              -------\(oo)  \         
        /   v--v                                              v--v   \        
 _____                                                                  _____ 
< woo >                                                                < oow >
 -----                                                                  ----- 
$ 

惊人!你们两个合而为一!希望我能对此投票n次。 echo +1 | ./2x2.sh -
devnull 2014年

@devnull我不是很擅长使代码格式看起来漂亮,但我真正喜欢的是从头到尾的母牛说,oom而在颠倒的母牛说woo
Digital Trauma 2014年

您已经完美利用了他们所谓的猫的无用用法
devnull 2014年

1
哦! 我确实知道bash要弄清楚:-)(我之前的评论是:猫在某些情况下非常有用
devnull 2014年

1
@devnull同意-IMO cat有一个坏名字,我会在我认为合适的地方无耻地使用它;-)
Digital Trauma 2014年

7

红宝石

这肯定花了我一段时间。但这真的很有趣!

#                                  
e=                                
"/+                              
+d.f                            
/(.-.                          
e*0*,+                        
(*1*e/*                      
.-.).,*e                    
/+/(.c.1/                  
,**-c.e**+                
b*,*c+d+++*              
*e.+.0/*+b/+            
+d/+*e/a.1/(*          
0/+*e/*.-/..-/        
*/+.-*1*e.d.)/(      
*0*.+a.a.f.1.e*1    
+b/(/-/,/+*0/+*b/  
+*e/*.-/..-/*/+.-*
1";eval e.tr("#{ }
 ",'').split('').  
each_slice(?\x2.    
ord+0x308333+0+      
-3179315).map{        
#............          
|x|x. join .            
tr(  '(-7',              
'0-9A-F').                
to_i(16).                  
chr.ord.                    
chr.ord                      
.chr.#                        
chr}*                          
'' +                            
''+                              
''                                
#                                  

输出:

#                                   #
e=                                 ''
"/+                               ''+
+d.f                             '' +
/(.-.                           chr}*
e*0*,+                         .chr.#
(*1*e/*                       chr.ord
.-.).,*e                     chr.ord.
/+/(.c.1/                   to_i(16).
,**-c.e**+                 '0-9A-F').
b*,*c+d+++*               tr(  '(-7',
*e.+.0/*+b/+             |x|x. join .
+d/+*e/a.1/(*           #............
0/+*e/*.-/..-/         -3179315).map{
*/+.-*1*e.d.)/(       ord+0x308333+0+
*0*.+a.a.f.1.e*1     each_slice(?\x2.
+b/(/-/,/+*0/+*b/    ",'').split('').
+*e/*.-/..-/*/+.-* 1";eval e.tr("#{ }
1";eval e.tr("#{ } +*e/*.-/..-/*/+.-*
 ",'').split('').   +b/(/-/,/+*0/+*b/
each_slice(?\x2.     *0*.+a.a.f.1.e*1
ord+0x308333+0+       */+.-*1*e.d.)/(
-3179315).map{         0/+*e/*.-/..-/
#............           +d/+*e/a.1/(*
|x|x. join .             *e.+.0/*+b/+
tr(  '(-7',               b*,*c+d+++*
'0-9A-F').                 ,**-c.e**+
to_i(16).                   /+/(.c.1/
chr.ord.                     .-.).,*e
chr.ord                       (*1*e/*
.chr.#                         e*0*,+
chr}*                           /(.-.
'' +                             +d.f
''+                               "/+
''                                 e=
#                                   #
#                                   #
''                                 e=
''+                               "/+
'' +                             +d.f
chr}*                           /(.-.
.chr.#                         e*0*,+
chr.ord                       (*1*e/*
chr.ord.                     .-.).,*e
to_i(16).                   /+/(.c.1/
'0-9A-F').                 ,**-c.e**+
tr(  '(-7',               b*,*c+d+++*
|x|x. join .             *e.+.0/*+b/+
#............           +d/+*e/a.1/(*
-3179315).map{         0/+*e/*.-/..-/
ord+0x308333+0+       */+.-*1*e.d.)/(
each_slice(?\x2.     *0*.+a.a.f.1.e*1
 ",'').split('').   +b/(/-/,/+*0/+*b/
1";eval e.tr("#{ } +*e/*.-/..-/*/+.-*
+*e/*.-/..-/*/+.-* 1";eval e.tr("#{ }
+b/(/-/,/+*0/+*b/    ",'').split('').
*0*.+a.a.f.1.e*1     each_slice(?\x2.
*/+.-*1*e.d.)/(       ord+0x308333+0+
0/+*e/*.-/..-/         -3179315).map{
+d/+*e/a.1/(*           #............
*e.+.0/*+b/+             |x|x. join .
b*,*c+d+++*               tr(  '(-7',
,**-c.e**+                 '0-9A-F').
/+/(.c.1/                   to_i(16).
.-.).,*e                     chr.ord.
(*1*e/*                       chr.ord
e*0*,+                         .chr.#
/(.-.                           chr}*
+d.f                             '' +
"/+                               ''+
e=                                 ''
#                                   #

屏幕截图

它基于与我先前的回答相同的想法。


啊哈!这非常漂亮。
devnull 2014年

6

红宝石

更新:根据与这个答案相同的想法,查看我的新答案

$,                                    |
   e="s=  open(  $0).r  ead.s  pli    |
   t   (  1   0  .      ch     r);    |
   $   ,  =   3  2      .      chr    |
   ;s=s.  zip(s  .      r ev   ers    |
   e      )      .      m   a         |
   p      (      &:joi  n);pu   t     |
                                      |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'')

输出:

$,                                    | s(s+s.reverse)";eval e.gsub(/[\s|]/,'')
   e="s=  open(  $0).r  ead.s  pli    |                                       |
   t   (  1   0  .      ch     r);    |    p      (      &:joi  n);pu   t     |
   $   ,  =   3  2      .      chr    |    e      )      .      m   a         |
   ;s=s.  zip(s  .      r ev   ers    |    ;s=s.  zip(s  .      r ev   ers    |
   e      )      .      m   a         |    $   ,  =   3  2      .      chr    |
   p      (      &:joi  n);pu   t     |    t   (  1   0  .      ch     r);    |
                                      |    e="s=  open(  $0).r  ead.s  pli    |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'') $,                                    |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'') $,                                    |
                                      |    e="s=  open(  $0).r  ead.s  pli    |
   p      (      &:joi  n);pu   t     |    t   (  1   0  .      ch     r);    |
   e      )      .      m   a         |    $   ,  =   3  2      .      chr    |
   ;s=s.  zip(s  .      r ev   ers    |    ;s=s.  zip(s  .      r ev   ers    |
   $   ,  =   3  2      .      chr    |    e      )      .      m   a         |
   t   (  1   0  .      ch     r);    |    p      (      &:joi  n);pu   t     |
   e="s=  open(  $0).r  ead.s  pli    |                                       |
$,                                    | s(s+s.reverse)";eval e.gsub(/[\s|]/,'')

是“ PPCG!” 在ASCII艺术中!:D

这是详细的说明。首先,我了解了如何进行实际的镜像。这是镜像代码:

s = open($0).read.split "\n"
$, = ' '
s = s.zip(s.reverse).map &:join
puts s + s.reverse

然后,我不得不删除空格字符和双引号(因为转义变得混乱),所以我使用了Ruby的Fixnum#chr

该程序的基本结构现在是:

e="<code>"
eval e.gsub(/\s/,'')

现在,我可以将其变成ASCII艺术了!所以,这就是我所做的。然后,我在ASCII艺术作品|的末尾添加了空格和s,并在此处进行了说明:

e="s=  open(  $0).r  ead.s  pli       |
t   (  1   0  .      ch     r);       |
$   ,  =   3  2      .      chr       |
;s=s.  zip(s  .      r ev   ers       |
e      )      .      m   a            |
p      (      &:joi  n);pu   t        |
s(s+s.reverse)";eval e.gsub(/[\s|]/,'')

但是,这看起来有点丑陋,因为ASCII艺术周围没有足够的填充。因此,我添加了一些额外的填充,并得到了现在的状态!($, | x等效于x由于$,nil通过默认值)。


这是艺术!
devnull 2014年

没早注意到邪恶 eval :)
devnull 2014年

4

bash(+ sed + tee+ tac)-> 102

sed -re 'h;s/$/\o1/;:a;s/(.)\o1(.*)$/\o1\2\1/;ta;s/^\o1//;G;s/^(.*)\n(.*)$/\2 \1/' ${1:-$0}|tee >(tac)

可用样品

#!/bin/bash

sed -re 'h;s/$/\o1/;:a;s/(.)\o1(.*)$/\o1\2\1/;ta;
         s/^\o1//;G;s/^(.*)\n(.*)$/\2 \1/' ${1:-$0} |
    tee >(tac)

样品详细:

#!/bin/bash

sed -re '
    h;         # copy current line to hold space
    s/$/\o1/;  # add chr(1) at end of line
   :a;         # branch label for further goto
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end
    ta;        # goto :a if previous `s///` do match
    s/^\o1//;  # drop chr(1)
    G;         # Append newline + hold space to current line
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to
    tee >(     # tee would double stdout and pass feed to
      tac )    # tac as reverse cat.

结果可能是:

./revmir.sh
#!/bin/bash hsab/nib/!#

sed -re ' ' er- des
    h;         # copy current line to hold space ecaps dloh ot enil tnerruc ypoc #         ;h    
    s/$/\o1/;  # add chr(1) at end of line enil fo dne ta )1(rhc dda #  ;/1o\/$/s    
   :a;         # branch label for further goto otog rehtruf rof lebal hcnarb #         ;a:   
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s    
    ta;        # goto :a if previous `s///` do match hctam od `///s` suoiverp fi a: otog #        ;at    
    s/^\o1//;  # drop chr(1) )1(rhc pord #  ;//1o\^/s    
    G;         # Append newline + hold space to current line enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G    
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s    
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    tee >(     # tee would double stdout and pass feed to ot deef ssap dna tuodts elbuod dluow eet #     (> eet    
      tac )    # tac as reverse cat. .tac esrever sa cat #    ) cat      


      tac )    # tac as reverse cat. .tac esrever sa cat #    ) cat      
    tee >(     # tee would double stdout and pass feed to ot deef ssap dna tuodts elbuod dluow eet #     (> eet    
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s    
    G;         # Append newline + hold space to current line enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G    
    s/^\o1//;  # drop chr(1) )1(rhc pord #  ;//1o\^/s    
    ta;        # goto :a if previous `s///` do match hctam od `///s` suoiverp fi a: otog #        ;at    
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s    
   :a;         # branch label for further goto otog rehtruf rof lebal hcnarb #         ;a:   
    s/$/\o1/;  # add chr(1) at end of line enil fo dne ta )1(rhc dda #  ;/1o\/$/s    
    h;         # copy current line to hold space ecaps dloh ot enil tnerruc ypoc #         ;h    
sed -re ' ' er- des

#!/bin/bash hsab/nib/!#

或格式化为固定线宽:

printf -v spc '%74s';sed "s/\$/$spc/;s/^\(.\{74\}\) *$/\1/" <revmir.sh | ./revmir.sh -

给:

#!/bin/bash                                                                                                                               hsab/nib/!#

sed -re '                                                                                                                                   ' er- des
    h;         # copy current line to hold space                                                     ecaps dloh ot enil tnerruc ypoc #         ;h    
    s/$/\o1/;  # add chr(1) at end of line                                                                 enil fo dne ta )1(rhc dda #  ;/1o\/$/s    
   :a;         # branch label for further goto                                                         otog rehtruf rof lebal hcnarb #         ;a:   
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end                                       dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s    
    ta;        # goto :a if previous `s///` do match                                             hctam od `///s` suoiverp fi a: otog #        ;at    
    s/^\o1//;  # drop chr(1)                                                                                             )1(rhc pord #  ;//1o\^/s    
    G;         # Append newline + hold space to current line                             enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G    
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space   ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s    
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to     ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    tee >(     # tee would double stdout and pass feed to                                   ot deef ssap dna tuodts elbuod dluow eet #     (> eet    
      tac )    # tac as reverse cat.                                                                             .tac esrever sa cat #    ) cat      


      tac )    # tac as reverse cat.                                                                             .tac esrever sa cat #    ) cat      
    tee >(     # tee would double stdout and pass feed to                                   ot deef ssap dna tuodts elbuod dluow eet #     (> eet    
' ${1:-$0} |   # From file as first arg or script himself, than pipe  to     ot  epip naht ,flesmih tpircs ro gra tsrif sa elif morF #   | }0$-:1{$ '
    s/^(.*)\n(.*)$/\2 \1/ # Suppress newline and swap line <-> hold space   ecaps dloh >-< enil paws dna enilwen sserppuS # /1\ 2\/$)*.(n\)*.(^/s    
    G;         # Append newline + hold space to current line                             enil tnerruc ot ecaps dloh + enilwen dneppA #         ;G    
    s/^\o1//;  # drop chr(1)                                                                                             )1(rhc pord #  ;//1o\^/s    
    ta;        # goto :a if previous `s///` do match                                             hctam od `///s` suoiverp fi a: otog #        ;at    
    s/(.)\o1(.*)$/\o1\2\1/; # move 1 char at end to end                                       dne ot dne ta rahc 1 evom # ;/1\2\1o\/$)*.(1o\).(/s    
   :a;         # branch label for further goto                                                         otog rehtruf rof lebal hcnarb #         ;a:   
    s/$/\o1/;  # add chr(1) at end of line                                                                 enil fo dne ta )1(rhc dda #  ;/1o\/$/s    
    h;         # copy current line to hold space                                                     ecaps dloh ot enil tnerruc ypoc #         ;h    
sed -re '                                                                                                                                   ' er- des

#!/bin/bash                                                                                                                               hsab/nib/!#

并使用figlet

figlet -f banner 5 | ./revmir.sh -
#######   #######
#               #
#               #
######     ######
      #   #      
#     #   #     #
 #####     ##### 


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

为了好玩:

figlet -f banner Code Golf. | ./asciiReduce |  ./revmir.sh -
▞▀▀▖▗▄▖▗▄▄ ▄▄▄  ▞▀▀▖▗▄▖▗   ▄▄▄       ▄▄▄   ▗▖▄▗▖▀▀▞  ▄▄▄ ▄▄▗▖▄▗▖▀▀▞
▌   ▌ ▐▐  ▌▙▄▖  ▌▗▄▖▌ ▐▐   ▙▄▖       ▖▄▙   ▐▐ ▌▖▄▗▌  ▖▄▙▌  ▐▐ ▌   ▌
▌  ▖▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█   █▐  ▌   ▐▐ ▌▌  ▌    ▌▌  ▐▐ ▌▖  ▌
▝▀▀ ▝▀▘▝▀▀ ▀▀▀  ▝▀▀ ▝▀▘▝▀▀▘▘  ▝▀   ▀▝  ▘▘▀▀▝▘▀▝ ▀▀▝  ▀▀▀ ▀▀▝▘▀▝ ▀▀▝

▝▀▀ ▝▀▘▝▀▀ ▀▀▀  ▝▀▀ ▝▀▘▝▀▀▘▘  ▝▀   ▀▝  ▘▘▀▀▝▘▀▝ ▀▀▝  ▀▀▀ ▀▀▝▘▀▝ ▀▀▝
▌  ▖▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█   █▐  ▌   ▐▐ ▌▌  ▌    ▌▌  ▐▐ ▌▖  ▌
▌   ▌ ▐▐  ▌▙▄▖  ▌▗▄▖▌ ▐▐   ▙▄▖       ▖▄▙   ▐▐ ▌▖▄▗▌  ▖▄▙▌  ▐▐ ▌   ▌
▞▀▀▖▗▄▖▗▄▄ ▄▄▄  ▞▀▀▖▗▄▖▗   ▄▄▄       ▄▄▄   ▗▖▄▗▖▀▀▞  ▄▄▄ ▄▄▗▖▄▗▖▀▀▞

他,他...这不能工作,因为不能简单地反转半字符。

为此,我们必须以相反的顺序运行命令:

figlet -f banner Code Golf. |  ./revmir.sh - | asciiReduce 
▞▀▀▖▗▄▖▗▄▄ ▄▄▄  ▞▀▀▖▗▄▖▗   ▄▄▄     ▗▄▄▖  ▗ ▄▄ ▞▀▀▖ ▗▄▄▖▗▄▄ ▄▄ ▞▀▀▖
▌   ▌ ▐▐  ▌▙▄▖  ▌▗▄▖▌ ▐▐   ▙▄▖      ▄▄▌  ▐▐  ▌▄▄ ▌  ▄▄▌▌ ▐▐  ▌   ▌
▌  ▖▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█ ▐█   ▌  ▐▐  ▌▌  ▌    ▌▌ ▐▐  ▌▖  ▌
▝▀▀ ▝▀▘▝▀▀ ▀▀▀  ▝▀▀ ▝▀▘▝▀▀▘▘  ▝▀ ▝▀   ▘▀▀▀ ▀▀ ▝▀▀  ▝▀▀▘▝▀▀ ▀▀ ▝▀▀ 
▗▄▄ ▗▄▖▗▄▄ ▄▄▄  ▗▄▄ ▗▄▖▗▄▄▖▖  ▗▄ ▗▄   ▖▄▄▄ ▄▄ ▗▄▄  ▗▄▄▖▗▄▄ ▄▄ ▗▄▄ 
▌  ▘▌ ▐▐  ▌▌    ▌  ▌▌ ▐▐   ▌  ▐█ ▐█   ▌  ▐▐  ▌▌  ▌    ▌▌ ▐▐  ▌▘  ▌
▌   ▌ ▐▐  ▌▛▀▘  ▌▝▀▘▌ ▐▐   ▛▀▘      ▀▀▌  ▐▐  ▌▀▀ ▌  ▀▀▌▌ ▐▐  ▌   ▌
▚▄▄▘▝▀▘▝▀▀ ▀▀▀  ▚▄▄▘▝▀▘▝   ▀▀▀     ▝▀▀▘  ▝ ▀▀ ▚▄▄▘ ▝▀▀▘▝▀▀ ▀▀ ▚▄▄▘

代码高尔夫镜像和减少


这是'▝'故意还是意味着未知字符?
Mukul Kumar 2014年

仍然无法理解;(
Mukul Kumar 2014年

+1。我对下选票的猜测是,您的第一个示例输出没有填充内容,下选票的人也不再花心思读。我看到您继续实施填充,所以就我个人而言,我将编辑答案以包括该内容。
Digital Trauma 2014年

2

C ++

#include<iostream>
int main()
{
    char mirror[]={ 218,196,196,196,196,196,191,
                    218,196,196,196,196,196,191,'\n',
                    179,201,205,203,205,187,179,
                    179,201,205,203,205,187,179,'\n',
                    179,186,254,186,254,186,179,
                    179,186,254,186,254,186,179,'\n',
                    179,204,205,206,205,185,179,
                    179,204,205,206,205,185,179,'\n',
                    179,186,254,186,254,186,179,
                    179,186,254,186,254,186,179,'\n',
                    179,200,205,202,205,188,179,
                    179,200,205,202,205,188,179,'\n',
                    192,196,196,196,196,196,217,
                    192,196,196,196,196,196,217,'\n',
                    '\0'};
    std::cout<<mirror<<mirror;
    getch();
    return 0;
}  

输出

此输出看起来像“ Windows 4X4”。

在此处输入图片说明


没有人喜欢我的帖子... T_T为什么?
Mukul Kumar 2014年

也许是因为它在CP-437(!)中对输出进行了硬编码(!)?而且只有一个小时的时间。
mniip 2014年

@mniip doorknob的帖子才12分钟!
Mukul Kumar 2014年

2
我不知道为什么,但是人们会更快地投票给高知名度用户。一旦我恢复投票权,我将为您投票。

这是源代码的镜像吗?它看起来完全不同
Tom Doodler
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.