g | x | w | all
Bytes Lang Time Link
469Brainfuck250511T172128ZJOrE
186Pascal250511T171358ZJOrE
016Vyxal220202T150715ZJakque
089Python 3.8210507T103912ZJakque
096Ruby200816T135626ZDingus
156AWK210611T212616ZPedro Ma
043Japt210507T114015ZEtheryte
nanPxem esolangbox notation210505T061343Zuser1004
086Python 2210409T064125Zdingledo
nanWolfram Language Mathematica200803T213534Zatt
028Klein 001201112T194702ZWheat Wi
140Haskell200805T212319ZSilvio M
127Haskell201108T163113ZWheat Wi
026Keg200804T005725Zlyxal
nanJava 10+200816T232449Zuser
nanR200803T172156ZDominic
121Python 3200814T003936ZQuelklef
125R200807T085840ZDominic
025Quine + Cat = Hello World200803T165429Zfireflam
017Jelly200805T214437ZJonathan
117PHP200806T130130ZRFSnake
032V vim200805T184654ZBeefster
189Python 2200803T200634ZBeefster
048><>200804T215427ZSE - sto
02305AB1E200804T100829ZKevin Cr
nanHello World + Quine = Cat200804T203000Zrtpax
051Alice200804T193144ZOyarsa
nanRust200803T194547ZTehPers
nanAceto200804T121909ZL3viatha
129Python 3200803T201447Zwater_gh
110Bash200803T215549ZBeefster

Brainfuck, Hello World + Quine = Cat, 469 bytes

Hello World (Requires dynamic memory)

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

Quine:

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

Cat Program:

+[,.]

Note: It needs a null at end of input, or the last character will repeated infinite times.

Pascal, Cat + Quine = Hello World, 186 Bytes

Cat Program:

var s:string;begin read(s);write(s)end.

Quine:

CONST T=';BEGIN WRITE(#67#79#78#83#84#32#84#61#39,T,#39,T)END.';BEGIN WRITE(#67#79#78#83#84#32#84#61#39,T,#39,T)END.

Hello World:

begin write("Hello World!")end.

Vyxal, Cat + Quine = Hello, 16 bytes

Hello world, 13 bytes

kh\!+□⁋`I^`I^

Try it Online!

Cat, 7 bytes

kh\!+□⁋

Try it Online!qwhYOKWoeKBiyIsIiIsImFcbmJcbmNcbmRcbiJd)

Quine, 6 bytes

`I^`I^

Try it Online!

Explanation :

## Cat (10)

kh       # push 'Hello World' onto the stack
  \!+    # add '!' to the string
     □   # push the list of the inputs onto the stack
      ⁋  # join the element on top of the stack, with '\n' as separator
         # implicit output

## Quine (6)

`I^`     # push 'I^' on the stack
    I    # string -> `string`string 
     ^   # reverse the stack
         # implicit output

## Hello (16)

kh\!+          # push `Hello World!` onto the stack
     □         #  | do
      ⁋        #  | many
       `I^`    #  | useless
           I   #  | things
             ^ # reverse the stack
               # implicit output

Python 3.8, Cat + Quine = Hello, 101 91 89 bytes

Cat (32 bytes)

a=id=""
while 1:a=input(a)+"\n";

Try it online!

Quine (57 bytes)

exec(s:='+input(id and"exec(s:=%r)"%s or"Hello World!")')

Try it online!

Hello World (89 bytes)

a=id=""
while 1:a=input(a)+"\n";exec(s:='+input(id and"exec(s:=%r)"%s or"Hello World!")')

Try it online!

How it works:

For the cat program:

For the quine program:

For the hello world program:

Old solution: cat (37) + quine (64) = hello (101 bytes)

Here is my old solution using triple quoted string and comments to "squeeze" the quine part and directly printing "Hello World!". It uses some cool tricks with comments:

while p:=print:id or p(input());id=""									# cat (37 bytes)
                                     "";exec(s:='input(\'"";exec(s:=%r)\'%s)#"""-p("Hello World!")#')	# quine (64 bytes)
