# Goodbye Cruel World!

## Background

Hello golfers! I would like to learn all the programming languages! But I kinda have a short attention span... and copying all the Hello World examples gets boring... but I like fire! ^w^

## Challenge

So here is the plan! I want you all to write the smallest code that will compile, print Goodbye Cruel World!, and then crash. Or, as a bonus twist challenge, print Hello World! and crash with Goodbye Cruel World!

## Rules

• Your score will be total character count used. The answer must be a whole executable program.
• Your program must print Goodbye Cruel World! to output, and then crash (unexpected error).
• For a score bonus, you must print Hello World! to output instead, but the error message must also contain Goodbye Cruel World!. If you complete the bonus challenge, you may divide your score by 2. (Include a ! at the end of your score if you are claiming the bonus!)
• As long as the standard output still prints, and standard error still prints, the order doesn't matter. Just as long as neither can block the other from happening.
• The output must contain the contents of the above; " shouldn't appear in the output.
• The output should contain the specified string, and nothing else.
• The crash report can contain anything, but to claim the bonus, the following regex should match /Goodbye Cruel World!/mi (aka, contains, ignore case/surrounding text))
• The strings Hello World! and Goodbye Cruel World! are case insensitive, but otherwise should appear exactly as above.
• If the language is capable of crashing (it cannot change its exit code), it needs to crash. Otherwise use the standard "error report" (i.e., STDERR) for the language.

I can crash Python 3, so I have included an example Python 3 answer! Now lets all set the world on fire! ^W^

var QUESTION_ID=125282,OVERRIDE_USER=0;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+r.match(SCORE_REG)[0],language:r.match(LANG_REG)[0].replace(/<\/?[^>]*>/g,"").trim(),link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/\d+((?=!?)|(?= Bytes))/i,OVERRIDE_REG=/^Override\s*header:\s*/i;LANG_REG=/^[^,(\n\r\|]+/i body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px} <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=617d0685f6f3"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> • Comments are not for extended discussion; this conversation has been moved to chat. Jun 8, 2017 at 13:41 • as a bonus twist challenge, print "Hello World!" and crash with "Goodbye Cruel World!"? Jun 8, 2017 at 14:34 • This is so much fun, I can't stop making solutions! – Adám Jun 9, 2017 at 12:31 • This has a bonus, and thus is code-golf. See here. Jun 15, 2017 at 1:52 • @Riker Did you mean to say "is not code-golf"? I think it still is, as the bonus is just an optional, harder version. The bonus modifier is just to make it viable as the preferred solution. My other options are post as separate question (would be closed as a dup), or use a different tag (which, at the end of the day, this is just 2 different difficulty code-golf challenges together, so doing that would defeat the point of the code-golf tag). For any rule, there will always be a good exception (I think this use case counts as one) And no one here seems bothered by it. Jun 16, 2017 at 15:47 ## 109 Answers # Jelly, 12 bytes “¿µƝɓṭỵae»Ȯ:  Try it online! Explanation: “¿µƝɓṭỵae»Ȯ: Ȯ Print “¿µƝɓṭỵae A string... » Decoded from base-250 : Integer division  As the integer division is a dyad, it will implicitly take the chain's current value as both arguments - which is a string. Crashes because it expects integers. • Welcome to PPCG! Jun 8, 2017 at 13:56 • Thank you! I've been lurking for a while now but this is the first time I found a challenge that I felt like I could actually solve decently! Jun 8, 2017 at 14:02 • Impressive answer, although nearly all Jelly answers are impressive, both because of the length and the fact that you managed to learn Jelly. Jun 8, 2017 at 16:38 • A base-250 encoded string That is both cool an scary that you can do that. X3 Jun 8, 2017 at 20:39 • This is significantly shorter than the string "Goodbye cruel world!" (20 bytes). Crazy... Jun 11, 2017 at 2:45 # C, 43 bytes main(){puts(puts("Goodbye Cruel World!"));}  Prints the string and then tries to use the return value as a pointer to another string to be printed, which causes a segmentation fault. Try it online! # C, 42 bytes Thanks to @Ruslan! main(i){i=puts("Goodbye Cruel World!")/0;}  Try it online! Just for fun: C (on 64-bit Linux), 149 bytes Modified from this Hello World -program here. const int main[]={-443987883,440,113408,-1922629632,4149,1358336,84869120,15544,266023168,1869563654,1702453860,1970422560,1461742693,1684828783,33};  Try it online! • main(i){i=puts("Goodbye Cruel World!")/0;} strips one byte off. Jun 9, 2017 at 14:42 • @Ruslan Thanks. I initially had i;f(){i=puts("Goodbye Cruel World!")/0;}, but f(){puts(puts("Goodbye Cruel World!"));} had the same length and was more interesting. It seems that f(i){i=puts("Goodbye Cruel World!")/0;} would have worked too. Jun 9, 2017 at 15:27 • You don't need i. puts("")/0; is a syntactically correct statement. – rici Jun 11, 2017 at 14:55 • @rici Yes it is, but it doesn't crash (at least on TIO). Jun 11, 2017 at 16:38 • @Steadybox: that's optimization for you. – rici Jun 11, 2017 at 18:57 # sed, 32 bytes iGoodbye Cruel World! w/dev/full  i inserts a line, and w writes to a file. /dev/full in this case because all writes to it return ENOSPC ("No space left on device"). It still needs a single line of input to work, though.  echo 1 | sed -f crash.sed
Goodbye, cruel world!
sed: couldn't flush /dev/full: No space left on device

