62
\$\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\$
27
  • 1
    \$\begingroup\$ as a bonus twist challenge, print "Hello World!" and crash with "Goodbye Cruel World!"? \$\endgroup\$ Commented Jun 8, 2017 at 14:34
  • 1
    \$\begingroup\$ This is so much fun, I can't stop making solutions! \$\endgroup\$
    – Adám
    Commented Jun 9, 2017 at 12:31
  • 1
    \$\begingroup\$ Can your program print extra text? \$\endgroup\$
    – ericw31415
    Commented Jun 12, 2017 at 14:00
  • 1
    \$\begingroup\$ @ericw31415 Only if that is part of the error output. \$\endgroup\$
    – Tezra
    Commented Jun 12, 2017 at 14:16
  • 1
    \$\begingroup\$ This has a bonus, and thus is code-golf. See here. \$\endgroup\$
    – Riker
    Commented Jun 15, 2017 at 1:52

113 Answers 113

1
\$\begingroup\$

Kitanai (28 bytes)

print"Goodbye Cruel World!"z

It just prints "Goodbye Cruel World!" then tries to call unknown function z (so it crashes)

\$\endgroup\$
1
\$\begingroup\$

Lua, 47 / 2 == 23 bytes

Prints "Hello World!" to STDOUT, then crashes with "Goodbye cruel world!" and a stack trace to SDTERR.

print"Hello World!"
error"Goodbye cruel world!"
\$\endgroup\$
1
\$\begingroup\$

Micro, 24 20.5

"Hello, World!":\"Goodbye, cruel world"0/

Previous version, no bonus:

""Goodbye, cruel world"0/
\$\endgroup\$
1
\$\begingroup\$

Pyth -- 38/2 = 19 !

K" World!"p"Hello"Kp"Goodbye Cruel"KsG

Try It

\$\endgroup\$
1
\$\begingroup\$

C, 60 bytes

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

JavaScript 58 bytes , with bonus 58/2 = 29 bytes

console.log("Hello World!");
throw "Goodbye Cruel World!"

Very Straightforward , I have crashed the program with the "Good Bye Cruel World!" error.

EDIT : Thanks to eithed and Erik the OutGolfer , Saved 36 bytes !. Hope this method still works for the challenge

\$\endgroup\$
2
  • \$\begingroup\$ You don't need to assign the message - console.log("Hello World!");throw new Error("Goodbye Cruel World!") will suffice (or even console.log("Hello World!");throw "Goodbye Cruel World!", though the rules are kind of weird for JS on this one) \$\endgroup\$
    – eithed
    Commented Jun 9, 2017 at 14:51
  • \$\begingroup\$ You can remove superfluous whitespace around the =s and newlines after ;s. \$\endgroup\$ Commented Jun 11, 2017 at 11:14
1
\$\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!'
\$\endgroup\$
1
\$\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.

\$\endgroup\$
0
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!

\$\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!

\$\endgroup\$
0
1
\$\begingroup\$

JavaScript, 55 bytes, score 27.5!

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

\$\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.

\$\endgroup\$
2
  • \$\begingroup\$ Invalid, "Goodbye Cruel World!" must be in the error \$\endgroup\$
    – ASCII-only
    Commented Jan 24, 2019 at 3:18
  • \$\begingroup\$ @ASCII-only Fixed. \$\endgroup\$
    – GMills
    Commented Jan 24, 2019 at 14:41
1
\$\begingroup\$

Stax, 16 bytes

