27
\$\begingroup\$

Write a program that outputs Hell0 W0rld!. It must match this output exactly, including capitalization, zeroes instead of o's, exactly one space, etc. Trailing new lines are allowed.

Lowest score wins. Scoring is based on the sum of the values of each character in the language's code page - otherwise Unicode values should be used. New lines are treated as spaces.

Here are a few example scores:

abc //Score: 294

print(Hell0 W0rld!) //Score: 1597

//Score: 1454
multi
line
code

You can check your ASCII score by inputting your code here. You can view individual ASCII values here.

\$\endgroup\$
3
  • \$\begingroup\$ Tabs are lower than spaces, but I seem to be getting a higher score using tabs. Are whitespace characters taken into account? That would shave a nice chunk off my score(s). \$\endgroup\$
    – ouflak
    Commented Nov 12, 2019 at 11:26
  • \$\begingroup\$ @ouflak Whitespace counts. Only change is that new lines count as spaces. So yes, tabs are cheaper than spaces. \$\endgroup\$
    – Evorlor
    Commented Nov 12, 2019 at 11:43
  • \$\begingroup\$ @Evordor, got it. Thanks. \$\endgroup\$
    – ouflak
    Commented Nov 12, 2019 at 12:05

52 Answers 52

1
2
1
\$\begingroup\$

Scratch 3, score: 2908 2012

In ScratchBlocks Syntax.