• Didn't even know there exists such a device! Jun 9, 2017 at 15:06

# R, 22 20! bytes (44/2) (40/2)

cat("Hello World!")
Goodbye Cruel World!


Try it online!

### Output:

Hello World!

Saved two points thanks to digEmAll

• You can shorten it to 40/2  Try it online! Aug 25, 2018 at 12:09

## ><>, 25 bytes

"!dlroW leurC eybdooG">o<


Basically it adds the string to the stack (Backwards, last in first out) and then does the equivalent of:

while(1):
pop the stack
print the character


When there are no characters left on the stack (The whole string has been printed) popping the stack gives an error

• +1. Came to #o<"Goodbye Cruel World!", which is basically the same. Mar 24, 2018 at 4:06

# Python 3 | Score: 24.5!23 22!

print("Hello World!")+"Goodbye Cruel World!"


Print "Hello World", than use invalid operator '+' on "Goodbye Cruel World!" to the NoneType return element. (cut out \n\r from previous version)

Try it online!

# Python 3 | Score: 34 30

+print("Goodbye Cruel World!")


Print Goodbye, than do an invalid unary + operation on print result (NoneType)

Try it online!

• +"Goodbye Cruel World!" is shorter by 3 bytes and outputs a TypeError. Jun 8, 2017 at 14:01
• print("Goodbye Cruel World!")/0 is shorter for the second one (3 bytes?) Jun 8, 2017 at 15:39
• @matsjoyce I was afraid that would crash before the print. But since it prints first, I'll just do unary on the print 'result' :3 Jun 8, 2017 at 15:48
• 2.585e+22 is a pretty big score... you sure you couldn't golf it down more? Jun 8, 2017 at 16:51
• @tuskiomi The '!' means that the final score is modified by the bonus challenge. Jun 8, 2017 at 16:57

# SOGL, 1525 17 bytes / 2 = 8.5!

Q7┌θ/²?‘■←#c℮‘o0n


Explanation:

...‘           push "goodbye cruel world!"
...‘       push "hello world!"
o     output "Hello World!"
0n  attempt to make an array where each line is 0 characters long, making the array
required to be infinite, which crashes (OutOfMemoryError)


(Ab)uses the fact that SOGL uses STDERR as a debug output, so in it there is a lot of text, along with the line

∑@22: ["goodbye cruel world!"]


If you piped the STDOUT of the Processing sketch to a file, the "Goodbye Cruel World!" would be there.

• Since the challenge mentions "The strings Hello World! and Goodbye Cruel World! are case insensitive, but otherwise should appear exactly as above.", you can golf your code by getting rid of the function █ entirely and just output in all lowercase. Aug 23, 2018 at 10:08
• @KevinCruijssen oh huh, thanks! Aug 23, 2018 at 10:45

## Lua, 31, 30 bytes

a=-print'Goodbye Cruel World!'