ö╞îö~l%♀~K5╓╖]Æ(

Run and debug it

It's a compressed string literal, followed by a packed Qe. Q peeks and outputs, and e is eval, which fails.

\$\endgroup\$
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!

\$\endgroup\$
1
  • \$\begingroup\$ the second one's supposed to crash after it prints Goodbye Cruel World! \$\endgroup\$ Commented Dec 27, 2019 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

\$\endgroup\$
1
\$\begingroup\$

05AB1E (legacy), score: 13.5 13 11.5 (23 bytes / 2 for bonus)

…Ÿ™‚ï!“‚¿bye±ƒuel‚ï!“.ǝ

Try it online.

-1.5 (-3 bytes) thanks to @Grimy.

Outputs in full lowercase.

05AB1E (legacy) is unable to exit with an error as far as I know (unless there is a bug in its source code), so instead this will print hello world! to STDOUT and goodbye cruel world! to STDERR.

Explanation:

…                 # Three lowercase dictionary-compressed words with space delimiter
 Ÿ™               #  "hello"
   ‚ï             #  "world"
     !            #  Literal "!"
“             “   # Push dictionary string in lowercase with automatic space-delimiter:
 ‚¿bye±ƒuel‚ï!    #  "goodbye cruel world!"
               .ǝ # Print to STDERR
                  # And print the top of the stack to STDOUT implicitly

See this 05AB1E this of mine (section How to use the dictionary?) to understand why …Ÿ™‚ï! is hello world! and “‚¿bye±ƒuel‚ï!“ is goodbye cruel world!.


05AB1E, score: 11.5 (23 bytes / 2 for bonus)

…Ÿ™‚ï!,“‚¿bye±ƒuel‚ï!“F

Unlike the legacy version, the new version is able to error out sometimes. The difference between the above program are:

  • The ,, which is an explicit print with trailing newline
  • And F instead of , which is a ranged loop and will error because the "goodbye cruel world!" is not an integer:

(RuntimeError) Could not convert goodbye cruel world! to integer.

\$\endgroup\$
6
  • \$\begingroup\$ } exits in an error (non-legacy). Try it online! Also, for legacy .0 causes division by 0 error forcibly. \$\endgroup\$ Commented Oct 24, 2018 at 17:47
  • \$\begingroup\$ @MagicOctopusUrn Ah, completely forgot about .0, since the commands had already changed when I posted this and it's not in the new version anymore. As for the errors in the Elixir rewrite, it can crash with quite a few different ways now, but mostly due to a bug that wasn't in the legacy version yet, so usually I report it in the 05AB1E chat to Adnan. \$\endgroup\$ Commented Oct 24, 2018 at 20:44
  • \$\begingroup\$ .•Uqʒ•’‚¿Þ¡ ÿ ‚ï!’ -> “‚¿bye±ƒuel‚ï“ for -4. There's no in modern 05AB1E, but here's an equal-bytes alternative. \$\endgroup\$
    – Grimmy
    Commented Sep 3, 2019 at 13:41
  • \$\begingroup\$ @Grimy Thanks. Didn't knew cr was a dictionary word. \$\endgroup\$ Commented Sep 4, 2019 at 6:43
  • 1
    \$\begingroup\$ @Grimy Woops, should have been 23 instead of 22.. Your versions were missing the exclamation mark in the goodbye cruel world!. I've updated the 11 to 11.5 when I noticed that, but forgot to update the 22. \$\endgroup\$ Commented Sep 4, 2019 at 9:27
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.

\$\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.

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 51 bytes, Real Crash

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

05AB1E, score 14.5 14!

”Ÿ™‚ï!”,.•1{ø{β?Õ&>₅₁\•™'!«ι

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Python 3, Score: 43/2=21.5!

+print("Hello"+"Goodbye Cruel World!"[-7:])

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Vyxal, 10.5! bytes

`ƛ⁋Ṗ⊍ Crꜝ∞ ƛ€!`kh\!+←

Try it Online!

`...`        # Push 'Goodbye Cruel World!' as a compressed string
     kh\!+,  # Push 'Hello World!', which will be implicitly output even though the program errors.      
           ← # Crash by accessing a nonexistent variable, Vyxal logs the stack on erroring
\$\endgroup\$
1
\$\begingroup\$

KonamiCode, 356 bytes

v(^^^^^^^>^)>((>))v(^>^>^)>((>))v(^>^>^)>((>))v(^>>)>((>))v(^^^^^^^^^>^^^^^^^^)>((>))v(^>^^>^)>((>))v(^>>^)>((>))v(^^^>^^)>((>))v(^^^^^^^^^>^^^^^^^^^)>((>))v(^>^>^^^^)>((>))v(^>^>^^^^^^^)>((>))v(^>>^)>((>))v(^>>^^^^^^^^)>((>))v(^^^>^^)>((>))v(^>^>^^^^^^^^^)>((>))v(^>^>^)>((>))v(^>^>^^^^)>((>))v(^>>^^^^^^^^)>((>))v(^>>)>((>))v(^^^>^^^)>(>)L(>)<<>((>))B(>)

Sadly, the fact that we have to encode "Goodbye, cruel world!" makes this very long.

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 51 / 2 = 25.5! 43 / 2 = 21.5!

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

console.log can be changed to alert and ("") to backticks saving 8 bytes (but I'm not sure this is eligible):

"Goodbye Cruel World!"(alert`Hello World!`)

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf! The second one is valid, alert can be used for output under site rules \$\endgroup\$
    – rydwolf
    Commented Jun 22, 2023 at 17:43
  • \$\begingroup\$ Thank you for clarifying, I've updated the score to match the shorter version. \$\endgroup\$
    – Nikolay
    Commented Jun 22, 2023 at 20:41
0
\$\begingroup\$

C++, 66 bytes

Compiles with VS 2017. A little type confusion for the crash.

extern"C"{int puts(void*);int main=puts("Goodbye Cruel World!");}
\$\endgroup\$
0
\$\begingroup\$

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

say Hello World!
-Goodbye Cruel World!

Try it online!

\$\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. >>
\$\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.

\$\endgroup\$
0
\$\begingroup\$

Batch, 20.5 bytes!

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

tcl, 28

error "Goodbye cruel World!"

demo

\$\endgroup\$
1
  • 3
    \$\begingroup\$ An anonymous user suggested improving the answer by claiming the bonus with set c World;puts Hello\ $c;Goodbye\ Cruel\ $c! \$\endgroup\$ Commented Jun 16, 2017 at 18:30

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.