Most tweetable ASCII art 1-line converter in 140 bytes

maffiodo2 won the title “Most tweetable entry” in IOCCC 2014 (23rd), which certainly is the best title, you can’t find more suitable for it. Why? Because it only has 140 characters, if it isn’t a tweet, what could it be?

d=80,e,j;g(){j+=getchar();}main(a,b)char**b;{for(;;){j=0;g();if(j<0)break;g(g());putchar(b[1][j/3*strlen(b[1])>>8]);if(!(++e%d))puts("");}}

d=80 is the width of the ASCII, unfortunately, no setting for height. It reads a raw RGB image and a conversion ramp from command-line argument.

For example, using my Clip smile and the following ramp:

./prog  '  .,:;!$#@' < cs.rgb

And I got this lengthy ASCII art, I don’t think the image aspect ratio is respected in generation:

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,::::,::,,:,,,::,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::,:,:,,,,:,:,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,::,,::,:,,:::::::::::,,:,,:,:,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,:,,,,::,,:,:;;::::::::::;;:,::,:::,:,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,:,,:,,:,::,;::::::::::::;,;:::::::::,::,::,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,::,,,:,,::,::::::::::::::::::;,::::::::::,:;;:,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,:;;:,,:::::::::;::;::::::::;;:;:::::::::::,::::,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,::::,::::::::::;:;;::::::::;;:;::::::::::::;,::,,,,:,,,,,,,,,,,,
,,,,,,,,,,,,,:,,:::;:::::::::::;::;::::::::;::;::::::::::::;:::::::,,,:,,,,,,,,,
,,,,,,,,,,,::::,:;,;:::::::::::;::;::::::::;::;:::::::::::;;,;:::::,:::,,,,,,,,,
,,,,,,,,,,,,,,:,:;,;;::::::::::;;:;::::::::!:;;:::::::::::;::;:::::::,,,,,,,,,,,
,,,,,,::,,,:::::,;::;::::::::::;;;;::::::::;;;::::::::::::;:;;:::::::::;:,,,,,,,
,,,,,::;:,::::::,:;:;::::::::::;;;;:::::;:;;:;;::::::::::;;:;::::::::::,::,,,,,,
,,,,,;:,;:,,::::::!:;;:::::::::;::;:::;:;;;;:;;::::::::::;;;;::::::::;:,:,,,,,,,
,,,,,:;,;;,:::::::;;;;::::::;;:;;;;:;;;;;;;;!;;;;::;:::::;:;;:::::::;;:::,,:,,,,
,,,,,,;::!::::::::;::;:::;::;;;;;;;;;;;;;;;;;;;;;;;:::;::;:;;:::::::;::;,:,:,,,,
,,,,,,;;,;;,:::::::;;;::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::::::;::;::::::,,,
,::::::!::!:::::::::;;::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;:::::::;::;;::::::,,,
,:::::::!,;;:::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;:::;;::;::::::::,,
,,::::::;;;;:::::::::::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::;;:;;:::::::::,,
,::::::::;::;:::::;;;:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;::;::::::::::::
:::::::::;::;:::;:;;;;;;;;;;;;;;;;;;;;;;;;;;;!;;;;;;;;;;;;;;;;;::;;;::::::::::::
::::::::::;;:::::;;;;;;;;;;;;;;;;;;!!!!!!;;;;!;;;;;;;;;;;;;;;;;;::;:::::::::::::
::::::::::::::::;;;;;;;;;;;;;;;;!!!!!!!!!!!;!;;!;!!!;;!;;;;;;;;;;;::::::::::::::
:::::::::::::::;;;;;;;;;;;;;;!!;!!!!!!!!!!!!!!!!!!!!!!!!;;;;;;;;;;;;::::::::::::
::::::::::::::;;;;;;;;;;;;!!!!!!!!!!!!!!!!!!!!!!!!;!!!!!;!!;;;;;;;;;;:::::::::::
::::::::::::;;;;;;;;;;;;;;;;;;;!!!!!!!!!!!!!!!;;;;!!!!!!!!;;;;;;;;;;;;::::::::::
:::::::::::;;;;;;;;;;;;;::::;;;;!!!!!!!!!!!!!;;;;::::;;;;!;;;;;;;;;;;;::::::::::
:::::::::;;;;;;;;;!;;;;:;;!!!!!:!!!!!!!!!!!!!;!!!!!;;:;;:;!;!!;;;;;;;;::::::::::
:::::::;::;;;;;;;;;;:!;;!;;;:;;;!!!!!!!!!!!!!!;;;:;;!;;!;;!;!!;;;;;;;;::::::::::
::::::::;;;;;;;;;;!;:;;::;;;!!!!!!!!!$!!!!!$!$!!!!;;;;;!;;!!!;;;;;;;;;;;;;::::::
::::::::;;;;;;;;;!;!!;;!!!!!$!!$!$$!$$$!!!$$$!$$$!!!!!!;!!!!!!;;;;;;;;;;;;::::::
::::::::;;;;;;;;!!!!!!!!!!!!$$$$$$!!$!$!!!$$$!$$$!!!!!!!!!!!!!;;;;;;;;;;;;;:::::
:::::::;;;;;;;;!!!!!!!!!!!!$!!$$$$$$$$$$!$$$$$$$$$!$$!!!!!!!!!;!!;;;;;;;;;::::::
::::::;;;;;;;;!!!!!!!!!!!!!$$$$$$$$$$$$$$$$$$$$$$$$$!!!!!!!!!;!!!!;;;;;;;;::::::
::::::;;;;;;;;;!!!!!!!!!!!!$$!!$$$$$$$$$$$$#$#$!$$$$!$!!!!!!!!!!!;;;;;;;;;;:::::
::::;;;;;;;;;!!!!!!!!!!!!$$$!!!!!!!$$$$$$$$$!!!!!$$$$$$!!!!!!!!!!;;;;;;;;;;;;:::
:::;;;;;;;;;!!!!!!!!!!$!!$$$!$$;$#!$$###$#$!$;!#!$$$$$$$$$$!!!!!!!;;;;;;;;;;::::
::::;;;;;;;;!!!!!!!!!!$$$$$$!$$;$$!########!#!!#!$$$$$$$$$$$!!!!!!;;;;;;;;;;;;:;
::;:;;;;;;;;;!!!!!!!!$$$$$$$;$!;!#;$######$!#!!$!!$$$$$$$$$$$!!!!!!;;;;;;;;;:;:;
::;;;;;;;;!!!!!!!!!!$$$$$$$$!$!;!#;#######$!#;;$!!#$$$$$$$$$!!!!!!!!!;;;;;;;;:::
::;;;;;;;;;!!!!!!!$$$$$$$$$$!$!;!#;########!#!;#$;#$$$$$$$$$$$$$!!!!!;;;;;;;;;;:
:;;;;;;;;;;!!!!!!!!$$$$$$$$$;#!;$#;########!@!:#$;#$$$$$$$$!$$!!!!!!!;;;;;;;;;;:
:;;;;;;;;;!!!!!!!!!$$$$$$$$!;#!;$$;########;@$:#$;##$$$$$$$$$$$!!!!!!!;;;;;;;;;;
::;;;;;;;;!!!!!!!!$$$$$$$$#$!$!;!!;@#####@#;#$:!!!##$$$$$$$$$$!!!!!!!!;;;;;;;;;:
:;;;;;;;;;!!!!!!!$$!$$$$$$#$$#!!$$!########$#$;$#$$$$$$$$$$$$$$$!!!!!;;;;;;;;;::
:;;;;;;;;;!!!!!!!!$!$$$$$##!$#!!##!@##@#@##$@#;##!$#$$$$$$$$$$$!!!!!!;;;;;;;;;;;
:;;;;;;;;;!!!!!!!!!$$$$$$$##!!$$!!#@#@#@@@@!#$$$!!#####$$$$$$$$!!!!!!!!;;;;;;;;:
:;;;;;;;;!!!!!!!!!!!$$$$$#########@###@#@@@#$$@########$$$$$$$$!!!!!!!!!;;;;;;::
;;;;;;;;;!!!!!!!!!!$$$$$$$######@@#@@@@@@@@#@@##@#####$$$$$$$$!!!!!!!!!;;;;;;;::
:;;;;;;;!!!!!!!!!!$$$$$$$$$######@@@@@@@@#@@@@@@##@###$$$$$$$!!!!!!!!;!;;;;;;;;:
::;;;;;;!!!!!!!!!!$$$$$$$$$######@@@@@@@@#@@@@#########$$$$$$!!!!!!!!;;;;;;;;;;;
::;;;;;;!!!!!!!!!!$$$$$$$$#####@@@@@@@@@@@@@@@@#@@###$$$$$$$$$$$!!!!;;;;;;;;;;::
::;;;;;;!!!!!!!!!$$$$$$$$$######@@@@@@@@@@@@@@@#@####$$$$$$$$$$!!!!;;;;;;;;;;;::
::;;;;;;!!!!!!!!!!$$$$$$$########@#@@@@@@@@@@@@@@@####$$$$$$$$$!!!!;;;;;;;;;;:::
::;;;;;;!!!!!!!!!$$$$$$$$#########@@@@@@@@@@@@@@@####$$$$$$$$$$!!!!!;;;;;;;:::::
::;;;;;!!!!!!!!!!$$$$$$$$#########@##@@@@@@@@@@@@####$$$$$$$$$!!!!!!;;;;;;;;;:::
:;;;;;;;!!!!!!!!;!$$$$$$###########@@@@@@@@@@@@@#####$$$$$$$$!!!!!!!;;;;;;;:::::
:;;;;;;;!!!!!!!;!;$$$$$$$###########@#@@@@###@@@######$$$$$$!!$;!!!!;;;;;::;::::
;;;;;;;;!!!!!!!;$!!$$$$################@@##############$$$$;!$!;!!!;;;;;;:::::::
:;;;;;;;;!!!!!!;;!;!$$$$$$#############@@############$$$$$!;!!;!!!!;;;;;;;::::::
::;;;;;;!!!!!!!!:!;;$$$$###############@###############$$$;!!;;!!!;;;;;;;;;;::::
::;;;;;;;;!!!!!!;;!;$$$$##############################$$$!;$!;!!!!;;;;;;;;::::::
:;;;;;;;;;!!!!!!;;$;!$$$$############################$$$$;!$;;!!!!!;;;;;;;;:::::
::;;;;;;;;;!!!!!!;!!;$$$$############################$$$!;!!;!!!!!;;;;;;;;::::::
::;;;;;;;;;;!!!!!;;!;!$$$$######################$##$$$$$!!!;;!!!!!!!;;;;;;::::::
:;;;;;;;;;;;!!!!!!;!!!$$$$$$####################$$$$$$$$;$!;!!!!!!!!;;;;;;;:::::
:;;;;;;;;;;;!!!!!!;$!!$$$$$$$###################$$$$$$$!;!;;!!!!!!!!!;;;;:;;::::
::;:;;;;;;;;!!!!!!!;;;!!!!!$#####################$$!;;!!;!!!!!!!!!!!;;;;;:::::::
:::;;;;;;;;;;!!!!!$!!;$$!!;;!$$################$$;;;!$$$;!!!!!!!!!!!;;;;;:::::::
::;;:;;;;;;;;!!!!!!!!!!!!$$$!;!!$#$##########$!!;!$$$;;;;!!!!!!!!!!;;;;;::::::::
:::;;;;;;;;;;!!!!!!!$$!!;;!$#$!$!!!!!!;!!!$$#!$$!$!;:;!!!!!!!!!!!!!;;;;;;:::::::
::::;:;;;;;;;;!!!!!!!!$$$!!;;!$#;;#$!$$$$$$!!!$#!;;!!$$!!!!!!!!!!!!!;;;;;:::::,,
:::::;;;;;;;;;;!!!!!!!!!$$$$$!!!!;$$!#$#####$!!!!!$$!!!!!!!!!!!!!;!!;;;;:::::::,
:::;;;;;;;;;;;;;;!!!!!!$$$$$$$$$$!!!;;;;;;!!!$$$$$$$!!!!!!!!!!!!!;;;;;;;;:::::::
:::::;;;;;;;;;;;!!!!!!!!$$$$$$$$$$#$$$$$$$$$$#$$$$$!!!!!!!!!!!!!!!!;;;;;::::::::
:::::;;;;;;;;;!!!;!!!!!!$$!$$$$$$$$$$$$$$$#$$$$$$$$!!!!!!!!!!!!!!;;;;;;;:::::::,
::::;;;;;;;;;;;;;;!!!!!!!!!$$$$$$$$$$$$$$$$$$$$$$$$!!!!!!!!!!!!!!;;;;;;::::::,,,
:::::;;;;;;;;;;;!!!!!!!!!!!!!$!$$$$$$$$$$$$$$$$$$$$!!!!!!!!!!!!!;;;;;;:::::::,,,