first prints out 'Goodbye Cruel World!' and then crashes when trying to add a nil value and 0.

Output:

Goodbye Cruel World!
input:1: attempt to perform arithmetic on a nil value


Credit to GalladeGuy for 1 byte less

• it prints out 'Goodbye Cruel World!' and then crashes though which i just thought it would simply have to crash to be accepted. Jun 11, 2017 at 17:42
• @Trebuchette The requirement is "Your program must print Goodbye Cruel World! to output, and then crash", the OP did not specify whether or not "output" means stderr, stdout, a messagebox, or any of the above. Jun 12, 2017 at 0:27
• @Pharap Oh, I see. STDERR only matters if you're going for the bonus. Thanks! Jun 12, 2017 at 6:25
• @Trebuchette Nope. It says "Or, as a bonus twist challenge, print Hello World! and crash with Goodbye Cruel World!". 'crash' does not necissarily imply stderr, 'crash' can also mean (among other things) an exception being thrown. Unless the OP defines it further it's open to interpretation. Also some applications of Lua have no concept of stderr (e.g. Lua embedded as a scripting language for games) and will instead print to a message box or a log file etc. Jun 12, 2017 at 6:57
• You can save a byte by doing this instead: a=-print"Goodbye Cruel World!" Aug 21, 2018 at 1:47

# C Preprocessor, 27 bytes

#error Goodbye Cruel World!


Output:

fatal error C1189: #error:  Goodbye Cruel World!

• You may be able to shorten it further with just #Goodbye Cruel World! Jun 10, 2017 at 23:58
• @apricotboy That would still produce an error but the full error message "goodbye cruel world" isn't output by the compiler (on MSVC at least) Jun 19, 2017 at 16:02
• @Gorvind Parmar ah. Well it definitely does on gcc: i.imgur.com/qmGnoJv.png Jun 20, 2017 at 4:27

# AWK, 72 bytes, Score 36!

BEGIN{print"Hello World!";print"Goodbye Cruel World!">"/dev/stderr";0/0}


Try it online!

AWK isn't fond of trying to divide by 0.

# Operation Flashpoint scripting language, 45/2 = 22.5 bytes

f={hint"Hello World!";a Goodbye Cruel World!}


Call with:

call f;


Output:

# CJam, 34 bytes, score 17!

"Goodbye Cruel World!"D>"Hello"ooo


Try it online! (See Debug panel for STDERR)

### Explanation

"Goodbye Cruel World!"              e# Push "Goodbye Cruel World!".
D>            e# Slice after index 13: " World!".
"Hello"o    e# Push "Hello" and print it.
o   e# Print " World!".
o  e# Attempt to print from an empty stack. Crashes.


On TIO, it generates this error message:

"Goodbye Cruel World!"D>"Hello"ooo
^
RuntimeException: The stack is empty
Java exception:
java.lang.RuntimeException: The stack is empty


# APL (Dyalog), 17.5 bytes

### Without bonus, 20 bytes

Goodbye Cruel World!


Try it online!

Note that the code is unquoted, so APL tries to execute it but World is not defined, causing a VALUE ERROR crash with the offending line of code included in the error message.

### With bonus, 35 ÷ 2 = 17.5 bytes

'Hello World!'
Goodbye Cruel World!


Try it online!

First prints the required string, then crashes like the above program.

### More sofisticated bonus version, 35 ÷ 2 = 17.5 bytes

⍎'Goodbye Cruel',5↓⎕←'Hello World!'


Try it online!

Prints the first string, then drops the first five characters from that (5↓), then concatenates that (,) to a new prefix, and then attempts to execute (⍎) that, causing the same error as above.

• @Cyoce Typo. Thanks
Jun 10, 2017 at 22:05

# TeX, 19!

Hello World!#\bye Goodbye Cruel World!


To force TeX to actually produce a dvi/pdf file without manual intervention, compile with -interaction=nonstopmode.

It prints Hello World!, throws an error for using # when you're not supposed to and then stops compilation with \bye. However, whatever's after \bye is still output in the error message, so it applies for the bonus.

# C#, 116 / 2 = 58 bytes!

using System;class P{static void Main(){Console.Write("Hello World!");throw new Exception("Goodbye Cruel World!");}}


