Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Write a program that produces mirror images of itself. An example, would be the fantastic camel code that reads it's own code and produces two smaller 2x2 versions. Given the input:

                                           $_='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

it produces:

        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.

(The copyright text is optional.)

A simpler example would take the input:

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

and produce:

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

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

The entries should demonstrate art.

This is a popularity contest, so the entry with maximum (up)votes wins!

share|improve this question
    
Is the goal here code which just mirrors text, or does it have to be a proper quine? Should it actually take input or not? –  nitro2k01 Mar 2 at 11:55
    
@nitro2k01 It should mirror text; it isn't really expected to be a proper quine. No user input is expected. –  devnull Mar 2 at 12:02
    
Well your camel 3 and 4 should be upside down to be mirror image of camel 1 and 2 ! –  Mukul Kumar Mar 2 at 15:10
    
@MukulKumar Either form is ok as long as the output is artistic. –  devnull Mar 2 at 15:13
7  
I think the title should be changed to "ɟʃǝs uʍo sʇı ɟo sǝƃɐɯı ɹoɹɹıɯ sʇuıɹd ʇɐɥʇ ɯɐɹƃoɹԀ". –  AJMansfield Mar 2 at 16:10
show 2 more comments

5 Answers 5

up vote 13 down vote accepted
+50

Bash and common utils

You may have to install rev

I wasn't satisfied with merely reflecting character positions, it really messes up ascii-art input. So I tried to reflect characters too, modulo the ascii character set.

#!/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)

With no arguments, the script prints itself reflected 2x2, as requested:

$ ./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#
$ 

You may also provide in input filename:

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


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

If the input filename is -, the script will read input from stdin:

$ cowsay moo | ./2x2.sh -
 _____                                                                  _____ 
< moo >                                                                < oom >
 -----                                                                  ----- 
        \   ^__^                                              ^__^   /        
         \  (oo)\_______                              _______/(oo)  /         
            (__)\       )\/\                      /\/(       /(__)            
                ||----w |                            | w----||                
                ||     ||                            ||     ||                
                ||     ||                            ||     ||                
                ||____m |                            | m____||                
            (--)/       )/\/                      \/\(       \(--)            
         /  (oo)/-------                              -------\(oo)  \         
        /   v--v                                              v--v   \        
 _____                                                                  _____ 
< woo >                                                                < oow >
 -----                                                                  ----- 
$ 
share|improve this answer
    
Amazing! You did both in one! Wish I could upvote this n times over. echo +1 | ./2x2.sh - –  devnull Mar 3 at 18:14
    
@devnull I'm not very good at making the code formatting look pretty, but what I really like is that a back-to-front cow says oom and an upside-down cow says woo –  DigitalTrauma Mar 3 at 18:15
    
You've made the perfect use of what they call useless use of cat. –  devnull Mar 3 at 18:21
1  
Oh! I do understand bash a bit to figure it out :-) (What I meant by in my previous comment was: cat is damn useful in certain situations) –  devnull Mar 3 at 18:31
1  
@devnull agreed - cat has a bad name IMO, and I will shamelessly use it where I think it is appropriate ;-) –  DigitalTrauma Mar 3 at 18:40
show 1 more comment

Ruby

This one definitely took me a while. But it was really fun!

#                                  
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}*                          
'' +                            
''+                              
''                                
#                                  

Output:

#                                   #
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=                                 ''
#                                   #

screenshot

It's based on the same idea as my previous answer.

share|improve this answer
    
Aha! this is extremely pretty. –  devnull Mar 3 at 3:26
add comment

Ruby

UPDATE: Check out my new answer, based on the same idea as this one!

$,                                    |
   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|]/,'')

Output:

$,                                    | 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|]/,'')

It's "PPCG!" in ASCII art! :D

Here's a detailed explanation. First, I found out how to do the actual mirroring. Here's the mirroring code:

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

Then I had to remove whitespace characters and double quotes (because escaping just gets messy), so I used Ruby's Fixnum#chr.

The basic structure of the program is now:

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

Now I can make it into ASCII art! So, that's what I did. Then, I padded the ASCII art with spaces and |s at the end, and I made it to here:

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|]/,'')

However, that looked a bit ugly, since there wasn't enough padding around the ASCII art. Therefore, I added a bit of extra padding, and got where I am now! ($, | x is equivalent to x since $, is nil by default.)

share|improve this answer
    
This is artistic! –  devnull Mar 2 at 14:49
    
Didn't notice the evil eval earlier :) –  devnull Mar 2 at 17:34
add comment

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)

Sample useable

#!/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)

Sample detailed:

#!/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.

This could result as:

./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/!#

or formated to fixed line width:

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

give:

#!/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/!#

and using figlet:

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


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

And for fun:

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

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

He, he... This could not work because of half-chars could not be simply reversed.

For this, we have to run command in reversed order:

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

code golf mirrored and reduced

share|improve this answer
    
Is this '▝' intentional or means unknown character ? –  Mukul Kumar Mar 2 at 13:15
    
Still can't understand that ;( –  Mukul Kumar Mar 2 at 13:34
    
+1. My guess for the downvote is your first example output doesn't do the padding, and the downvoter didn't bother reading further. I see you go on to implement padding, so personally I would edit the answer just to include that. –  DigitalTrauma Mar 3 at 18:24
add comment

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;
}  

output

This output looks like "Windows 4X4".

enter image description here

share|improve this answer
    
No one likes my post ... T_T why ? –  Mukul Kumar Mar 2 at 14:53
    
Maybe because it hardcodes (!) the output in CP-437 (!)? Also it's only an hour old. –  mniip Mar 2 at 14:59
    
@mniip doorknob's post is only 12 minutes old! –  Mukul Kumar Mar 2 at 15:04
1  
I don't know why, but people vote for the high-rep users quicker. I will vote for you as soon as I get my voting power back. –  hosch250 Mar 2 at 18:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.