55
\$\begingroup\$

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>

\$\endgroup\$
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Dennis Jun 8 '17 at 13:41
  • \$\begingroup\$ as a bonus twist challenge, print "Hello World!" and crash with "Goodbye Cruel World!"? \$\endgroup\$ – Magic Octopus Urn Jun 8 '17 at 14:34
  • \$\begingroup\$ Suppose I'm working in a language like Java, where STDOUT and STDERR are, of course, printed in different threads. This means that, although the program, in order, prints "Hello world" and then crashes, it is possible that the stack trace will be printed first... Is that allowed? \$\endgroup\$ – Socratic Phoenix Jun 8 '17 at 14:39
  • \$\begingroup\$ @SocraticPhoenix As long as STDOUT still prints, and STDERR still prints, the order doesn't matter. Just as long as neither can block the other from happening. \$\endgroup\$ – Tezra Jun 8 '17 at 14:45
  • 1
    \$\begingroup\$ This is so much fun, I can't stop making solutions! \$\endgroup\$ – Adám Jun 9 '17 at 12:31

103 Answers 103

1
\$\begingroup\$

Java 6, 83 bytes, Score 41.5!

Java 6 loaded static initializers before searching for the main method, making it possible to bypass the lengthy main signature. However, past 6, it first looks for the main method and then static initializers, making this solution void.

class A{static{System.out.print("Hello World!");new Long("Goodbye Cruel World!");}}

Expanded:

class A {
    static {
        System.out.print("Hello World!");
        new Long("Goodbye Cruel World!");
    }
}
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

C, 60 bytes

puts("Hello, World!");puts("Goodbye, cruel world!");abort();
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Processing 3, 42 bytes

println("Goodbye Cruel World!");int b=1/0;

First try at using Processing for a golfing challenge. Couldn't figure out a way for the bonus challenge since Processing is very good at finding errors before you run your code!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Clean, 64 bytes / 2 = 32 score

-2 thanks to Jo King

import StdEnv
Start=("Hello world!",abort"Goodbye cruel world!")

Try it online!

Prints Hello world!, tries to print the second element of the tuple and aborts with Goodbye cruel world!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 55 bytes, score 27.5!

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

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

PowerShell, 49 bytes

'Goodbye Cruel World!';[Environment]::FailFast(0)

Try it online!

Prints Goodbye Cruel World! and crashes. Uses the .NET built-in FailFast() feature.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Invalid, "Goodbye Cruel World!" must be in the error \$\endgroup\$ – ASCII-only Jan 24 '19 at 3:18
  • \$\begingroup\$ @ASCII-only Fixed. \$\endgroup\$ – Gabriel Mills Jan 24 '19 at 14:41
1
\$\begingroup\$

Rust, (83) 41.5! bytes

fn main(){print!("Hello World!");"".bytes().nth(1).expect("Goodbye Cruel World!");}

Try it online!

Rust, 41 bytes

fn main(){print!("Goodbye Cruel World!")}

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ the second one's supposed to crash after it prints Goodbye Cruel World! \$\endgroup\$ – Sagittarius Dec 27 '19 at 5:28
1
\$\begingroup\$

Zsh, 18!

36/2 bytes, including hello world! for extra credit. Try it online!

echo hello world!
goodbye\ cruel\ $_

NB: The identifier $_ doesn't work with <<< because <<< runs in a sub-shell. Example

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

ink, 44! bytes

VAR a="Goodbye Cruel World!"
Hello World!->a

Try it online!

Funnily enough, even though variables created in VAR declarations are usually always available even if the VAR statement is unreachable, this program only "works" if that VAR statement comes before the divert - if it doesn't, it's a syntax error instead.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Ruby, 41 bytes / 2 = 20.5 bytes!

"Goodbye Cruel World!"&$><<"Hello World!"

Try it online!

$><< is a very useful method of output for Ruby golfing--syntax around it is very forgiving("Goodbye Cruel World!"&puts"Hello World!" would be a syntax error, for example, rather than the runtime exception we need), and << has medium precedence so we can control when it executes more freely.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Keg, 23 bytes

Basically a port of the ><> answer.