Normal version for 94 87 bytes:

class P{static void Main(){System.Console.Write("Goodbye Cruel World!");int n=0;n/=n;}}


Saved 7 bytes thanks to @KevinCruijssen.

• int n=0;n/=n; is shorter for your first answer. Jun 9, 2017 at 9:44
• @KevinCruijssen Nice spot, I was having trouble with getting it to compile without division by constant zero error. Jun 9, 2017 at 9:46
• Yeah, in Java you can just do int n=1/0;, but apparently that isn't possible in C# (which is actually a good thing for the language, but bad for codegolfing). Btw, why isn't the bonus on at the top? That one is shorter. Jun 9, 2017 at 10:35
• @KevinCruijssen I wasn't sure if it qualified as it was a bit unclear when I posted my answer, seeing as it has been further clarified I've switched them around. Jun 9, 2017 at 10:37

# WinDBG (Windows XP/Vista Local Kernel Debugging), 33 bytes

.echo Goodbye Cruel World!;.crash


Warning: This will crash the entire machine, not just the program.

Local kernel debugging is only allowed on Windows XP and Vista (but not enabled by default in Vista). The WinDBG dialog on local kernel debugging does't mention any other Windows OS so I assume it can't even be enabled for those. Presumably for other Windows OS's you can attach to a remote machine for kernel debugging, but it's the remote machine that will crash so I don't think this solution counts there.

• Local kernel debugging is also supported on Windows 7, and I haven't heard that it's been removed since then (but I may have missed it). Jun 11, 2017 at 13:06

# JS (ES5), 46 / 2 = 23 bytes!

alert("Hello, World!")["Goodbye Cruel World!"]


Alerts Hello, World!, then errors with Uncaught TypeError: Cannot read property 'Goodbye Cruel World!' of undefined

Bash 20.5! 18.5!

I am not going to bash jelly, but I am a little bashful of my bash at bashing out a quick bash script. 18.5 isn't too bad for a non-golfing language. (Note this has to be a script, interactive bash will try to interpret ! as a history lookup)

echo Hello World!
Goodbye\ Cruel\ $_  Returns with error code 127 and: Hello World! bash.sh: line 2: Goodbye Cruel World!: command not found  As requested no "'s... anywhere :). As suggested by apricot boy I now lookup the last argument of the previous command to save 4 bytes. • I tried to beat you … and failed with 21! bytes. :) W=\ World\!;echo Hello$W;"Goodbye Cruel$W" Jun 10, 2017 at 22:10 • You could probably change the second line to Goodbye\ Cruel\ !$, not 100% but pretty sure that !$ is "last word of last command" Jun 11, 2017 at 0:03 • But what if an executable named "Goodbye Cruel World!" exists in the PATH? :) Aug 19, 2019 at 17:50 • Verified OK on TIO.run... beats my zsh answer :/ Aug 21, 2019 at 3:41 # PowerShell, 26 Bytes 'Goodbye Cruel World!';1/0  I think dividing by 0 is the easiest way to throw an error. # PowerShell, 35/2 = 17.5 Bytes "Hello World!";Goodbye Cruel World!  by TessellatingHeckler, throws the error like so: PS C:\Users\Connor> "Hello World!";Goodbye Cruel World! Hello World! Goodbye : The term 'Goodbye' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:16 + "Hello World!";Goodbye Cruel World!  • Shouldn't it be $w='World!' (with an !)? Jun 11, 2017 at 2:53
• "Hello World!";Goodbye Cruel World! is 17.5 bytes, throws an exception because Goodbye is not recognized as a command, and the exception message includes the line in full so it matches the regex.. Jun 11, 2017 at 19:21
• Using the same logic as the 17.5b answer, 'Goodbye Cruel World!';x would save two bytes for 24 Aug 20, 2018 at 23:10

# Fortran (GFortran), 58/2=29 bytes!

PRINT*,'Hello World!'
ERRORSTOP 'Goodbye Cruel World!'
END


Try it online!

## Node.js, Score: 25.5 24.5!

Saved 1 point thanks to ETHproductions

A syntactically correct full program which crashes at runtime because console.log() is not returning a function.

console.log('Hello World!')Goodbye Cruel World!