define
say[Hell0 W0rld!

Defines an anonymous function. When called, it returns Hell0 W0rld!.

http://scratchblocks.github.io/#?style=scratch3&script=define%0Asay%5BHell0%20W0rld!%5D

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

ink, Score: 959

Hell0 W0rld!

Try it online!

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

str, Score: 1081

`(ELL7RLD`32+o;

There are a lot of unprintable characters that don't show up above, see the TIO link for the full code.

Adds 32 to each character to get a lower score (the naive solution has a score of 1321)

Try it online!

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

Runic Enchantments, Score: 1091

"Hell0 W0rld!"@

Try it online!

I honestly can't find a way to do this cheaper. The costs of string manipulation are just not worth the savings that can be gained. Eg. subtrating 30 from each character the output string saves 360 but costs 289 to undo plus another 165 in control logic (454 total). Encoding the operational part of the program inside the string saves 32 (one fewer ") but costs 187.

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

Jelly, Score 998

“¡¡¡...(22405534226214299955809248283 more ¡'s)...¡¡¡‘Lb⁹Ọ

\$254 + 0 + 0 + \cdots + 0 +252 + 76 + 98 + 137 + 181 = 998\$

Proof of concept A
\$35 \times 256 + 33=8993\$ ¡'s prints #!

Proof of concept B
\$22405534226214299955809248289\$ ¡'s would print Hell0 W0rld!
(just a few too many characters for TIO)

How?

“¡¡¡...¡¡¡‘Lb⁹Ọ - Main Link: no arguments
“¡¡¡...¡¡¡‘     - list of code-page indices = [0,0,0,...,0,0,0]
           L    - length = 22405534226214299955809248289
             ⁹  - literal 256
            b   - to base = [72,101,108,108,48,32,87,48,114,108,100,33]
              Ọ - to characters = "Hell0 W0rld!"

Base decompression using Jelly's code-page as digits would also score 998:

“¡¡¡...(22716232902740826769901577500 more ¡'s)...¡¡¡‘LṃØJ

\$254+0+0+⋯+0+252+76+219+18+179=998\$

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

Assembly (nasm, x64, Linux), score: 9942 (114 bytes)

extern puts
global main
section .data
a: db "Hell0 W0rld!",0
section .text
main:
mov rdi,a
call puts wrt ..plt
ret

Try it online!

Simple assembler code which does the job (taken from original NASM's 64-bit hello-world, with unnecessary things being cut and some labels renamed to minimise the score). Probably can be golfed further.

\$\endgroup\$
3
  • \$\begingroup\$ Normally I'd golf in machine code, not asm source. But sure, it's just as valid as other languages. Yes as you suspected you're missing some optimizations. If you link into a non-PIE executable, you don't need wrt ..plt. And you can tailcall puts with jmp puts instead of call/ret. You also don't need to put the string in a separate section from main. (And if you did, the default section is .text so you could have just put the data after). You do need extern puts and global main, though, for NASM. With GAS syntax you wouldn't need extern. \$\endgroup\$ Commented Oct 22, 2019 at 3:50
  • \$\begingroup\$ 68 bytes: tio.run/… I'll leave it to you to calc the score. Note the removal of the space after a:, and the newline after main:. Also the space after db. And using backticks instead of double quotes around the string for \0. I tried omitting the \0 to depend on whatever's after it in the .text section, but I didn't get lucky with zero padding. Anyway, it links fine with nasm -felf64 hell0.asm && gcc -no-pie hell0.o \$\endgroup\$ Commented Oct 22, 2019 at 3:59
  • \$\begingroup\$ Hmm, I forgot about the scoring system for a minute. Note that uppercase letters have lower codepoints, so MOV EDI,A / JMP puts. And EXTERN puts / GLOBAL main. And A:DB"Hell0 W0rld!",0. Also use tabs instead of spaces, and tab instead of : on labels. But double-quotes with ,0 is better than backticks with \0. IDK what I was thinking there, it's not even a saving in bytes. tio.run/… \$\endgroup\$ Commented Oct 22, 2019 at 4:16
1
\$\begingroup\$

///, Score 959

Hell0 W0rld!

Try it online!

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

R, Score: 1420

Boring answer coming through. One thing to note, using " instead of ' saved 10 score points.

cat("Hell0 W0rld!")

Try it online!

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

Ruby, Score:1245

$><<"Hell0 W0rld!"

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ I think the quotes means it doesn't match the output exactly and is thus invalid. You probably have to go with the score 1245 solution $><<"Hell0 W0rld!" instead... \$\endgroup\$
    – Value Ink
    Commented Oct 21, 2019 at 22:58
1
\$\begingroup\$

Whitespace, score: 2438 (118 bytes)

[S S T  T   S S S T S S N
_Push_-68_!][S S T  T   N
_Push_-1_d][S S S T T   T   N
_Push_7_l][S S S T  T   S T N
_Push_13_r][S S T   T   T   S T S T N
_Push_-53_0][S S T  T   T   T   S N
_Push_-14_W][S S T  T   S S S T S T N
_Push_-69_space][S T    S S T   S N
_Copy_0-based_2nd_-53_0][S S S S T  T   T   N
_Push_7_l][S N
S _Duplicate_top_7_l][S S S N
_Push_0_e][S S T    T   T   T   S T N
_Push_-29_H][N
S S N
_Create_Label_LOOP][S S S T T   S S T   S T N
_Push_constant_101][T   S S S _Add_top_two][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Uses this Whitespace tip of mine to print the output. The optimal constant is generated by this Java program. In addition, I use one duplicate for the ll and one copy for the 0 to save bytes/score.

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

JavaScript, Score: 1644

alert("Hell0 W0rld!")

You can't really do much with JavaScript.

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

Rust, score: 2788

fn    main(){print!("Hell0 W0rld!")}

I was able to save some score by using a tab, but it's hard to make a short answer in Rust.

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

International Phonetic Esoteric Language, Score: 1192 (WIP language) (OLD)

<Hell0 W0rld!>o

No TIO interpreter yet, but is runnable by cloning the repository above, and calling python3 main.py "code here".

<Hell0 W0rld!>o

<Hell0 W0rld!>  ;push string "Hell0 W0rld!"
              o ;pop, print
\$\endgroup\$
1
\$\begingroup\$

x86 machine code - 72 bytes, score : 9253

I'm using write() syscall for printing a string.

     1                                  global _start
     2                                  section .data
     3 00000000 48656C6C                msg db  "Hell"
     4                                  
     5                                  section .text
     6                                  _start:
     7                                  
     8 00000000 8D0D[00000000]              lea ecx, [rel msg]
     9 00000006 43                          inc ebx
    10 00000007 80C204                      add dl, 4
    11 0000000A B004                        mov al, 4
    12 0000000C CD80                        int 0x80
    13 0000000E 80EA03                      sub dl, 3
    14 00000011 C60100                      mov byte [ecx + 0 - 0], 0
    15 00000014 800130                      add byte [ecx + 0 - 0], "0"
    16 00000017 B004                        mov al, 4
    17 00000019 CD80                        int 0x80
    18 0000001B C60120                      mov byte [ecx + 0 - 0], 0x20  
    19 0000001E B004                        mov al, 4
    20 00000020 CD80                        int 0x80
    21 00000022 42                          inc edx
    22 00000023 66C7015730                  mov word [ecx+ 1 - 1], "W0"
    23 00000028 B004                        mov al, 4
    24 0000002A CD80                        int 0x80
    25 0000002C 80C203                      add dl, 3
    26 0000002F C701726C6421                mov dword [ecx + 3 - 3], "rld!"
    27 00000035 B004                        mov al, 4
    28 00000037 CD80                        int 0x80
    29 00000039 99                          cdq
    30 0000003A 42                          inc edx
    31 0000003B C6010A                      mov byte [ecx + 0 - 0], 0x0a
    32 0000003E B004                        mov al, 4
    33 00000040 CD80                        int 0x80
    34                                      
    35 00000042 31DB                        xor ebx, ebx
    36 00000044 B001                        mov al, 1
    37 00000046 CD80                        int 0x80
    38                                  
    39                                  
    40 00000048 48                      .size: db $ - _start

Output : Hell0 W0rld!

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

80186, score 1727

A:  org  $0100
    mov  sp, $0200
    popa
    int  $21
    ret

    db $200-$ dup 0
    dw $0000  ; DI
    dw $0000  ; SI
    dw $0000  ; BP
    dw $0000  ; Ignored
    dw $0000  ; BX
    dw $0300  ; DX
    dw $0000  ; CX
    dw $0900  ; AX
    dw $0000  ; IP for RET

    db $300-$ dup 0
    db "Hell0 W0rld!$"
B:

Try it online!

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

PowerShell, 13 bytes, 1027 score

"Hell0 W0rld"

Try it online!

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

Pascal, 884 ≥ 3387 (ASCII) ≥ 6645 (EBCDIC)

The programming language Pascal is independent from any “code page”. The Pascal ISO standards call this circumstance “implementation-defined”. The theoretical minimum score should be about 900. If you tailored your source code to ASCII, you’ll capitalize keywords and identifiers and use tabs as token separators (the blanks outside the string are meant to be tabs):

PROGRAM A(OUTPUT);BEGIN WRITE('Hell0 W0rld!')END.

If you tailored your source code to EBCDIC, you’ll keep keywords and identifiers lower-case and also use tabs:

program a(output);begin write('Hell0 W0rld!')end.

In yet another character encoding other letters may be particularly “expensive” and you might trade longer code for “cheaper” letters.

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

Io, score: 1584

Thanks to its lightweight syntax, we can get rid of the parentheses.

"Hell0 W0rld!"print

Try it online!

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

VBScript, 1523 score

MSGBOX "Hell0 W0rld!"
\$\endgroup\$
0
\$\begingroup\$

Windows Batch, 1278 score

ECHO Hell0 W0rld
\$\endgroup\$
0
\$\begingroup\$

Noether, Score: 1107

"Hell0 W0rld!"P

Try it online!

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

Bits, score: 3973

1001000000101001100001100111110000001111110101111111100000010010001100000100011101

If you're interested, this is 82 bits = 10.25 bytes.

Explanation

1001000    // H
000101     // e
001100     // l
001100     // l
1111100000 // 0
011111     //  
1010111    // W
1111100000 // 0
010010     // r
001100     // l
000100     // d
011101     // !
           // [Implicit join and output]
\$\endgroup\$
1
2

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.