51
\$\begingroup\$

Create a program which prints the amount of characters its source has in English words.

If your program is nine letters long it should print "nine".

Capitalization is ignored: in case you're printing "one" (somehow) you can print "one", "oNe", "ONE" or anything else.

Base ten is required.

Proper spacing is also required.

In the (unlikely but just for specification) case your program reaches one billion characters or more, use the American number scale. A billion here is 10^9 and a million is 10^6.

Do not use "one hundred and one": use "one hundred one".

Do not use the hyphen. Print forty four, not forty-four.

Test cases with a fake program:

10.(96 0s later)..01 prints one HuNdreD ONE -- okay: proper spacing, no "and"
10.(96 0s later)..01 prints one HuNdreDONE -- not okay: wrong spacing
10.(96 0s later)..01 prints one thousand two hundred two -- not okay: base 3 rather than base 10
10...(999999996 0s later) prints nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-six: not okay, wrong number and includes hyphens

Golfy challenge, as always: shortest code wins. You're free to post after the green tick has been given, though. This serves more for completeness for hard to program languages. Malbolge, anyone?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Proper spacing is also required. Does this mean no trailing spaces in the output? \$\endgroup\$ Oct 23, 2019 at 12:14
  • \$\begingroup\$ To solve it in Unary, is there a list of larger units? \$\endgroup\$
    – l4m2
    Jan 21, 2022 at 12:59

128 Answers 128

1
\$\begingroup\$

Pip, 6 bytes

"six";

Try it online!

; is a comment.

\$\endgroup\$
5
  • \$\begingroup\$ Also a polyglot in R, and this exact 'program' was even already submitted in R \$\endgroup\$ Sep 16, 2020 at 6:22
  • \$\begingroup\$ And, as a bonus, the other answer in R is also a polyglot in Pip \$\endgroup\$ Sep 16, 2020 at 6:24
  • \$\begingroup\$ I've been trying to find easy challenges for R, but all of them somehow have an R solution \$\endgroup\$
    – Razetime
    Sep 16, 2020 at 6:53
  • 2
    \$\begingroup\$ I don't think that should stop you from having a go. I wish there were more challenges with more-than-one answer in R (or any other language). It's really fun & instructive to see the different approaches. Obviously, one of them will always be the shortest, but that isn't a problem. I usually try to deliberately avoid looking at any other R answers if there already are any, and post my own answer if it ends-up different from whatever is already there, even if it's longer (and usually one of the other R golfers then makes it shorter for me anyway...). \$\endgroup\$ Sep 16, 2020 at 7:03
  • 1
    \$\begingroup\$ For instance, this recent challenge got 4 independent (and all different) R answers... \$\endgroup\$ Sep 16, 2020 at 7:06
1
\$\begingroup\$

MAWP, 30 bytes

99W3M!;98W!;1M;2A!;2M!;11MM3M;

Try it!

prints in capitals.

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

naz, 30 bytes

9a9m3a1o9s3s1o1a1o9a1o2a1o5a1o

Outputs THIRTY.

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

StupidStackLanguage, 55 30 bytes

avvdqvdmdfwwddfifvvdfiifvfaaaa

Try it online!

I found this by generating a list of numbers 1 - 100 as words, and then mapping said array with my StupidStackLanguage printing algorithm to generate an array of number printing programs. I then padded each program in the array with meaningless a characters until the number of characters it had equalled it's position in the array. Then, I just found the first program which had the same length as the number it printed.

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

Pxem, Filename: 6 bytes + Content: 0 bytes = 6 bytes.

  • Filename: six.px
  • Content is empty.

Sorry for a boring post.

Try it online!

\$\endgroup\$
1
  • 3
    \$\begingroup\$ This challenge states to output the number of characters in your program, not your score (filename+program). So you have to add a byte: zero.px \$\endgroup\$
    – Makonede
    May 18, 2021 at 20:04
1
\$\begingroup\$

BRASCA, 5 bytes

`five

Try it!

Explanation

`five      - Push "five" on the stack, char by char
<implicit> - Print the stack, reversed
\$\endgroup\$
1
\$\begingroup\$

Japt, 4 bytes

Lucked out that the string compression found anything to compress in one of the smaller numbers.

`f r
`    // Decompress compressed string
 f r // Compressed string literal for "four"

Try it here.

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

Duocentehexaquinquagesimal, 39 32 bytes