If 140 characters are still too long for you, the author also provided a 121-character version, which uses a fixed ramp:

d=80,e,j;g(){j+=getchar();}main(){for(;;){j=0;g();if(j<0)break;g(g());putchar(" .:#@"[j/3*5>>8]);if(!(++e%d))puts("");}}

maffiodo2 is written in C11, 2014-10-29, by Sandro Maffiodo, who also has another entry as homage to classic games.

endoh2 is an ASCII to DNA transcoder, quick example with text “YJL”:

% echo YJL | ./prog > YJL.c
This chromosome program synthesizes a double helix. The helix can also be compiled as a C program.
% cat YJL.c
#include "prog.c"

     AT
    C~~G
    C~~~G
    G~~~~C
     C~~~~G
      C~~~G
       A~~T
        CG
        TA
       G~~C
      G~~~C
     C~~~~G
    A~~~~T
    T~~~A
    A~~T
     CG
     TA
    A~~T
    A~~~T
    G~~~~C
     G~~~~C
      A~~~T
       A~~T
        GC

You don’t need to compile yourself, the Makefile can do that for you:

% make YJL
cc -Wall -std=c11  -O2    YJL.c   -o YJL

If you run the synthesized DNA program, you get the input ASCII text, is this a form of hiding information in DNA?

