24
\$\begingroup\$

Your challenge: The code must print "Hello, World!" and nothing else.

Your restrictions: Your program must satisfy these requirements:

  1. The program must be a pangram.

    • It must use every character in printable ASCII, or, if you chose a particularly strange language, characters which are stored as one byte.
    • You are allowed to use other characters.
  2. The program may not have unnecessary characters.

    • No subset of individual characters may be removed from the program while the program still outputs "Hello, World!"
    • For example, if code ABBC outputs Hello, World! then neither codes AC nor BC may output "Hello, World!", although code BA may.
    • This also means you cannot have a statement to print "Hello, World!" per se anywhere in your program, as everything other than that statement could be deleted and the program would do the same thing.
  3. The program must not take input.

  4. Your program does not create any errors.

  5. You must not use any "Hello, World!" builtins.

Your score: Your score is calculated by [length of the program in characters] - [number of different characters]. Lowest score wins. (Tie-breakers are oldest post.)

Nota Bene: the second requirement is almost impossible to verify, so an answer is valid only after a week has passed for anyone who wishes to do so to be able to disprove the validity of your answer.

\$\endgroup\$
15
  • 4
    \$\begingroup\$ Welcome to CGCC! Interesting first challenge. For the ABBC example, would a more comprehensive list of restricted programs be ABB, ABC, BBC, AB, BB, BC, AC, A, B, and C? \$\endgroup\$
    – Jo King
    Commented Feb 25, 2021 at 2:20
  • 8
    \$\begingroup\$ Related: Biggest Irreducible Hello World, which shares the "Hello World!" and irreducible code restriction. \$\endgroup\$
    – Bubbler
    Commented Feb 25, 2021 at 2:22
  • 3
    \$\begingroup\$ Given that this is still fairly new, I’d suggest changing the string to something like Greetings, World! to avoid Hello World builtins \$\endgroup\$ Commented Feb 25, 2021 at 4:15
  • 2
    \$\begingroup\$ Next time, maybe try the Sandbox. \$\endgroup\$
    – emanresu A
    Commented Feb 25, 2021 at 4:21
  • 4
    \$\begingroup\$ @Hyperbole That's an unobservable requirement, I'd recommend against it. \$\endgroup\$
    – rydwolf
    Commented Feb 25, 2021 at 16:52

12 Answers 12

8
\$\begingroup\$

Husk, 256 bytes, 256 characters, score=0

m←`C₁†ȯ→*2c¨abqnpsyhkzjwf
¢"H½↕↑↓↔∟¦¡¿‼…‰‡√≤≥±∂∫∞≈≠≡⌐¬÷×τ►#$%&'()+Φ-./013456789:;<=>?@ABDEFG¤IJKLMNOPQRSTUVṄXYZ[\]^_⁵ı§χituvxg¹{|}~·₀₂₃₄₅₆₇₈₉⌈⌉⌊⌋ΓΔΘΛΞΠΣ€ΨΩαβγδεζηθλμξπρςσ▲φƒψω⁰r²³⁴d⁶⁷⁸⁹£,¥o´ ▼!◄lȦḂĊḊĖḞĠḢİĿṀWȮṖṘṠṪẆẊẎŻȧḃċḋėḟġḣeȷŀṁṅṗṙṡṫẇẋẏżÄËÏÖÜŸØäëïöüÿø◊□¶«»

Try it online!

I think this is irreducible. It certainly took a bit of effort to build, but striving for a score of zero is inviting pretty close scrutiny...

Husk has 256 characters on its codepage, so this pangram needs to use all of them. Aiming for a zero score also means that (a) the 'program' code cannot easily include any of the letters of 'Hello, World!', and (b) we need to find a way to 'recycle' the letters 'l' and 'o', which each occur more-than-once in the output.
Unfortunately, Husk uses '!' as its indexing function, which rules-out the most straightforward approach to extracting elements from a long string, so we need to find a different way to do this.

Here's my approach:

line 2: the encoding string (228 characters, + 2 characters ¢")

¢"H½↕↑↓↔∟¦¡¿ ... öüÿø◊□¶«»      # A 228-character string, repeated forever.  
                                # Since one of the characters is a '\', though,
                                # this is read by Husk as a 227-character array.
                                # The characters of 'Hello, World!' are inserted
                                # at specific positions in the infinite string, 
                                # (so they occur out-of-order in the single copy).

line 1: the indexing program (26 characters)

     †ȯ   c¨abqnpsyhkzjwf       # For all the codepoints of the index string "abqnpsyhkzjwf":
        *2                      # double them
       →                        # and add 1.
  `C₁                           # Now divide the encoding string into substrings with these lengths