while p:=print:id or p(input());id="""";exec(s:='input(\'"";exec(s:=%r)\'%s)#"""-p("Hello World!")#')	# hello (101 bytes)

Try it online!

Who said that comments were not usefull in codegolfing?

Ruby, Cat + Quine = Hello World!, 100 97 96 bytes

Reading the source code is prohibited for quines but there is no such rule for Hello World! programs. We exploit this fact using Ruby's DATA/__END__ mechanism. If __END__ appears alone on any line in the code, execution terminates there. However, any further code is accessible via the constant DATA, which is initialised to a File object containing all of this non-executable 'data'.

Cat

$><<(DATA||=$<).read;a

Try it online!

The idiomatic ||= operator sets the value of the variable DATA only if it is not already defined. In this case, DATA is not defined because the program does not contain __END__. In effect, the first part of the code therefore reduces to $><<$<.read, where $< and $> point to STDIN and STDOUT, respectively. For later use, the final a (which is an undefined variable) throws an error, which is inconsequential here.

Quine

eval$s=%q($><<"eval$s=%q(#$s)
__END__
Hello World!")
__END__
Hello World!

Try it online! or verify quine.

All of the real work is done in the first line, which is a basic Ruby quine template. With __END__ now making an appearance, it shouldn't be too hard to see where this is going.

Hello World!

$><<(DATA||=$<).read;a
eval$s=%q($><<"eval$s=%q(#$s)
__END__
Hello World!")
__END__
Hello World!

Try it online!

Finally we have DATA and __END__ together. Unlike in the cat program, DATA is defined this time: it's a File object containing Hello World!. Once this has been printed, there is no further output because of the error thrown by the final a (undefined) in the first line.

AWK, Cat + HW = Quine, 156 bytes

BEGIN{k=1}1;BEGIN{if(k){printf a="BEGIN{k=1}1;BEGIN{if(k){printf a=%c%s%c,34,a,34,34,34;exit}print%cHello World!%c}",34,a,34,34,34;exit}print"Hello World!"}

Try it online!

This is the overall algorithm:

BEGIN{k=1}1;
BEGIN{if(k){
    print"Quine";exit
    }
print"Hello, World!"
}

Cat

BEGIN{k=1}1;

Hello World

BEGIN{if(k){printf a="BEGIN{k=1}1;BEGIN{if(k){printf a=%c%s%c,34,a,34,34,34;exit}print%cHello World!%c}",34,a,34,34,34;exit}print"Hello World!"}

Japt, Quine + Cat = Hello World, 43 bytes

All of the complexity is jammed into making a quine that includes a variable that holds Hello World!. Cat simply outputs the default input and the Hello World merger reuses the variable from the quine.

Quine, 41 bytes

"Hello World!"             // U = "Hello World!"
"iQ ²iRiQiUiQ"iQ ²iRiQiUiQ // A bunch of messy string manipulations to make this a quine

Cat, 2 bytes


U // Output the default first input

Hello World, 43 bytes

"Hello World!"             // U = "Hello World!"
"iQ ²iRiQiUiQ"iQ ²iRiQiUiQ // Throwaway line
U                          // Output U

Pxem (esolang-box notation), Hello World: 48 bytes + Quine: 110 bytes = Cat: 158 bytes.

Unprintables are escaped.

Hello World

.f!.zHello World.p.d.a.w.c.z.w.o.i.c\001.+.a.d.a.a

Quine

!Be!?BzBc!!B+BzXXFBaBcFBzBsXXFBBaBsBtBvBmBvBcAcB-BaBsBp".e!?.z.c!!.+.zXXF.a.cF.z.sXXF..a.s.t.v.m.v.cAc.-.a.s.p

Cat

.f!.zHello World.p.d.a.w.c.z.w.o.i.c\001.+.a.d.a.a
!Be!?BzBc!!B+BzXXFBaBcFBzBsXXFBBaBsBtBvBmBvBcAcB-BaBsBp".e!?.z.c!!.+.zXXF.a.cF.z.sXXF..a.s.t.v.m.v.cAc.-.a.s.p

Try it online!

Use variable mode to switch programs.

How it works

The Hello World program consists of several parts, as in:

# branch if content begins with '!' or not
.f!.z
  # Hello World program
  # Note that '!' is recycled here
  Hello World.p.d
.a
.w.c.z
  # Cat program
  # Note that content of stack is cleared before entrying here
  .w.o.i.c\001.+.a.d
.a.a\n

Quine is recycled from here.

Cat program uses this specification:

The first line is the file name of the pxem code.

The rest is the content of the pxem code.

Python 2, Quine + Cat = Hello World, 86 bytes

Quine (35 bytes)

id='id=%r;print id%%id';print id%id

Cat (51 bytes)

+0*''and'Hello World!'
while''>id:print raw_input()

Hello World (86 bytes)

id='id=%r;print id%%id';print id%id+0*''and'Hello World!'
while''>id:print raw_input()

Wolfram Language (Mathematica), Quine + Cat = Hello World, 15+28=43 15 + 22 = 37 bytes

3 functions.

Quine

ToString[#0] & 

Try it online!

Cat

#/.#_:>"Hello World!"&

Try it online!

Hello World

ToString[#0] & #/.#_:>"Hello World!"&

Try it online!


HW+Q=C,46+58=104 Q+C=HW,43+48=91 Cat + Quine = Hello World, 49 + 37 = 86 bytes

Cat

Print[#/._@_->"Hello World!"]&@$ScriptInputString

Try it online!

Quine

Print[ToString[#0, InputForm][]] & []

Try it online!

Hello World

Print[#/._@_->"Hello World!"]&@$ScriptInputStringPrint[ToString[#0, InputForm][]] & []

Try it online!

Klein 001, Quine + Cat = Hello World, 28 bytes

Quine, 11 bytes

This is Martin Ender's quine from here

:?\:2+@> "

Try it online!

Cat, 17 bytes

@ >"Hello world!"

Try it online!

Hello World, 28 bytes

:?\:2+@> "
@ >"Hello world!"

Try it online!

Haskell, Cat + Quine = Hello World, 140 bytes

Cat

b=interact id
main=b where c=1;

Quine

main=putStr a>>print a;b=putStrLn "Hello world!";a="main=putStrLn a>>print a;b=putStrLn \"Hello world!\";a="

Hello World!

b=interact id
main=b where c=1;main=putStr a>>print a;b=putStrLn "Hello world!";a="main=putStrLn a>>print a;b=putStrLn \"Hello world!\";a="

We exploit the rules of variable shadowing. The cat program simply calls the global b, defined as interact id (a standard cat in Haskell). We declare a variable c that's never used, simply so we can concatenate later. The quine is pretty standard; we define a variable b that we never use, but otherwise it simply prints its payload and exits.

Here's a version of "Hello world" with better spacing.

b = interact id
main = b
  where c=1
        main=putStr a>>print a
        b=putStrLn "Hello world!"
        a="main=putStrLn a>>print a;b=putStrLn \"Hello world!\";a="

main simply calls b, but this time is calls the locally-declared b, which prints "Hello world!". All of the other variables are unused.

Haskell, Cat + Quine = Hello World, 127 bytes

Cat, 27 bytes

o=interact id
main=o where 

Try it online!

Quine, 100 bytes

o=putStr"Hello, world!";main=putStr$(++)<*>show$"o=putStr\"Hello, world!\";main=putStr$(++)<*>show$"

Try it online!

Hello World

o=interact id
main=o where o=putStr"Hello, world!";main=putStr$(++)<*>show$"o=putStr\"Hello, world!\";main=putStr$(++)<*>show$"

Try it online!

Explanation

The main trick in this answer is scoping. In the cat we have a simple program. We have a main which is just defined to be o, which is a cat program. At the end of the program there is a where which opens a new scope. This will make our entire quine program attached to the scope of the main program. Two things are solved by doing this.

The overall technique is very similar to Silvio Mayolo's answer, however improves upon it in two ways.

Keg, Hello World + Quine = Cat, 26 bytes

«H%c¡|,!«``:[④|᠀,]`:[④|᠀,]

Try it online!

How it Works

Hello World

«H%c¡|,!«`

Try it online!

This is my answer to the HW challenge with some additional string closing syntax. Why? Because a) the main string needs closing to be concatenated and b) the end ``` is needed to "ignore" the quine part

Quine (non-trivial)

`:[④|᠀,]`:[④|᠀,]

Try it online!

`:[④|᠀,]`           

Push the string :[④|᠀,] to the stack

:[④|᠀,]

Duplicate the string and start an if-block. The if block uses the truthiness of the t.o.s to determine which branch is to be executed. In this case, the string is truthy, so the is executed (printing the string raw). Implicit output then prints the string nicely.

Concatenation

«H%c¡|,!«``

Push the string Hello, World! followed by an empty string onto the stack.

:[④|᠀,]

Duplicate the top of the stack (an empty string) and start the if block. Empty strings are considered falsey, so the ᠀, branch is executed. This takes input and prints it.

`:[④|᠀,]

Push the string :[④|᠀,] and don't do anything with it.

Java 10+, Cat + Quine = Hello World, 384 (135 + 249) bytes

Cat, 135 bytes

interface C{static void main(String[]a){System.out.println(Boolean.TRUE?new java.util.Scanner(System.in).nextLine():"Hello World");}}//

Quine, 249 bytes

(note: TIO doesn't let me run the code unless I rename my interface from Q to Main, but just know that it's supposed to be named the former)

interface Q{static void main(String[]a){var s="interface Q{static void main(String[]a){var s=%c%s%c;System.out.printf(s,34,s,34,10);}}%cinterface Boolean{boolean TRUE=false;}";System.out.printf(s,34,s,34,10);}}
interface Boolean{boolean TRUE=false;}

Hello World, 384 bytes

interface C{static void main(String[]a){System.out.println(Boolean.TRUE?new java.util.Scanner(System.in).nextLine():"Hello World");}}//interface Q{static void main(String[]a){var s="interface Q{static void main(String[]a){var s=%c%s%c;System.out.printf(s,34,s,34,10);}}%cinterface Boolean{boolean TRUE=false;}";System.out.printf(s,34,s,34,10);}}
interface Boolean{boolean TRUE=false;}

Again, the TIO link contains an interface called Main, but it's actually C, the cat program.

It redefines Boolean.TRUE to be false when the quine is concatenated to the cat.

R, Quine + hello, world = cat; 48 + 49 ... 43 + 44 = 87 bytes

Or 75 bytes as internal code of functions and not including function(){} wrappers.

Edit: -14 bytes thanks to Robin Ryder!

Nontrivial quine:

'->T;cat(sQuote(T),T)' ->T;cat(sQuote(T),T)

Try it online!

Hello,world:

~F->y;cat(`if`(T>0,"Hello world!",scan(,T)))

Try it online!

Cat:

'->T;cat(sQuote(T),T)' ->T;cat(sQuote(T),T)~F->y;cat(`if`(T>0,"Hello world!",scan(,T)))

Try it online!

A 'trivial quine' version could be Quine = ~1, and Hello, world = +F->y;cat(`if`(y<0,scan(,''),'Hello world!')), for 2+45=47 bytes.

How? (nontrivial & trivial versions)

The default behaviour of R is to output any unassigned values (such as variables or expressions). So, to print a quine, we simply need to generate an expression containing the program code, and it is output by default (this applies both to the nontrivial quine, which is contructed using cat to join the various text elements together, as well as the trivial quine ~1 consisting simply of a formula which is outputted)

If a value is assigned to a variable, it is not output. So to stop the quines from printing, we incorporate them into an expression and assign this to the variable y.

To do this, we need to use a binary operator, but since this operator will also appear at the start of the 'Hello, world' program, it must also function as a unary operator. Both the ~ (formula) and + (positive/sum) operators have this property.

Conveniently, R also includes a (little used outside coding challenges) left-to-right assignment operator, ->, which - together with a unary/binary operator - lets us package the quine into the variable y & forget about it. Then all we need to do is to determine whether this has happened or not, and use this to switch between 'Hello, world' and 'cat' behaviour.

Python 3, Cat + Quine = Hello World, 121 bytes

Cat:

Actual cat part is taken from the top comment of this SO answer.

If the file is long enough, switch to a Hello World program.

len(open(__file__).read())<99or~print('Hello World!')
import sys
print(sys.stdin.read())

The ~print exits the program after printing: print returns None and ~None throws. (Crashing to exit was allowed by OP in a comment.)

Quine:

Pretty standard. Originally wanted to use Python 3.8 := to do print((s:='print((s:=%r)%%s)')%s), but that was longer. Stole the use of ; instead of \n from one of the other Python answers.

s='s=%r;print(s%%s)';print(s%s)

Combined:

len(open(__file__).read())<99or~print('Hello World!')
import sys
print(sys.stdin.read())
s='s=%r;print(s%%s)';print(s%s)

R, Quine (74 51 bytes) + Cat (77 74 bytes) = Hello world 151 125 bytes

R, Hello world (173 174 bytes) + Cat (77 74 bytes) = Quine 250 248 bytes

R, Quine (74 51 bytes) + Hello world (173 174 bytes) = Cat 247 225 bytes

A set of Quine, Cat & Hello world from which any 2 can be combined to form the third.

Not the shortest answer, but pleasingly symmetric.

Quine (74 51 bytes)

'->F;T=0;cat(sQuote(F),F)' ->F;T=0;cat(sQuote(F),F)

Try it online!

Cat (77 74 bytes)

~1->y;cat(`if`(T>1,sprintf(T,sQuote(T)),`if`(T,scan(,""),"Hello world!")))

Try it online!

Hello world (173 174 bytes)

~1->y;T='~1->y;T=%s;cat(`if`(F<0,scan(,""),"Hello world!"))~1->y;cat(`if`(T>1,sprintf(T,sQuote(T)),`if`(T,scan(,""),"Hello world!")))';cat(`if`(F<0,scan(,""),"Hello world!"))

Try it online!

Quine + Cat = Hello World, Jelly, 25 bytes

-2 bytes thanks to @Jonathan Allan

Quine (12 bytes)


“Ṿṭ⁷;⁾v`”v`

(starts with a newline)

Try it online!

Cat (13 bytes)

Ṇ
“,ḷṅḳȦ»³ÑƑ?

Try it online! (argument quoted to avoid casting to a Python object from string as per @Jonathan Allan's suggestion)

Hello World (25 bytes)


“Ṿṭ⁷;⁾v`”v`Ṇ
“,ḷṅḳȦ»³ÑƑ?

(starts with a newline)

Try it online!

How it Works

In Jelly, the last link (last line) is always executed as the main link. The Cat and Hello World have the same last link, so they are differentiated by the value of the first link (blank (identity) or (logical not)).

“,ḷṅḳȦ»³ÑƑ?
          ?  # If
        ÑƑ   # The first link is the identity
“,ḷṅḳȦ»        # Return "Hello World!" (String Compressor: https://codegolf.stackexchange.com/a/151721/68261)
             # Else
       ³       # Return the input

The quine is slightly difficult because it needs to prepend a blank line.

“Ṿṭ⁷;⁾v`”v` 
“Ṿṭ⁷;⁾v`”     # Set the string "Ṿṭ⁷;⁾v`"
         v`   # Eval it on itself:
 Ṿṭ⁷;⁾v`
 Ṿ              # Uneval: "“Ṿṭ⁷;⁾v`”"
  ṭ⁷            # Prepend a newline "¶“Ṿṭ⁷;⁾v`”"
    ;⁾v`        # Concatenate "v`" to get "¶“Ṿṭ⁷;⁾v`”v`"

Jelly, Quine + Cat = Hello World! 17 bytes

Note that using a formatted input has been deemed valid and this entry takes input as a command-line argument formatted as a Python string. To have a pure-Cat program we'd need to use STDIN in Jelly, since it first attempts to evaluate any command-line argument as Python. This is achievable in 21 bytes with ”ṘṘ + ”1$0¡ƈȮ¤L¿“,ḷṅḳȦ»Ṇ? TIO.

”ṘṘ

Quine

1$0¡³“,ḷṅḳȦ»⁼?

Cat

”ṘṘ1$0¡³“,ḷṅḳȦ»⁼?0

Hello World!

How?

The shortest proper quine in Jelly is:

”ṘṘ - Main Link: any arguments
”Ṙ  - an 'Ṙ' character
  Ṙ - print Jelly representation of x (i.e. ”Ṙ) and yield x ('Ṙ')
    - implicit print (i.e. Ṙ)

To use it we need to not let the execute in the largest program.

One way to not execute a link is to follow it with - repeat zero times, but ¡ needs a link to repeat, like X0¡, so we make X equal 1$.

$ composes the preceding two links into a single monadic link and (slightly surprisingly) 1$ can start a full program, as a monad which yields \$1\$ but when repeated zero times it just yields whatever its left argument is.

As such starting a program which has one command-line argument with 1$0¡ applies 1$ zero times to that argument, i.e. is a no-op, giving the rest of the program that same left argument.

But when 1$0¡ is prefixed with ”ṘṘ we have the X (described earlier) equal to Ṙ1 which when applied zero times to ”Ṙ yields the character 'Ṙ'.

Since the character, 'Ṙ', is not equal to the right argument of the Main Link (which, when given a single command-line argument is that argument) since that is a list of characters, we can use equality, , to test, ?, (effectively) whether the prefix ”ṘṘ is present and either...

...Cat* (if not):

³ - yield the programs 1st command-line argument

...or Hello World!:

“,ḷṅḳȦ» - compressed string = "Hello World!"

* The Cat code for the 21 byte STDIN version is:

ƈȮ¤L¿ - niladic link (no arguments)
    ¿ - do...
  ¤   - ...instruction: nilad followed by link(s) as a nilad
ƈ     -   read a character from STDIN
 Ȯ    -   print & yield
   L  - ...while?: length (0 at EOF)

and we use the monad logical-NOT, , as our test since we get an implicit left argument of 0 with no command-line arguments and by this point gets an argument of 0 (0Ṇ = \$1\$ -> Cat) or 'Ṙ' (”ṘṆ = \$0\$ -> Hello World!).

PHP, Hello World + Quine = Cat, 117 bytes

Because of the input method this only works using the command line.

Hello world

the double die is because the php code has to get interupted earlier in order to prevent errors being printed (missing function a)

<?php if(!function_exists('a')){die('Hello world!');}die(a($argv));

Quine

without opening tag, php just outputs whatever it contains

function a($b){unset($b[0]);echo implode(' ',$b);}

Cat

Because function declations are passed first, the die() isn't called yet and therefor a() exists, and is called in order to print its arguments. The unset avoids the scriptname from being printed (which is not an input)

<?php if(!function_exists('a')){die('Hello world!');}die(a($argv));function a($b){unset($b[0]);echo implode(' ',$b);}

If only the first argument has to be printed, a shortcut can be used (101 bytes):

<?php if(!function_exists('a')){die('Hello world!');}die(a($argv));function a($b){unset($b[0]);echo implode(' ',$b);}

This however is not the full input and i consider this invalid

V (vim), Quine + Hello World = Cat, 32 bytes

Quine

dG2idG2i

Explanation:

Hello World

"_dG4iHello World!
␛pH3D

With trailing newline. TryItOnline also shows a trailing space after that, but this appears to be an artifact of it's V runner.

Explanation:

Cat

dG2idG2i"_dG4iHello World!
␛pH3D

Since all no-ops in V are automatically cat programs, the trick here is to make the combined program cancel out itself.

Explanation:

Try it online!

Python 2, Hello World + Cat = Quine, 200 198 189 bytes

Hello World

id=0;a="Hello World!";a0='id=0;a="%s";a0=%r;print a0%%((a,a0)if id<1else 1)\nimport sys\nif id:print sys.stdin.read()';print a

Cat

0%((a,a0)if id<1else 1)
import sys
if id:print sys.stdin.read()

My previous answer was actually wrong. raw_input only reads one line. This reads the entire input.

Quine

id=0;a="Hello World!";a0='id=0;a="%s";a0=%r;print a0%%((a,a0)if id<1else 1)\nimport sys\nif id:print sys.stdin.read()';print a0%((a,a0)if id<1else 1)
import sys
if id:print sys.stdin.read()

Try it online!


2020-08-05: -42 bytes thanks to Jonathan Allen, +33 to fix a bug

><>, Quine + Cat = Hello World!, 48 bytes

Quine

"r00gol?!;40.

The classic ><> quine

Cat

"]v"i:0(?;o
>l?!;o
^"Hello World!"<

A simple cat program, loaded with some other code that isn't being run.

Hello World!

"r00gol?!;40."]v"i:0(?;o
>l?!;o
^"Hello World!"<

The quine part makes the instruction pointer stop interpreting "]v" as text, instead clearing the stack and moving down to the "Hello World!" printer.


Equivalently, the program can be written as

'rd3*ol?!;40.']v'i:0(?;o
>l?!;o
^"Hello World!"<

Which, as Jo King points out, avoids using the g code reflection instruction, arguably making the quine more genuine.

05AB1E, Quine + Hello World = Cat, 23 bytes

Quine:

2096239D20BJ

Try it online (with input) or try it online (without input).

Hello World:

I.gi”Ÿ™‚ï!

Try it online (with input) or try it online (without input).

Cat:

2096239D20BJI.gi”Ÿ™‚ï!

Try it online (with input) or try it online (without input).

(All three output with trailing newline.)

Explanation:

2096239       # Push integer 2096239
       D      # Duplicate it
        20B   # Convert it to base-20 as list: "D20BJ"
           J  # Join stack together: "2096239D20BJ"
              # (after which it is output implicitly as result)

I             # Push the input (or an empty string if none is given)
 .g           # Get the amount of items on the stack (which will be 1)
   i          # If this amount is 1 (which it always is):
    ”Ÿ™‚ï!    #  Push dictionary string "Hello World!"
              #  (after which it is output implicitly as result)

2096239D20BJ  # Same as above
I             # Push the input (or an empty string if none is given)
 .g           # Get the amount of items on the stack: 2
   i          # If this amount is 1 (which it isn't):
    ”Ÿ™‚ï!    #  Push dictionary string "Hello World!"
              # (implicit else:)
              #  (implicitly output the input we pushed earlier as result)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ”Ÿ™‚ï! is "Hello World!".
Credit of the quine goes to @Grimmy's answer here.

Hello World + Quine = Cat, C (GCC), 149 (81 + 68)

Hello World

a;main(s){a?read(0,&s,1)&&main(putchar(s)):puts("Hello World!");}
#define main m

Try it online!

Quine

a=1;main(s){printf(s="a=1;main(s){printf(s=%c%s%1$c,34,s);}",34,s);}

Try it online!

Cat (Hello World + Quine)

a;main(s){a?read(0,&s,1)&&main(putchar(s)):puts("Hello World!");}
#define main m
a=1;main(s){printf(s="a=1;main(s){printf(s=%c%s%1$c,34,s);}",34,s);}

Try it online!

Alice, Cat + Quine = Hello World, 51 bytes

Cat: (With trailing newline)

\ >  "!dlroW olleH"d&O@
  ^/ v
  # < i

Try it online.

Uses # to skip the redirect west and instead hit the redirect south into the i, which pushes the input as a string to the top of the stack. The instruction pointer then reflects off the top and bottom boundaries of the grid, hitting the o and @ from the Hello World program, causing it to output the top of the stack as a string and then terminate. The code requires a trailing newline, which I couldn't get to display here in the code block.

Quine:

"!<@O&9h.

Try it online.

Just a standard Alice quine.

Hello World:

\ >  "!dlroW olleH"d&O@
  ^/ v
  # < i
"!<@O&9h.

Try it online.

The # is now used to skip the @ from the quine program, causing the instruction pointer to instead hit the redirect west, which passes through a mirror and hits two more redirects to hit a standard Alice Hello World program.

Rust, Quine + Cat = Hello, world! (106 + 2 = 108 bytes)

Quine (108 106 bytes):

-2 bytes: removed ',' from "Hello world!"

let s=format!("Hello world!");format!("{},{0:?})","let s=format!(\"Hello world!\");format!(\"{},{0:?})\"")

.into() instead of format! saves a few bytes but is context-dependent.

Cat (2 bytes):

;s

Quine + Cat = Hello, world! (110 108 bytes):

let s=format!("Hello world!");format!("{},{0:?})","let s=format!(\"Hello world!\");format!(\"{},{0:?})\"");s

Try it!

Updated to not use include_str!. Hopefully this doesn't break any rules anymore.

This relies on it being in a closure/function that implements Fn(String) -> String with argument s.


Old answer, uses include_str!:

Quine (67 bytes):

match include_str!("f"){p@_ if p.len()==67=>p,_=>"Hello, world!"}//

(Not very creative, unfortunately)

Cat (1 byte):

s

Quine + Cat = Hello, world! (68 bytes):

match include_str!("f"){p@_ if p.len()==67=>p,_=>"Hello, world!"}//s

Try it! (Repl.it link due to multiple files)

This depends on the code being in its own file named "f" and being include!'d into main.rs before being executed. The Repl.it link has the programs in separate files with different names, which means that the quine and hello world programs are different by one character so that they include the correct string.

This challenge was especially difficult in Rust (without using a comment at the end of one of the programs) because of the syntax of the language. Functions and multi-statement closures have braces surrounding them, so you can't just concat two closures to get a third, unfortunately.

Aceto, quine (67) + cat (33) = Hello World (100 bytes*)

(*I counted one file including a final newline so that catting them together works as expected)

quine (made it for this challenge):

£"24«cs%55«3+cp24«2+cdpsdpsppn"24«cs%55«3+cp24«2+cdpsdpsppn

cat:

X


n
p el
r"HlX
^^ oldnp
 ^Wor!"

The quine itself was the hardest part, due to the nature of having code on a Hilbert curve (The "Hello World", and cat programs are trivial compared to it). The solution of having the concatenated program do something else than the parts is simple in Aceto: Because the (longer-line) quine enforces a square size of an even power of two (64 = 2^6), and the cat program has, on its own, a square of size 8x8 (8 = 2^3, an odd power of two), the instruction pointer starts moving in a different direction.

Python 3, Hello World + Quine = Cat, 129 bytes

Hello World:

import os,atexit as a
p=print
a.register(p,"Hello World!")
def print(_):
 p(input())
 os._exit(0)

Quine:

s='s=%r;print(s%%s)';print(s%s)

Cat:

import os,atexit as a
p=print
a.register(p,"Hello World!")
def print(_):
 p(input())
 os._exit(0)
s='s=%r;print(s%%s)';print(s%s)

atexit lets you define cleanup steps that will run when your program exits "normally". In this case, I register the print function (renamed p) with the argument "Hello World!", so it will print that string when the program ends.

I then redefine print to become a cat function. Normally, this would cause the program to print its input and "Hello World!", but os._exit() is an "abnormal" exit that bypasses the cleanup steps.

Now that print has been redefined, the Quine simply calls this cat function and the program abruptly exits. If the Quine doesn't exist, then the program exits normally, printing "Hello World!" in the process.

The final program doesn't work on TIO, but it works for me running Python 3.7.3 on MacOS.

Bash, Quine + Cat = Hello World, 110 bytes

Quine

q='eval printf "$s" "$s"';s='q=\47eval printf "$s" "$s"\47;s=\47%s\47;$q';$q

Cat

true false&&cat||echo Hello World!

Hello World

q='eval printf "$s" "$s"';s='q=\47eval printf "$s" "$s"\47;s=\47%s\47;$q';$qtrue false&&cat||echo Hello World!

This takes advantage of the fact that undefined variables expand to the empty string and that true is a command that can take arguments.

You can trivially swap the cat and the hello world by swapping true and false