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.

I am not sure if this is possible. I have tried it and couldn't make it work at all, but I am being hopeful.

If this is not possible please flag this question and I will promptly delete it.

Conditions are simple,

Write code that will output same amount of character in the same shape as the code.

For example (A very stupid example).

If code says

#include<stdio.h>

main()
{
    printf("Hello World");
}

Then output must be

kjh#$@#)(12398n,s

lkrjop
t
    jherl;k@&##*$&@3n,2m$*
t

I really do not care which characters are being used in the output or anything like that except that space is space and tab is tab. So whatever is the shape of the code, the output should be the same.

Winner: Either popularity , or help me decide the criteria.

The only way I managed to make this work, is I created a file reader that reads the code and does rot13 on every character in the code and prints it out. However I was not fond of it, because the shape was not interesting, nor do I want to use file reader to do something like this because it is too easy.

share|improve this question
 
"Most complex and interesting" aren't exactly objective judging criteria. –  Iszi Nov 22 '13 at 16:07
 
@Iszi please let me know what you think I should have as winning criteria? I was having a big difficulty deciding. –  Quillion Nov 22 '13 at 16:23
1  
The problem is that the 'coolest' shape is subjective: for example if there's a circle and a triangle as code, then perhaps you like the triangle but I like the circle. An objective winning criteria is a criteria where the opinion of someone doesn't matter. –  ProgramFOX Nov 22 '13 at 16:37
1  
@Iszi ok I gave what shape to make. –  Quillion Nov 22 '13 at 17:19
1  
If you do not care about the characters being used, any quine will pass your conditions, right? –  saeedn Nov 24 '13 at 6:47
show 20 more comments

closed as off-topic by Chris Jester-Young Dec 9 '13 at 16:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." – Chris Jester-Young
If this question can be reworded to fit the rules in the help center, please edit the question.

13 Answers

up vote 18 down vote accepted

JS

I know it's still being contested, but I thought I'd have a go:

          (function (){a='';
       a           ;         a=
     '             ';           h
    =             '#'            ;
   s             = ' '            ;
  s             ;  s  ;            s
 ;             s   ;   s            ;
s             ;    s    ;            s
;            s     ;     s           ;
s           ;      s      ;          s
;          s       ;       s         ;
 b        =       '';       s       ;
  s      ;      return(      a     +
   b    +     b+arguments[    b   +
    'ca'   +'llee'].toString   ( )
      .replace(/\S/g,h)+'###');s;
          s                 ;
               s;s;s})()

When run in Chrome's console produces:

Chrome's console output

Not 100% accurate, but I thought it was quite close. As intangible as the criteria were to begin with, I did like the idea of the challenge, despite how easy/difficult is in differing languages.

share|improve this answer
 
I love it dude :) and the shape itself is my favorite too. Let's wait and see what we decide on for criteria, but this is the type of answer I had in mind. –  Quillion Nov 22 '13 at 18:23
add comment

on the Dyalog APL terminal

abcde fghij

outputs

VALUE ERROR
share|improve this answer
 
Well to be completely accurate it outputs VALUE ERROR abcde fghij ^. (and some spaces that won't show up.) –  marinus Nov 25 '13 at 4:45
add comment

BF

>++++++++[>+++++++>+++++++<<-]>++>++++++<>++++++<<<++++++++++[>++++<-]>[>.>.<<-]

It just outputs a set of laughing smileys:

:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D:D

Size of code and its output are both 80.

share|improve this answer
add comment

Python, 0 (kind of cheating)

Here's a totally valid Python program:



And here's the output of that program, of same shape:



:)

share|improve this answer
1  
Empty code block: <pre></pre>. –  manatwork Nov 25 '13 at 13:31
 
Thank you manatwork! –  psxls Nov 25 '13 at 13:35
1  
Technically, it wont print –  user80551 Dec 5 '13 at 5:08
 
This is a polyglot actually. –  Cruncher Dec 5 '13 at 15:28
 
@user80551 Technically print("") won't print. –  Cruncher Dec 5 '13 at 15:29
show 2 more comments

Python

Smallest thing I could think of.

print 'a'*5+' '+'a'*16

Output

aaaaa aaaaaaaaaaaaaaaa

That space in the middle is part of a string so it doesn't count.

share|improve this answer
 
print 'a'*5+'\x20'+'a'*19 –  gnibbler Nov 25 '13 at 10:22
 
for python3 you can do print('a'*13) –  Cruncher Dec 6 '13 at 13:48
 
that would require a from __future__ import print_function –  user80551 Dec 6 '13 at 17:16
add comment

Quines

Any quine (a program producing a copy of its own source code) would do the trick. There are thousand examples on the internet written in many different languages. For example:

Perl, 34 Author: V Vinay

$_=q(print"\$_=q($_);eval;");eval;

Python, 33 Author: Frank Stajano

l='l=%s;print l%%`l`';print l%`l`

Java, 252 Bertram Felgenhauer

class S{public static void main(String[]a){String s="class S{public static void main(String[]a){String s=;char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}";char c=34;System.out.println(s.substring(0,52)+c+s+c+s.substring(52));}}

Tcl, 34 Author: Joe Miller

join {{} \{ \}} {join {{} \{ \}} }
share|improve this answer
 
Right. This is a more lax condition on quines –  Cruncher Dec 5 '13 at 15:30
add comment

or if you are picky