\!dlroW leurC eybdooG{,

Explanation

\!dlroW leurC eybdooG#Push "Goodbye Cruel World!"
{,#                   Forever, pop and output the top of the stack

This halts by popping an empty stack.

Keg, 13 bytes

Without the -rt flag that you can actually try it online.

“⑮I⅍Gc¡“,\!,/

Try it online!

Keg -rt, 14 bytes

(Doesn't work on TIO as Keg needs a pull)

/00,\!,“⑮I⅍Gc¡

Try it online!

Explanation

       “⑮I⅍Gc¡ # Define a space-separated string "Goodble Cruel World"
      ,        # Print it as a character
   ,\!         # Print an exclamation mark
/00            # Perform 0-division, which is an undefined operation
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 14 bytes: /00,\!,“⑮I⅍Gc¡ using -rt \$\endgroup\$ – Lyxal Dec 27 '19 at 22:14
1
\$\begingroup\$

W, 34 33/2 = 16.5 bytes

s|x@`p"Goodbye Cruel"" World!"P+/

Explanation

"Hello"p                            % Print "Hello" to STDOUT without a newline
                       " World!"P   % Output " World" to STDOUT with a newline
        "Goodbye Cruel"          +  % Join "Goodbye Cruel" with the string
                                  / % Perform division upon strings (which is undefined behavior)
                                    % Join the two different snippets of code into a single snippet

The error message provides the source code for debugging purposes.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

W d, 17 bytes

Weirdly enough, I got the same bytecount when I avoided the bonus!

.≈ò♠┐M*óö↑á☼r↕Qá╠%·

Unpacked:

CD(IdK815Ak]T&:Q>`P/

After string-decompression:

Goodbye Cruel World!"P/

Explanation

"Goodbye Cruel World!"   % Define the string "Goodbye Cruel World!"
                      P  % Output the string to STDOUT with a newline
                       / % Divide 0 by the string, which causes an error.
                         % We can't do 0-division because in W,
                         % 0-division is defined as positive infinity.
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 51 bytes, Real Crash

[console.log("Goodbye Cruel World!"),...Array(1e9)]
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python 3, 33 31

print('Goodbye Cruel World!')
e

very basic

Try it online!

Python 3, 23! 19!

print('Hello World!')
Goodbye Cruel World!

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Rexx (Regina), 39/2 37/2 bytes = 19.5!

say Hello World!
-Goodbye Cruel World!

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Mathematica, 23! Bytes

Print["Hello World!"]/."Goodbye Cruel World!";

Prints the first string then attempts to use the second string as a replacement rule which it isn't so crashes (throws an error message which is equivalent to a crash in Mathematica).

Output:

Hello World

ReplaceAll::reps: {Goodbye Cruel World!} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

C, 42 bytes

Not shorter than Steadybox's C answer, but more resistant to optimization.

main(){ftw(puts("Goodbye Cruel World!"));}

ftw has a short name and its first parameter is a pointer, so the return value from puts makes it crash.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Batch, 20.5 bytes!

@echo Hello World!
"Goodbye Cruel World!
  • +41 bytes source code
  • -50% bonus
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

tcl, 28

error "Goodbye cruel World!"

demo

| improve this answer | |
\$\endgroup\$
  • 3
    \$\begingroup\$ An anonymous user suggested improving the answer by claiming the bonus with set c World;puts Hello\ $c;Goodbye\ Cruel\ $c! \$\endgroup\$ – Martin Ender Jun 16 '17 at 18:30
0
\$\begingroup\$

T-SQL, 22 bytes

[Goodbye Cruel World!]

It tries to execute the nonexistent stored procedure called Goodbye Cruel World! -if there is no SQL Server instance with that dramatic sp-.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Windows .BAT, Score: 19.5!

echo Hello World!&"Goodbye Cruel World!

Yes it works on my CMD

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Yabasic, 21.5 bytes!

An anonymous function that takes no input, prints "Hello World!", then crashes with error "Goodbye Cruel World!"

?"Hello World!"
Error"Goodbye Cruel World!"

Try it online!

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

J, 28 Bytes

=:echo'Goodbye cruel world!'

Echoes 'Goodbye cruel world!', and then encounters a syntax error when theres no variable to assign the result (an empty list) to.

Example:

   =:echo'Goodbye cruel world!'
Goodbye cruel world!
|syntax error
|   =:echo'Goodbye cruel world!'
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Java 8, 108 bytes, score 54!

interface M{static void main(String[]a){System.out.print("Hello World!");new Byte("Goodbye Cruel World!");}}

Try it online here.

This solution attempts to create a Byte from the given String and crashes since "Goodbye Cruel World!" cannot be evaluated to an integer value.

Java 8, 93 bytes (no bonus)

interface M{static void main(String[]a){System.out.print("Goodbye Cruel World!");int i=0/0;}}

This is pretty straightforward as well. It crashes upon trying to divide by zero.

Try it online here.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Forth (gforth), 26 bytes

." Goodbye Cruel World!" =

Try it online!

Prints output text and then crashes with a stack-underflow when it tries to call equals on an empty stack (assumes stack is empty before code is executed).


Forth (gforth), 28.5! bytes

." Hello World!" s" Goodbye Cruel World!" exception throw

Try it online!

The bonus is actually worse than the basic implementation even after the score modifier, due to the required use of exception and throw to get a custom error message in Forth.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Python 3, 33 bytes

print('goodbye cruel world!')

0/0
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ I believe you need the ! at the end for it to be valid. \$\endgroup\$ – Οurous Aug 20 '18 at 6:27
  • \$\begingroup\$ oops, thank for reminding me \$\endgroup\$ – AndiChin Aug 20 '18 at 22:31
  • \$\begingroup\$ Why use \n\n0/0 instead of simply ;_? \$\endgroup\$ – Jonathan Frech Aug 20 '18 at 22:41
  • 1
    \$\begingroup\$ This answer is extremely similiar to the example one presented in the question. \$\endgroup\$ – Jonathan Frech Aug 20 '18 at 22:41
0
\$\begingroup\$

Common Lisp, 39 bytes

(format t"Goodbye, cruel world!~%")1/0

I have no real idea of LISP yet, but this should work even without a REPL but with direct eval, I have no way to proof it.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I think TIO's Common Lisp is not a REPL; it works there. \$\endgroup\$ – Jonathan Frech Aug 21 '18 at 13:24
  • \$\begingroup\$ @JonathanFrech fine then, thanks! \$\endgroup\$ – Mega Man Aug 21 '18 at 13:24
0
\$\begingroup\$

Batch, 29 Bytes

echo Goodbye Cruel World!
|{

Explanation:

echo Goodbye Cruel World!         //Prints out (echoes) "Goodbye Cruel World!"
|{                                //I just typed random stuff here and hoped it would return an error.
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ I don't think that's a crash, that's just a command to shutdown the computer \$\endgroup\$ – Jo King Oct 22 '18 at 2:49
  • \$\begingroup\$ A program that crashes the computer would have the same effect (for /p) but I still get your point and will try to rephrase my answer \$\endgroup\$ – MilkyWay90 Oct 22 '18 at 11:35
  • \$\begingroup\$ I take crash to mean the program ending prematurely or as the question phrases it, an unexpected error. The computer turning off when you use the shutdown command is completely expected behaviour... Would it not be easier to do something like set /a 1/0? \$\endgroup\$ – Jo King Oct 22 '18 at 11:40
  • \$\begingroup\$ Oh okay, I'll just put random chars after the echo. \$\endgroup\$ – MilkyWay90 Oct 22 '18 at 11:42
0
\$\begingroup\$

Pepe, 195 191 bytes

Saved 4 bytes thanks to u_ndefined.

 reeEeeeEEErEeEEeEEEEreeereeereeEEeeEeereeEEeeeEereeEEEEeeEreeEEeeEeEREeeEeeeeeReeereeEeeeeEEreeEEEeeEereeEEEeEeEreeEEeeEeEreeEEeEEeeReeereeEeEeEEEreeereeEEEeeEereeEEeEEeereeEEeeEeereeeEeeeeEReeee

Outputs exactly Goodbye Cruel World!RERROR!.

And in the debug log: R # ERROR: R doesn't exist

Try it online!

Pepe, 199 195 bytes

Saved 4 bytes thanks to u_ndefined.

Because the absence of space after the ! annoys me.

reeEeeeEEErEeEEeEEEEreeereeereeEEeeEeereeEEeeeEereeEEEEeeEreeEEeeEeEREeeEeeeeeReeereeEeeeeEEreeEEEeeEereeEEEeEeEreeEEeeEeEreeEEeEEeeReeereeEeEeEEEreeereeEEEeeEereeEEeEEeereeEEeeEeereeeEeeeeEReeeReeee

Try it online!

| improve this answer | |
\$\endgroup\$
  • 3
    \$\begingroup\$ Replacing Reeee with R works, and saves you 4 bytes, \$\endgroup\$ – u-ndefined Oct 24 '18 at 8:50
  • \$\begingroup\$ @u_ndefined I've never seen an absolutely serious comment be so hilarious. \$\endgroup\$ – Magic Octopus Urn Oct 24 '18 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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