This code-golf is about creating 2 different sourcecodes that both outputs exactly: Hello, new world! again. without linefeed, and when combining the two sourcecodes into one sourcecode it should still output exactly: Hello, new world! again.


  1. Your programs should take no input (from user, filename, network or anything).
  2. You can choose any combination of programming languages, from one language for all three sourcecodes to three different languages.
  3. The combination of the two sourcecodes to create the third is done by putting alternating characters from both from start to end and fill up the third sourcecode from start to end.
  4. You must choose 10 different characters that both sourcecodes may use (case sensitive). All other characters is mutual exclusive between the two sourcecodes. Characters may be re-used without restriction. Exactly all 10 characters choosen must be used in both sourcecodes atleast once.

Clarification example on sourcecode combination:

Javascript          sourcecode: console.log("Hello, new world! again.");
GolfScript          sourcecode: 'Hello, new world! again.'
Combined (unknown?) sourcecode: c'oHneslolloe,. lnoegw( "wHoerllldo!,  angeawi nw.o'rld! again.");

The above example does however violate rule #4 as more than 10 characters is "shared" in both sourcecodes. And the combined sourcecode does not output: Hello, new world! again.

Be sure to declare what programming languages is used (all three) and what 10 characters that is allowed in both sourcecodes.

This is code-golf, least bytes in combined sourcecode wins! Good luck, have fun!

  • \$\begingroup\$ Are also symbols like ,.:( or the whitespace counted in the 10 common characters, or only letters? \$\endgroup\$
    – flonk
    Commented Jan 20, 2014 at 15:17
  • \$\begingroup\$ The constraint is for All characters, including symbols. No more than total 10 characters (or symbols) can be common \$\endgroup\$ Commented Jan 20, 2014 at 20:53
  • \$\begingroup\$ Just to be 100% sure, also the whitespace? \$\endgroup\$
    – flonk
    Commented Jan 20, 2014 at 20:59
  • \$\begingroup\$ Yes, that is correct! whitespace too. \$\endgroup\$ Commented Jan 20, 2014 at 21:12
  • \$\begingroup\$ The currently accepted answer does not comply with the without linefeed requirement. \$\endgroup\$
    – Dennis
    Commented Feb 14, 2016 at 19:19

4 Answers 4


C99 + sh + C11, 165 162 146 145 combined chars

Edit: using @flonk's trick I managed to put the "comment" in C (making use of C11's u"" Unicode literals).

Common characters are: acehinortu.

hello.c (106):


hello.sh (39):

echo -n 'Hello, new world! again.'

hello-combined.c (145):

2e+c+h+o+ +-+n+ +'+H+e+l+l+o+,+ +n+e+w+ +w+o+r+l+d+!+ +a+g+a+i+n+.+'";i;main(){for(;i<24;)putchar("Lipps0$ri{${svph%$ekemr2"[i++]+~3);}

Here are some utilities that might prove useful for other participants.


#include <stdio.h>
int main(int argc, char *argv[]) {
  FILE *f1 = fopen(argv[1], "r"), *f2 = fopen(argv[2], "r");
  while (!feof(f1) || !feof(f2)) {
    int c1 = fgetc(f1), c2 = fgetc(f2);
    if (c1 != EOF) putchar(c1);
    if (c2 != EOF) putchar(c2);
  return 0;


comm -12 <(grep -o . "$1" | sort | uniq) \
         <(grep -o . "$2" | sort | uniq) | tr -d '\n'

Here's a variation that unfortunately ended up (considerably) longer, but it's pretty cool in how it works. (I didn't bother getting the intersection between the sets of characters down to 10, since it ended up longer anyway.)

hello.c (113):


hello.sh (51):

echo -n 'Hello, new world! again.' #     tr  1

hello-combined.c (164):

5eLcihpop s-0n$ r'iH{e$l{lsov,p hn%e$we kweomrrl2d+!+ +a+g+a+i+n+.+'+ +#" , * b = &tar, c =16;i;main(){char*p=*b;for(i=c/8;p[i]-50;)putchar(p[i+=c/4]-4);}

This one is fun, because it doesn't just "comment out" a bunch of characters, but actually stores the characters it prints inside the string literal and accounts for the extra characters in the for-loop of the generated program.

  • \$\begingroup\$ +1 nice first! I would however do it the other way round, re-using the "longer" sourcecode and brick the shorter code into the sidelines dating the comments ;P That way you can shorten the long comment-row, I think... not sure. \$\endgroup\$ Commented Jan 19, 2014 at 20:14
  • \$\begingroup\$ @Plarsen well, it doesn't work that well with C since its comment marker is two characters... hmm, but I might be able to switch it around so the sh version is the one with the character translation. I'm just worrying about the 10-shared-characters rule... \$\endgroup\$
    – FireFly
    Commented Jan 19, 2014 at 20:19
  • \$\begingroup\$ Yeah, that is true it may introduce some additional obstacles. worth investigating though \$\endgroup\$ Commented Jan 19, 2014 at 20:21

Brainfuck + C (196+77)

Not a very golfy answer, but I just think it is fun




main(){printf("Hello");putchar(44);printf(" new world! again");putchar(46);}

Combined (Also in brainfuck):

+m+a+i+n+(+)+{+p+r+i[n>t+f+(+"+H+e+l+l>o+"+)+;+p>u+t+c+h+a+r+(+4+4+)+;>p+r+i+n<t<f<(<"- ]n>e+w+ .w>o>r+l.d+!+ +a+g+a+i+n.".)+;+p+u.t<c+h+a+r+(.4>6>)+;+}.

All the characters from the C code are considered as comments in brainfuck

The common characters are printfHelo, appended at the end of the brainfuck code as comments


Befunge + sh + Befunge, 111 chars

Common characters are: !,-Hehilor

hello.bef (78):


hello.sh (33):

echo -n Hello, new world\! again.

hello-combined.bef (111):

veHcehloo ---n- -H-e-l-l-o-,- -n-e-w- -w-o-r-l-d-\-!- -a-g-a-i-n-.

Python + dc (160,141,137,116 81+27=108)

program1: (python)

'yyyyyyyyyyyyyyyyyyyyyyyyyy';exec'PRINT\'%sELLO, NEW WORLD! AGAIN.\''.lower()%'H'

program2: (dc)

[Hello, new world! again.]p

combined: (python)

'[yHyeylylyoy,y ynyeywy ywyoyrylydy!y yaygyayiyny.y]yp';exec'PRINT\'%sELLO, NEW WORLD! AGAIN.\''.lower()%'H'

Common characters (including space): ! ,.elorwH

The parts program1 and program2 are quite simple to understand, where the first has some case switches to reduce the common characters.

As program1 starts with a quotation ', in the combined code all the gibberish walks into a long string, becoming irrelevant for the interpreter. The string 'yy...y' is of the same length as program2, so after its closing ' the relevant code of program1 is appended to the combined program.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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