5 ⍴ 1 + 1

outputs

2 2 2 2 2
share|improve this answer
 
What language is it? –  Timtech Dec 2 '13 at 0:08
 
@Timtech, it's APL. –  epidemian Dec 3 '13 at 1:28
add comment

Perl

Any program which reads it's own source file will do (technically, it's not considered to be a quine). Here's a simple Perl script (my lack of inspiration restricted me from giving to the code a shape more complex than a diamond/rhombus)!

         use
      warnings;
   use strict;open
(my $IN,'<',$0)or die
   "PCG FTW";print
     <$IN>;close
         $IN

Which will print:

         use
      warnings;
   use strict;open
(my $IN,'<',$0)or die
   "PCG FTW";print
     <$IN>;close
         $IN
share|improve this answer
 
You need longer code to make an interesting picture :) –  Cruncher Dec 5 '13 at 15:32
add comment

HQ9+

 +++    +++
 +++    +++

     ++
++   +Q   ++
++        ++
 ++      ++
  +++  +++
    ++++

Or, something like this:

                  ___                       __   _____ 
  ____  ____   __| _/____      ____   ____ |  |_/ ____\
_/ ___\/  _ \ / __ |/ __ \    / ___\ /  _ \|  |\   __\ 
\  \__(  <_> ) /_/ \  ___/   / /_/  >  <_> )  |_|  |   
 \___  >____/\____ |\___  >  \___  / \____/|____/__|   
     \/           \/    \/  /_____/                  Q  

Credits to this site ;)

Basically, anything will work, as long as it has exactly:

  • 0 Hs
  • 0 9s
  • 1 Q

Or, some minimalist solutions:

  • 1 char

    Q
    
  • 0 chars

share|improve this answer
add comment

Python

Generic solution. Just save the file as 'source.py' and execute.

import random

def main():
    f = open('source.py')
    s = ''
    d = {' ':1,
     '\t':2,
     '\n' :3}
    rstring = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`1234567890-=~!@#$%^&*()_+,./<>?;:[]{}|'
    for line in f:
        for char in line:
            if char in d:
                s += char
            else:
                s += random.choice(rstring)
    print s

main()
share|improve this answer
add comment

May be simplest solution for Python

print'*'*11

and for Py3K

print('*'*13)

and another generic solution for Py3K

import random, sys

def main():
    f = open(__file__).read()
    d = ' \t\n'
    r = ''.join(chr(c) for c in range(33, 127))
    sys.stdout.write(''.join(c if c in d else random.choice(r) for c in f))

if __name__ == '__main__':
    main()
share|improve this answer
3  
print-1e5 and print(-1e7) are shorter :P –  WolframH Nov 24 '13 at 23:53
1  
For Py3K works also print(1e7) –  AMK Nov 26 '13 at 15:43
add comment

Perl 44 chars

open O,"<$0";while(<O>){y|!-~|P-~!-O|;print}

In action:

echo $'#!/usr/bin/perl\nopen O,"<$0";while(<O>){y|!-~|P-~!-O|;print}' >/tmp/autohide.pl
chmod  +x /tmp/autohide.pl 
/tmp/autohide.pl 
RP^FDC^3:?^A6C=
@A6? ~[QkS_QjH9:=6Wk~mXLJMP\OM!\OP\~MjAC:?EN

reverse:

/tmp/autohide.pl | perl -pe 'y|!-~|P-~!-O|'
#!/usr/bin/perl
open O,"<$0";while(<O>){y|!-~|P-~!-O|;print}

Rot47 vs Rot13:

To correspond to behaviour of Rot13, but from ! to ~, there is 94 chars. I wrote rot47:

#!/usr/bin/perl -s
$                 s
?           $     O
=          *      STDIN
:                   open
$                   O
,                "<"
.                  $
0           ;while
(       <$O>
)      {#
y|!-~|P-~!-O|
;    print   }

(I've tried to draw beavis, but this is not very well!)

Store them, for sample in autohide.pl:

chmod  +x autohide.pl 

with executable rights,

./autohide.pl
RP^FDC^3:?^A6C= \D
S                 D
n           S     ~
l          Y      $%sx}
i                   @A6?
S                   ~
[                QkQ
]                  S
_           jH9:=6
W       kS~m
X      LR
JMP\OM!\OP\~M
j    AC:?E   N

Than, there is no reverse operation, it's only repeat same translation.

When run with -s parameter, this use STDIN instead of himself code, so running ./autohide.pl -s <autohide.pl do same as if run without argument:

./autohide.pl -s <autohide.pl | ./autohide.pl -s
#!/usr/bin/perl -s
$                 s
?           $     O
=          *      STDIN
:                   open
$                   O
,                "<"
.                  $
0           ;while
(       <$O>
)      {#
y|!-~|P-~!-O|
;    print   }
share|improve this answer
add comment

Bash 9 8 chars (Thanks @FireFly)

rot13<$0

This match requirement:

  • output same amount of character in the same shape as the code
  • rot13

Practical

echo  >autorot13.sh 'rot13 <$0' 
chmod  +x autorot13.sh 
./autorot13.sh 
ebg13<$0
share|improve this answer
 
You can drop the space before the <; being an operator character means it's forced to delimit the word token before it. –  FireFly Dec 1 '13 at 10:52
 
@FireFly Thanks, I've missed this! –  F. Hauri Dec 1 '13 at 11:56
add comment

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