Try it online!

• Sadly, there is no factorial for 25.5... :(( Jun 8, 2017 at 13:37
• @Mr.Xcoder It is Gamma(26.5), as with Mathematica definition. Jun 8, 2017 at 15:39
• @user202729 who said Mathematica ain't broken? :))) Jun 8, 2017 at 15:40
• Can you remove the X (and maybe even the newline)? Jun 8, 2017 at 16:58
• @ETHproductions Yes indeed. Thanks! Jun 8, 2017 at 17:03

# Aceto, score: 21.5!

yeru
b Ce+
do l"d
GoWorl
"!dl
p"or
HeW
"llo


Prints Hello World!, then crashes with

Traceback (most recent call last):
File "/Users/l3viathan/bin/aceto", line 230, in _plus
self.push(y+x)
TypeError: unsupported operand type(s) for +: 'int' and 'str'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/l3viathan/bin/aceto", line 811, in <module>
A.run()
File "/Users/l3viathan/bin/aceto", line 104, in run
raise e
File "/Users/l3viathan/bin/aceto", line 98, in run
self.step()
File "/Users/l3viathan/bin/aceto", line 152, in step
method(self, cmd)
File "/Users/l3viathan/bin/aceto", line 233, in _plus
raise CodeException(f"Can't add {x!r} to {y!r}")
__main__.CodeException: Can't add 'Goodbye Cruel World' to 0


# Pyth, 28 24 bytes

"GOODBYE CRUEL WORLD!"hY


Prints a string, then tries to get the first element of the empty list.

Try this!

# Japt, 22 bytes

°Oo!dlžW ¤¨C eybºoGw

°Oo!dl&#158;W ¤¨C eybºoGw
Oo                            output
!dl&#158;W ¤¨C eybºoG     the compressed string "!dlroW leurC eybdooG"
w    reversed.
°                              ° transpiles to ++, causing an error; a string can't be incremented


Try it online!

Saved 3 bytes thanks to obarakon and ETHproductions

• You can compress the string using Oc"<string>" and then replace the current string with the compressed version and surrounded by backticks.
– Luke
Jun 8, 2017 at 13:39
• An explanation would be nice. Jun 9, 2017 at 8:39
– Tom
Jun 9, 2017 at 9:26

# Jelly, 10.5! bytes

“,ḷṅḳȦ»¹“¿µƝɓṭỵae»+/R


Try it online!

This exploits undefined behavior, using Python strings (strings) instead of Jelly strings (list of 1-char strings). The conversion is done by reducing the Jelly string by addition, and Python's + concatenates two strings, so two strings added together are concatenated Python-wise. Then, it uses the appropriate monad (range) so that Python's int is called on the string, resulting in an error that would always contain Goodbye Cruel World!.

Explanation:

“,ḷṅḳȦ»¹“¿µƝɓṭỵae»+/R Main Link, niladic.
“,ḷṅḳȦ»¹              Print "Hello World!"
“¿µƝɓṭỵae»+/  Convert "Goodbye Cruel World!" to a Python string
R Make a range out of it


# x86-64 Binary Code (with Linux system calls), 43 bytes

## Disassembly:

0:  31 c0                   xor    eax,eax
2:  ff c0                   inc    eax            ; write syscall number = 1
4:  31 ff                   xor    edi,edi
6:  ff c7                   inc    edi            ; stdout file descriptor = 1
8:  48 8d 35 07 00 00 00    lea    rsi,[rip+0x7]  ; load the string at offset 16 into rsi
f:  31 d2                   xor    edx,edx
11: b2 15                   mov    dl,0x15        ; 21 byte string
13: 0f 05                   syscall
15: f4                      hlt
16: 47 6f 6f 64 62 79 65 20 43 72 75 65 6c 20 57 6f 72 6c 64 21 0a .ascii "Goodbye Cruel World!\n"

Note: 0x16 code bytes + 0x15 string bytes = 0x2B = 43 total bytes


This program bundles the data it needs (the string "Goodbye Cruel World!\n") into its own code. It loads a pointer to that string using rip relative addressing, and calls the write syscall directly rather than through a glibc wrapper, so it's entirely position-independent, and we can easily test it by embedding the code into a const string and casting that string to a function pointer. To crash the program, I end it with a hlt instruction, which with ring 0 privileges would silence the processor forever (or at least until the next interrupt comes in), but with ring 3 privileges (typical for user programs) we get a far less dramatic Segmentation Fault.

## Test Program:

#include <stdio.h>

const char code[43] = "\x31\xC0\xFF\xC0\x31\xFF\xFF\xC7\x48\x8D\x35\x07\x00\x00\x00\x31\xD2\xB2\x15\x0F\x05\xF4Goodbye Cruel World!\n";

int main() {
printf("Code bytes: %zi\nNow running the code:\n\n", sizeof(code));
((void(*)())code)();
printf("Failed to crash, now exiting!\n");
return 0;
}


## Output:

Code bytes: 43
Now running the code:

Goodbye Cruel World!
Segmentation fault


Note that the 43 byte code is a complete program as specified by the challenge, not just a function. It doesn't depend on the main function of the test program to function correctly; it would still print the string and crash if loaded and jumped-to by the loader directly.

• Save a few bytes by using push/pop to load registers. For example, the first two instructions can be push 1+pop rax, which is 1 byte shorter. Then, the next two instructions can be replaced with mov edi, eax, which is 2 bytes shorter. The same push/pop trick can be applied to instructions 6 and 7: push 0x15+pop rdx. Jun 11, 2017 at 13:02

# LOLCODE, I CAN HAZ 21 BYTES

:Goodbye Cruel World!


Simply places an invalid operator in front of the string. You can give it a go online here.

# OCaml, 28.5! (57 Bytes / 2)

The OCaml version:

print_string"Hello World!";failwith"Goodbye Cruel World!"


The output is:

Hello World!Fatal error: exception Failure("Goodbye Cruel World!")

• Welcome to the site! :) Mar 24, 2018 at 13:20

# Rust, 66 bytes / 2 = 33

fn main(){println!("Hello World!");panic!("Goodbye Cruel World!")}


Try it online!

Prints "Hello World!" and makes the the program panic with message "Goodbye Cruel World!" The panic! macro doesnt need a semicolon because it returns () just like the main function.

• Hi and welcome to PPCG! Just a small correction: the panic! macro returns the never type (!), which can be used as any type (including ()) example playground Aug 21, 2018 at 16:27
• todo! is shorter than panic! (although not supported in TIO) and print! is shorter than println!. You can save 3 bytes for a score of 31.5 :) Aug 3, 2020 at 23:45

