47
\$\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 at 12:59

110 Answers 110

1 2 3
4
1
\$\begingroup\$

Knight, 6 bytes

O"six"

Try it online!

Not much to explain; O is shorthand for OUTPUT.

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

Zsh, 6 bytes

<<<six

Try it online!

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

C (gcc), 29 bytes

main(){puts("twenty nine");;}

It's an actual program...

Try it online!

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

C# (Visual C# Interactive Compiler), 18 bytes

Write("eighteen ")

Try it online!

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

Wolfram Language/Mathematica, Multiple Solutions, Bytes vary

four

"seven"

Print@"fifteen"

Echo@"fifteen";

Text[+"sixteen"]

FromCharacterCode@{70,105,102,116,121,32,70,73,118,101}

All of these work and are quite trivial, except for the last one, which actually took a bit of thought.

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

rusty_deque, 12 bytes

"twelve"~ol~
\$\endgroup\$
0
\$\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\$
0
\$\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\$
0
\$\begingroup\$

Minecraft Command Blocks, 11 bytes

w @a eleven

Whispers eleven to every player

@ whispers to you: eleven

If @ whispers to you: is not allowed

tellraw @a "twenty four"

outputs just twenty four and is 24 bytes.

twenty four

\$\endgroup\$
1 2 3
4

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.