% ./YJL
YJL

If you ask how the source code, prog.c, looks like, well, you don’t need to have smart gene to guess, it’s all in the gene — no pun intended:

 #include      <stdio.h>
#define TA    q=/*XYXY*/
#define/*X    YXY*/CG r=
void p(int    n,int c){;
for(;n--;)    putchar(c)
#define Y(    z)d;d=c++\
%2<1?x=x*4    +z,c%8>5?\
x=x?p(1,x),   0:x:0:0;d=
#define/*X    YX*/C Y(1)
#define/*X    YX*/G Y(2)
 ;}int(*f)(  void),d,c,
 #define/*X  YX*/A Y(0)
  #define/*XY*/AT int\
     m(void/**/){d=
  #define/*XYX*/T Y(3)
 #define GC  d; return\
 0;}int(*f)  (void )=m;
x,q,r; int    main(){if(
f)f();else    {for(puts(
"#include"    "\40\"pro\
g.c\"\n\n     \101T"+0);
d=!d?x=(x=    getchar())
<0?0:x,8*8    :d,TA++c%8
,TA(1+7*q-    q*q)/3,r=c
*15-c*c-36    ,p(r<0?!q+
4:r/6+!q+4    ,32),q||x;
c%=16)q?p(    1,"ACGT"[x
/d&3]),p(q    ,126),p(1,
"TGCA"[x/d    &3]),d/=4,
p(001,10):    puts(c%8?\
"CG":"TA")    ;puts("GC"
 );}return     0;}/**/

The author said: “Enjoy DNA programming!” and “The synthesized helix of course follows the base-pairing rules for DNA: A is bonding only to T, and C is bonding only to G.”

I wonder if a DNA programming language can be done — or is there already one? Not for actual DNA, of course. If you know of Brainfuck, coding in only those brainfucking symbols, which I have done once five years ago, why not CGAT?

endoh2 is written in C11 by Yusuke Endoh, 2014-10-29, inspired by Perl’s Acme::DoubleHelix, it has 32 LOC or 785 bytes.