# x86 and x64_64 machine language on Linux, 38 61 bytes/2=30.5! 60 bytes/2=30!

00:       e8 20 00 00 00          call  0x25
05:       48 65 6c 6c 6f 20 57    "Hello World!Goodbye Cruel World!"
6f 72 6c 64 21 47 6f
6f 64 62 79 65 20 43
72 75 65 6c 20 57 6f
72 6c 64 21
25:       59                      pop   %ecx
26:       6a 01                   push  $0x1 28: 5b pop %ebx 29: 6a 0c push$0xc
2b:       5a                      pop   %edx
2c:       6a 04                   push  $0x4 2e: 58 pop %eax 2f: cd 80 int$0x80
33:       b3 02                   mov   $0x2,%bl 35: b2 14 mov$0x14,%dl
37:       2c 08                   sub   $0x8,%al 39: cd 80 int$0x80
3b:       6e                      outsb  %ds:(%esi),(%dx)


Prints Hello World! to stdout and Goodbye Cruel World! to stderr. Crashing is easy in machine language. To Try it online!, compile and run the following C program.

const char main[]="\xe8 \0\0\0Hello World!Goodbye Cruel World!Yj\1[j\fZj\4X\xcd\x80\1\xc1\xb3\2\xb2\24,\b\xcd\x80n";


EDIT: TIO link now works again.

• Since a 64 bit number can represent 8 chars, I wonder if it is possible to construct the string using some clever arithmetic and shifting. Specifically 47 6f 6f 64 62 79 65 20 43 72 75 65 6c 20 57 6f 72 6c 64 21.
– qwr
Apr 1, 2018 at 2:57
• 64 bit multiply fills up rdx:rax
– qwr
Apr 1, 2018 at 3:22