m←                              # and get the first letter of each.

The indexing string "abqnpsyhkzjwf" is constructed to 'hit' the letters 'o' and 'l' 2 and 3 times, respectively, by 'wrapping around' in the infinite list, so that those letters only need to occur once in the encoding string. The largest index needs to be the same as the length of the encoding string, in order to 'hit' the same target ('l') twice in a row: this is achieved with 'q' (2x codepoint 113 + 1 = 227).

\$\endgroup\$
2
  • \$\begingroup\$ @Razetime - Yeah, but this isn’t code golf, so I need to use all 256 characters, right...? \$\endgroup\$ Commented Mar 1, 2021 at 6:56
  • \$\begingroup\$ hmm yeah (silly me) \$\endgroup\$
    – Razetime
    Commented Mar 1, 2021 at 7:07
8
\$\begingroup\$

C (gcc), 111 109 bytes, score = 14

main(){printf("H%cllo, Wo\x72ld!",39+sizeof"14568:<=>?@ABCDEFGIJKLMNOPQRSTUVXYZ[]`bghjkquvwy0|~#$&'*-./^_");}

Try it online!

Edit: bugfix thanks to Noodle9

Edit 2: changed order of numbers and operators in the string to fix a problem found by G B, replaced "Hello, World!" with "Hello, Wo\x72ld!"

shorter solution based on Sheik Yerboutis Code (107 bytes, score = 12)

main(){printf("H%cllo, Wo\x72ld!","_:?=<#$&*-+^|./4138596@ABCDEFGIJKLMNOPQRSTUVXYZ`bghjkquvwysz0~e"['>']);}

Try it online!

\$\endgroup\$
10
  • \$\begingroup\$ @Noodle9 thanks, it should be fixed now \$\endgroup\$
    – xibu
    Commented Feb 25, 2021 at 15:41
  • \$\begingroup\$ -5 characters \$\endgroup\$
    – anotherOne
    Commented Feb 25, 2021 at 16:08
  • \$\begingroup\$ @Sheik Yerbouti I dont' think, that that solution is allowed. You can remove letters from the string and numbers from the index at the same time. example \$\endgroup\$
    – xibu
    Commented Feb 25, 2021 at 16:20
  • 2
    \$\begingroup\$ @xibu oh you are right! I fixed it at the cost of one character Try it online! Anyway, your sizeof approach is different enough from this shorter code to be posted alongside with it. \$\endgroup\$
    – anotherOne
    Commented Feb 25, 2021 at 16:29
  • 1
    \$\begingroup\$ Still not ok: main(){printf("H%cllo, World!",79|35);} \$\endgroup\$
    – G B
    Commented Feb 25, 2021 at 21:39
7
\$\begingroup\$

Ruby, 119 112 bytes / score 17

puts ["%x"%(("!\#&+,-01245:;<>?@ABDEFIJKLNOQRUVWXYZ`dflqnry{|}"=~/$/)^"s8j9bePwGp7SgMTCvznH".to_i(36))].pack'h*'

Try it online!

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

Python 3, 101 bytes, 101 - 95 = 6

print('o#$%&*./0W368;<=>? @ABCDEFG,IJKLMNOPoQRSTUVXY\154Z^_`abcflghjkmqsuevwyz{|}~H'[::-9]+"\x72ld!")

Try it online!

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

Backhand, 100 - 95 = 5

M#$%&"()*+H-./0e1234l5678l9:;<o=>?@,ABCD FGIJWKLNOoPQRSrTUVXlYZ[\c^_`b"dfgh]ikmn'pqst!uvwxryz{}a|~jE

Try it online!