ÖtΛ‰[WåÙUYr™{—*l”î)‘RçÊí¹©ÓûŽUQ‹

Try it online!

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

Knight, 6 bytes

O"six"

Try it online!

Not much to explain; O is shorthand for OUTPUT.

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

Java 8 (full program), 75 70 bytes

interface M{static void main(String[]a){System.out.print("seventy");}}

-5 bytes thanks to @CommandMaster.

Try it online.

Java 8 (lambda function), 9 bytes

v->"nine"

Try it online.

Java 5/6 (full program), 40 bytes

enum M{A;{System.out.print("forty");}}//

No online compiler, because I don't know any for Java 5 or 6..
The trailing // are no-ops, but outputting forty is shorter.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can't you output seventy in the first solution? \$\endgroup\$ May 24, 2021 at 13:05
  • \$\begingroup\$ @CommandMaster Lol, I indeed can.. :/ Thanks! \$\endgroup\$ May 24, 2021 at 14:39
1
\$\begingroup\$

8086 DOS .COM file, 16 bytes

Hexdump:

0CD5:0100  B4 09 BA 08 01 CD 21 C3-73 69 78 74 65 65 6E 24 ......!.sixteen$

Assembly source:

        // NASM syntax with C comments because no SE highlighting
        [org 0x100]
        section .text
        global start
start:
        // int 21:09: write $-terminated string in ds:dx
        mov     ah, 0x09
        mov     dx, str
        int     0x21
        // exit
        ret
str:
        db      "sixteen$"

8086 DOS .COM file, dirty exit, 10 bytes

This one prints "ten" and then does whatever, likely in the form of a crash.

0CD5:0100  B4 09 BA 07 01 CD 21 74-65 6E                   ......!ten
        // NASM syntax with C comments because no SE highlighting
        [org 0x100]
        section .text
        global start
start:
        // int 21:09: write $-terminated string in ds:dx
        // but it prints even if it isn't $-terminated so why bother?
        // It's real mode, it'll find a $ eventually™
        mov     ah, 0x09
        mov     dx, str
        int     0x21
        // exit
        // jk
str:    // not $ terminated
        db      "ten"

everything is fine

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

Vyxal, 3 bytes

`∧ḭ

Try it Online!

Dictionary compression FTW!!!

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

Barrel, 4 bytes

four

Implicitly prints the unknown instructions "four". However, this could potentially be voided by later modifications, so here's a safe 5-byter that uses a string:

'five
\$\endgroup\$
1
\$\begingroup\$

AWK, 20 bytes

BEGIN{print"twenty"}

Try it online!

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

International Phonetic Esoteric Language, 8 bytes

"eight"o

Pushes and prints the string "eight".

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

Emmental, 30 bytes

#84.#72.#73.#82.#84.#89.######

Try it online!

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

tinylisp, 6 bytes

Very simple solution, (q quotes the name after it to prevent it from being evaluated, the parentheses are implicitly closed at the end of the line, and the result of the top-level statement is implicitly outputted,

(q six

Try it online!

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

EEL - 78 Bytes

=83 !>=69 !>=86 !>=69 !>=78 !>=84 !>=89 !>=32 !>=69 !>=73 !>=71 !>=72 !>=84

Explanation

EEL (Easy Esoteric Lang) is an esoteric programming language created by me, easy to manage, hence the name. Below is a brief description of the language.

.-EEL is based on a vector of bytes initialized to zero, on which basic arithmetic operations can be performed, whose length is equal to 64Kb.

.-EEL allows the reading and writing of one byte at a time in the form of an ASCII character in the standard input and output respectively.

.-EEL has a brief help section which can be viewed from the interpreter.

.-EEL is extremely sensitive, so a wrong input byte can cause a wrong output.

.-EEL does not have an error/exception handling system, so it may crash unexpectedly if a fatal error such as division by zero occurs.

Defined operations:

=000 -> Copy the value of number 000 to the current byte.

+000 -> Add to the current byte, the value of number 000.

-000 -> Subtract to the current byte, the value of number 000.

*000 -> Multiply to the current byte, the value of number 000.

/000 -> Divide to the current byte, the value of number 000 (cannot be zero).

%000 -> Calculate the modulo of the current byte and the value of number 000 (cannot be zero).

> -> Go to the next byte of the vector.

< -> Go to the previous byte of the vector.

? -> Read a ASCII character from STDIN and assign it to current byte.

! -> Write to current byte in STDOUT as an ASCII character.

: -> Open/close the space for comments.

. -> Exit the program.

$ -> Reference to current byte.

NOTES:

The 000 number can be s current byte reference operator ($).

The 000 number (x) must be an integer number, such 0 < x <= 255.

There must be a space character u+0020 after each number 000.

Try the EEL interpreter!

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

Thunno, \$ 5\log_{256}(96)\approx \$ 4.12 bytes

"five

Attempt This Online!

Pretty simple.

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

Z80Golf, 10 bytes

00000000: 3e74 ff3e 65ff 3e6e ff76                 >t.>e.>n.v

Try it online!

  ld a, 't'
  rst 38h
  ld a, 'e'
  rst 38h
  ld a, 'n'
  rst 38h
  halt
\$\endgroup\$
1
\$\begingroup\$

Nim, 10 bytes

echo "ten"

Attempt This Online!

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

Julia 1.0, 15 bytes

print(:fifteen)

Try it online!

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

Aheui (esotope), 52 bytes

발밦밞발밞다받받밞밞따댜먛뻐더희xxxx

Try it online!

Contains 20 chars (16 hangul and 4 unused ascii) and prints TWenty. 19 seems to be out of reach. NINTeen barely fits, but the correct spelling of 19 is "nineteen".

밞바밣밞다밦발바발타밞밞따받탸먛뻐더희

Try it online!


Aheui (esotope), 40 bytes, solves for bytes instead

발박받밞밝발박따땨먛뻐더희

Try it online!

Prints FORTY. The strictly increasing nature of FORTY is useful again.

Each Hangul character costs 3 bytes, so 40 bytes can fit 13 chars and a newline. Luckily FORTY can be printed in exactly 13 chars (4 for charcode differences, 5 for the value 70, 3 for "dup; print; add" loop, and 1 for halt).

발박받밞    Push 5, 2, 3, 9
밝발박따따  Push 70 (7 * 5 * 2)
빠맣다      Loop: dup; print as char; add
            Break when add fails
희          Halt
\$\endgroup\$
2
  • \$\begingroup\$ Because the challenge says "Create a program which prints the amount of characters its source has in English words." and not "bytes", shouldn't this print "fourteen"? \$\endgroup\$
    – The Thonnu
    Mar 28, 2023 at 6:25
  • 1
    \$\begingroup\$ @TheThonnu Good point. Added a solution for characters. \$\endgroup\$
    – Bubbler
    Mar 28, 2023 at 7:52
1
\$\begingroup\$

><>, 9 bytes

"ooooENIN

Try it online!

Prints NINE and halts with error (E is not a valid command).

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

Zalgo, 54 bytes

t̝̐̄̇h̝̐̈̆i̝̐̉̆r̝̐̂̇t̝̐̄̇y̝̐̉̇

Escaped with each cluster per line:

t\u031d\u0310\u0304\u0307
h\u031d\u0310\u0308\u0306
i\u031d\u0310\u0309\u0306
r\u031d\u0310\u0302\u0307
t\u031d\u0310\u0304\u0307
y\u031d\u0310\u0309\u0307

Prints thirty. Pushing a constant and printing takes 4 characters, and the first number whose length in English is strictly smaller than 1/4 of its value is 30. For stylistic reasons, each grapheme cluster in this code prints its root character (e.g. t̝̐̄̇ prints t). Python code used to generate the source.


Zalgo, 25 bytes, 1 grapheme cluster

I̝̝̝̐̏̆̐̎̆̐̅̆

Escaped:

I\u031d\u031d\u031d\u0310\u030f\u0306\u0310\u030e\u0306\u0310\u0305\u0306

Prints one. Validity of this answer depends on the definition of "character" in this challenge. Python code used to generate the source.

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

Stax, 5 bytes

äφ╓Dr

Run and debug it

Just unpacks to "five", which is then implicitly output

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

SWI-Prolog, 15 bytes

write(fifteen).

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Ten: write(ten)? \$\endgroup\$
    – Night2
    Oct 20, 2019 at 9:17
  • 1
    \$\begingroup\$ Apparently that works in the online version :) But in the terminal versions, we have to close it with a dot. \$\endgroup\$
    – anderium
    Oct 20, 2019 at 9:25
  • \$\begingroup\$ You can always limit your answer to a specific version. This is code golf, doesn't matter if the answer is not cross-compatible. \$\endgroup\$
    – Night2
    Oct 20, 2019 at 13:53
0
\$\begingroup\$

Pyth, 5 bytes

"five

Try it online!

I don't think it's possible to get shorter than this. The overhead for compressed strings is 4 bytes already, so it's impossible to also get a 4-byte message in it.

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

MSM, 11 9 6 bytes

xsi/..

The 3 letters are pushed on the stack, / swaps s and i to get the correct (reverse) order and the two 3 dots concatenate them to a single string. There are variants such as '.xis. or ?..xis.

Try it online!

Edit: -3 bytes thanks to @Night2

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

Pepe, 50 bytes

reeEEeeEEereeEEeEeeEreeEEeeEEereeEEEeEeereeEEEEeeE

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.