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

107 Answers 107

37
\$\begingroup\$

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!

\$\endgroup\$
6
  • 2
    \$\begingroup\$ main(i){i=puts("Goodbye Cruel World!")/0;} strips one byte off. \$\endgroup\$ – Ruslan Jun 9 '17 at 14:42
  • \$\begingroup\$ @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. \$\endgroup\$ – Steadybox Jun 9 '17 at 15:27
  • 2
    \$\begingroup\$ You don't need i. puts("")/0; is a syntactically correct statement. \$\endgroup\$ – rici Jun 11 '17 at 14:55
  • 2
    \$\begingroup\$ @rici Yes it is, but it doesn't crash (at least on TIO). \$\endgroup\$ – Steadybox Jun 11 '17 at 16:38
  • 1
    \$\begingroup\$ @Steadybox: that's optimization for you. \$\endgroup\$ – rici Jun 11 '17 at 18:57
36
\$\begingroup\$

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.

\$\endgroup\$
5
  • 7
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ – Dennis Jun 8 '17 at 13:56
  • \$\begingroup\$ 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! \$\endgroup\$ – scatter Jun 8 '17 at 14:02
  • 30
    \$\begingroup\$ Impressive answer, although nearly all Jelly answers are impressive, both because of the length and the fact that you managed to learn Jelly. \$\endgroup\$ – Gryphon Jun 8 '17 at 16:38
  • 4
    \$\begingroup\$ A base-250 encoded string That is both cool an scary that you can do that. X3 \$\endgroup\$ – Tezra Jun 8 '17 at 20:39
  • 3
    \$\begingroup\$ This is significantly shorter than the string "Goodbye cruel world!" (20 bytes). Crazy... \$\endgroup\$ – Adam Plocher Jun 11 '17 at 2:45
11
\$\begingroup\$

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
\$\endgroup\$
1
  • 4
    \$\begingroup\$ Didn't even know there exists such a device! \$\endgroup\$ – Ruslan Jun 9 '17 at 15:06
11
\$\begingroup\$

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

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

Try it online!

Output:

Hello World!

Error: object 'Goodbye Cruel World!' not found

Saved two points thanks to digEmAll

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

><>, 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

\$\endgroup\$
1
  • \$\begingroup\$ +1. Came to #o<"Goodbye Cruel World!", which is basically the same. \$\endgroup\$ – hakr14 Mar 24 '18 at 4:06
10
\$\begingroup\$

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!

\$\endgroup\$
6
  • \$\begingroup\$ +"Goodbye Cruel World!" is shorter by 3 bytes and outputs a TypeError. \$\endgroup\$ – Gábor Fekete Jun 8 '17 at 14:01
  • \$\begingroup\$ print("Goodbye Cruel World!")/0 is shorter for the second one (3 bytes?) \$\endgroup\$ – matsjoyce Jun 8 '17 at 15:39
  • \$\begingroup\$ @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 \$\endgroup\$ – Tezra Jun 8 '17 at 15:48
  • 32
    \$\begingroup\$ 2.585e+22 is a pretty big score... you sure you couldn't golf it down more? \$\endgroup\$ – tuskiomi Jun 8 '17 at 16:51
  • 1
    \$\begingroup\$ @tuskiomi The '!' means that the final score is modified by the bonus challenge. \$\endgroup\$ – Tezra Jun 8 '17 at 16:57
10
\$\begingroup\$

SOGL, 15 25 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.

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ – Kevin Cruijssen Aug 23 '18 at 10:08
  • \$\begingroup\$ @KevinCruijssen oh huh, thanks! \$\endgroup\$ – dzaima Aug 23 '18 at 10:45
9
\$\begingroup\$

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

\$\endgroup\$
6
  • 2
    \$\begingroup\$ it prints out 'Goodbye Cruel World!' and then crashes though which i just thought it would simply have to crash to be accepted. \$\endgroup\$ – eniallator Jun 11 '17 at 17:42
  • \$\begingroup\$ @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. \$\endgroup\$ – Pharap Jun 12 '17 at 0:27
  • \$\begingroup\$ @Pharap Oh, I see. STDERR only matters if you're going for the bonus. Thanks! \$\endgroup\$ – Trebuchette Jun 12 '17 at 6:25
  • \$\begingroup\$ @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. \$\endgroup\$ – Pharap Jun 12 '17 at 6:57
  • 1
    \$\begingroup\$ You can save a byte by doing this instead: a=-print"Goodbye Cruel World!" \$\endgroup\$ – GalladeGuy Aug 21 '18 at 1:47
7
\$\begingroup\$

C Preprocessor, 27 bytes

#error Goodbye Cruel World!

Output:

fatal error C1189: #error:  Goodbye Cruel World!
\$\endgroup\$
3
  • 1
    \$\begingroup\$ You may be able to shorten it further with just #Goodbye Cruel World! \$\endgroup\$ – apricot boy Jun 10 '17 at 23:58
  • \$\begingroup\$ @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) \$\endgroup\$ – Govind Parmar Jun 19 '17 at 16:02
  • 1
    \$\begingroup\$ @Gorvind Parmar ah. Well it definitely does on gcc: i.imgur.com/qmGnoJv.png \$\endgroup\$ – apricot boy Jun 20 '17 at 4:27
6
\$\begingroup\$

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.

\$\endgroup\$
6
\$\begingroup\$

Operation Flashpoint scripting language, 45/2 = 22.5 bytes

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

Call with:

call f;

Output:

\$\endgroup\$
5
\$\begingroup\$

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
    at net.aditsu.cjam.CJam.pop(CJam.java:75)
    at net.aditsu.cjam.Op1.run(Op1.java:10)
    at net.aditsu.cjam.Block.run(Block.java:304)
    at net.aditsu.cjam.CJam.runCode(CJam.java:210)
    at net.aditsu.cjam.CJam.main(CJam.java:240)
\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ @Cyoce Typo. Thanks \$\endgroup\$ – Adám Jun 10 '17 at 22:05
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ int n=0;n/=n; is shorter for your first answer. \$\endgroup\$ – Kevin Cruijssen Jun 9 '17 at 9:44
  • \$\begingroup\$ @KevinCruijssen Nice spot, I was having trouble with getting it to compile without division by constant zero error. \$\endgroup\$ – TheLethalCoder Jun 9 '17 at 9:46
  • \$\begingroup\$ 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. \$\endgroup\$ – Kevin Cruijssen Jun 9 '17 at 10:35
  • \$\begingroup\$ @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. \$\endgroup\$ – TheLethalCoder Jun 9 '17 at 10:37
4
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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). \$\endgroup\$ – Cody Gray Jun 11 '17 at 13:06
4
\$\begingroup\$

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

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ I tried to beat you … and failed with 21! bytes. :) W=\ World\!;echo Hello$W;"Goodbye Cruel$W" \$\endgroup\$ – reitermarkus Jun 10 '17 at 22:10
  • 1
    \$\begingroup\$ You could probably change the second line to Goodbye\ Cruel\ !$, not 100% but pretty sure that !$ is "last word of last command" \$\endgroup\$ – apricot boy Jun 11 '17 at 0:03
  • \$\begingroup\$ But what if an executable named "Goodbye Cruel World!" exists in the PATH? :) \$\endgroup\$ – spuck Aug 19 '19 at 17:50
  • \$\begingroup\$ Verified OK on TIO.run... beats my zsh answer :/ \$\endgroup\$ – roblogic Aug 21 '19 at 3:41
4
\$\begingroup\$

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!
\$\endgroup\$
3
  • \$\begingroup\$ Shouldn't it be $w='World!' (with an !)? \$\endgroup\$ – gmatht Jun 11 '17 at 2:53
  • \$\begingroup\$ "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.. \$\endgroup\$ – TessellatingHeckler Jun 11 '17 at 19:21
  • 1
    \$\begingroup\$ Using the same logic as the 17.5b answer, 'Goodbye Cruel World!';x would save two bytes for 24 \$\endgroup\$ – Veskah Aug 20 '18 at 23:10
4
\$\begingroup\$

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

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

Try it online!

\$\endgroup\$
4
\$\begingroup\$

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!

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

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
\$\endgroup\$
3
\$\begingroup\$

Pyth, 28 24 bytes

"GOODBYE CRUEL WORLD!"hY

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

Try this!

\$\endgroup\$
3
\$\begingroup\$

Japt, 22 bytes

°Oo`!dlžW ¤¨C eybºoG`w
°Oo`!dl&#158;W ¤¨C eybºoG`w
 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

\$\endgroup\$
3
  • \$\begingroup\$ You can compress the string using Oc"<string>" and then replace the current string with the compressed version and surrounded by backticks. \$\endgroup\$ – Luke Jun 8 '17 at 13:39
  • \$\begingroup\$ An explanation would be nice. \$\endgroup\$ – iFreilicht Jun 9 '17 at 8:39
  • 1
    \$\begingroup\$ @iFreilicht explanation added. \$\endgroup\$ – Tom Jun 9 '17 at 9:26
3
\$\begingroup\$

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
\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Cody Gray Jun 11 '17 at 13:02
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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!")
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to the site! :) \$\endgroup\$ – DJMcMayhem Mar 24 '18 at 13:20
3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$ – Herman L Aug 21 '18 at 16:27
  • \$\begingroup\$ 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 :) \$\endgroup\$ – TehPers Aug 3 '20 at 23:45
3
\$\begingroup\$

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
31:       01 c0                   add   %eax,%ecx
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.

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ – qwr Apr 1 '18 at 2:57
  • \$\begingroup\$ 64 bit multiply fills up rdx:rax \$\endgroup\$ – qwr Apr 1 '18 at 3:22

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.