Note that the version on TIO is missing a couple of instructions (notably '), so I've copied the interpreter here. This program works because Backhand executes every fifth instruction thanks to the first M (it's actually a little more complex than this), so the actual code is more like:

M    "    H    e    l    l    o    ,         W    o    r    l    c    "    ]    '    !    r    a   j 

However, since you can't remove the spaces inbetween without breaking the flow of the program, you can replace them with whatever you want. The final check is that the j jumps to the 10th character (H) to halt and output,, which is less feasible if you modify the program. It's possible you might be able to form a valid program from this mishmash, but it is unlikely, and I'm sure that there's another permutation that fixes that.

Explanation:

M                      Increase the step count from 3 to 5
 "Hello, Worlc"        Push the string to the stack
               ]       Increment c to d
                '!     Push !
                  r    Reverse the stack
                   aj  Jump back to the 10th character
  H                    Halt and output the stack
\$\endgroup\$
2
  • \$\begingroup\$ you can remove the ~ then it goes 2 back and 1 forth, and return still return to 10th position \$\endgroup\$
    – Alex bries
    Commented Feb 26, 2021 at 15:35
  • \$\begingroup\$ @Alexbries ah right, should have been more careful with placing that }s. Fixed \$\endgroup\$
    – Jo King
    Commented Feb 27, 2021 at 3:18
5
\$\begingroup\$

JavaScript (ES6), score 30 124 - 95 = 29

alert(`Hell`+String.fromCharCode(057^"#$%&*-/1234689:;<=>?@ABDEFGIJKLMNOPQRTUVXYZ][_bcjkpqsuvwxyz{|}~\\".length)+', World!')

The os of fromCharCode cannot be put inside quotes. Its char code is 111, which can't be uses directly as an argument to String.fromCharCode. You can't XOR to get it because you need 64, 86, 104 or 106, which are also impossible, I think.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Aren't there 95 printable ASCIIs? \$\endgroup\$ Commented Feb 25, 2021 at 10:04
  • \$\begingroup\$ @DominicvanEssen Sorry, I have a headache, I just copied some number I saw without thinking too hard about it... \$\endgroup\$
    – Neil
    Commented Feb 25, 2021 at 10:06
  • \$\begingroup\$ @Alexbries Your version still outputs Hello, World! if you remove the leading !. \$\endgroup\$
    – Neil
    Commented Feb 25, 2021 at 11:13
  • \$\begingroup\$ I just noticed that it can be reduced to these 2 variants, but you can fix it by simply moving the 5 before the 1 \$\endgroup\$
    – Alex bries
    Commented Feb 25, 2021 at 20:54
  • \$\begingroup\$ @Alexbries I just managed to golf a byte off using ^, I think it's safe from your variants this time... \$\endgroup\$
    – Neil
    Commented Feb 26, 2021 at 0:56
4
\$\begingroup\$

JavaScript (Node.js), 118 117 116 - 95 = 21

shoutout to tsh for spotting 2 issues

alert(`Hello, Wo${('\71'+";#%&*/8025:<=>[]?@ABCDEFGIJKLMNOPQRTUVXYZ|_bcfjkpmqsuvwxyz".length^-~94).toString(36)}d!`)

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ Maybe remove the `\` \$\endgroup\$
    – tsh
    Commented Feb 26, 2021 at 3:25
  • \$\begingroup\$ @tsh but then i don't have all the ascii pritable characters \$\endgroup\$
    – Alex bries
    Commented Feb 26, 2021 at 8:17
  • 2
    \$\begingroup\$ I mean this program may still print "Hello, World!" without the `\` in it. So it does not follow the rule of "may not have unnecessary characters" \$\endgroup\$
    – tsh
    Commented Feb 26, 2021 at 9:04
  • 1
    \$\begingroup\$ ${...length...} -> l \$\endgroup\$
    – tsh
    Commented Feb 26, 2021 at 12:28
4
\$\begingroup\$

BASIC, 129 bytes

FOR i=8-2 TO 79 STEP 3+3:PRINT MID$("9*./!H065<>e?@ABClGJKLQlUVYZ[o\]^_`,abcf  ghjksWmnpqxotuvwyrz4{|}l~#%&'d",MOD(i,73),1);:NEXT

