63
\$\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
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Dennis Jun 8 '17 at 13:41
  • 1
    \$\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
  • 1
    \$\begingroup\$ This is so much fun, I can't stop making solutions! \$\endgroup\$ – Adám Jun 9 '17 at 12:31
  • 1
    \$\begingroup\$ This has a bonus, and thus is code-golf. See here. \$\endgroup\$ – Rɪᴋᴇʀ Jun 15 '17 at 1:52
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Tezra Jun 16 '17 at 15:47

108 Answers 108

1
\$\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\$
1
\$\begingroup\$

Pyth -- 38/2 = 19 !

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

Try It

\$\endgroup\$
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!");
    }
}
\$\endgroup\$
1
\$\begingroup\$

C, 60 bytes

puts("Hello, World!");puts("Goodbye, cruel world!");abort();
\$\endgroup\$
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 Jan 24 '19 at 3:18
  • \$\begingroup\$ @ASCII-only Fixed. \$\endgroup\$ – Gabriel Mills Jan 24 '19 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\$ – 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

\$\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\$ – Magic Octopus Urn Oct 24 '18 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\$ – Kevin Cruijssen Oct 24 '18 at 20:44
  • \$\begingroup\$ .•Uqʒ•’‚¿Þ¡ ÿ ‚ï!’ -> “‚¿bye±ƒuel‚ï“ for -4. There's no in modern 05AB1E, but here's an equal-bytes alternative. \$\endgroup\$ – Grimmy Sep 3 '19 at 13:41
  • \$\begingroup\$ @Grimy Thanks. Didn't knew cr was a dictionary word. \$\endgroup\$ – Kevin Cruijssen Sep 4 '19 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\$ – Kevin Cruijssen Sep 4 '19 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\$

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.

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

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
\$\endgroup\$
1
  • \$\begingroup\$ 14 bytes: /00,\!,“⑮I⅍Gc¡ using -rt \$\endgroup\$ – lyxal Dec 27 '19 at 22:14
1
\$\begingroup\$

Python 3, Score: 43/2=21.5!

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

Try it online!

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

JavaScript: 24.5!

alert('Hello World!');throw'Goodbye Cruel World!'

If alert does not count as a valid output function, then I will use console.log (3 extra points).

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

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

Windows .BAT, Score: 19.5!

echo Hello World!&"Goodbye Cruel World!

Yes it works on my CMD

\$\endgroup\$

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.