Try it online!

Updated to a valid version thanks to Dominic van Essen.

\$\endgroup\$
7
  • \$\begingroup\$ Welcome to Code Golf! Nice first answer. \$\endgroup\$
    – rydwolf
    Commented Feb 27, 2021 at 18:45
  • \$\begingroup\$ I'm afraid I've deleted 5 characters (+3#%&) and it still works... try it... \$\endgroup\$ Commented Feb 27, 2021 at 23:46
  • 1
    \$\begingroup\$ Something like this might be golfable, though...? \$\endgroup\$ Commented Feb 28, 2021 at 0:24
  • 1
    \$\begingroup\$ @Dominic van Essen - Ahhhhh.... guess I'm not as smart as I thought I was. Haha delete one character it stops working, delete almost the whole thing and it works fine. Hmmm. I'll look at your example. \$\endgroup\$ Commented Feb 28, 2021 at 2:52
  • 1
    \$\begingroup\$ Unfortunately ,don't worry we got face slaped like this too \$\endgroup\$
    – Alex bries
    Commented Mar 3, 2021 at 11:01
3
\$\begingroup\$

R, 119 117 bytes, score=24 22

Thanks to Dominic van Essen for spotting a bug.

cat('Hello, Wo',intToUtf8(nchar("#$%&*-./012479:;<>?@ABDEFGIJKLMNOPQRSVXYZ[]^_`bgjkmquvwyz{|}~")+53),"\x6Cd!",sep="")

Try it online!

Uses the hex code trick to encode the last l as \x6C. This saves 2 bytes: 1 by avoiding the reuse of the l (none of the other characters are used anywhere else), and 1 by avoiding having to escape the \ (as \\) in the string.

The long string in the middle is 61 characters long. They are all necessary to get the character r (ASCII code 114), which is produced by the intToUtf8(nchar("...")+53) part.

\$\endgroup\$
2
  • \$\begingroup\$ I deleted some characters: try it... \$\endgroup\$ Commented Feb 25, 2021 at 10:29
  • \$\begingroup\$ @DominicvanEssen argh, how did I miss that? Fixed now (I hope). \$\endgroup\$ Commented Feb 25, 2021 at 10:30
3
\$\begingroup\$

C (gcc), score 114 - 95 = 19

Saved 2 bytes and removed 3 points thanks to Sheik Yerbouti!!!

j;main(){for(;j<74;j+=6)putchar("H#$%&'e*-./0l12358l9:>?@oABCDE,FGIJK LMNOPWQRSTUoVXYZ\\r^_`bglkqsvwdxyz|~!"[j]);}

Try it online!

All characters outside of the double-quotes are needed in order for the program to compile and run properly. Taking any of the characters out from the double-quoted string will mess-up Hello, World! from being printed properly. That string is exactly Hello, World! with 5 characters in between each character.

\$\endgroup\$
2
  • \$\begingroup\$ -3 bytes \$\endgroup\$
    – anotherOne
    Commented Feb 25, 2021 at 15:48
  • 1
    \$\begingroup\$ @SheikYerbouti Nice one - thanks! :D \$\endgroup\$
    – Noodle9
    Commented Feb 25, 2021 at 15:56
0
\$\begingroup\$

Zsh, score \$ 116 - 108 = 8 \$

1=`wc -m<<<'␀␁␂␃␄␅␆␇␈␎␏ABCDEFGIJKMNOPQRSTUVXYZabfghjkqsuvxyz234567890_+[];:~./>?\|"%^&*'`
print   He${(L#)@}lo, World!

Attempt This Online!

␀␁␂␃␄␅␆␇␈␎␏ should be the unprintable characters 0x00 to 0x08 and 0x0E to 0x0F, but these don't render in SE markdown.

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

JavaScript (Node.js), score: 124 - 95 = 29

console['l\157g'](`Hello, Wo${"#%&'*+-/0124789:;<=>?@ABCDEFGIJKLMNOPQRTUVXYZ^_abfjkmpquvwxyz|~".length.toString(36)[1]}ld!`)

Try it online!

\$\endgroup\$

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.