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\$ Commented Oct 23, 2019 at 12:14
  • \$\begingroup\$ To solve it in Unary, is there a list of larger units? \$\endgroup\$
    – l4m2
    Commented Jan 21, 2022 at 12:59

128 Answers 128

4
\$\begingroup\$

Hexagony, 9 bytes

n;i;@;e\\

Try it online!

I'm slightly disappointed that I couldn't get six to work (that would be pushing it with three characters, one output, one redirection and one termination).

Not How it works

This Hexagony program looks almost like normal code!

n;i;@;e\\
n;i;       Pushes n and prints it, then pushes i and prints it
    @;     Retrieves the bottom of the stack (n) and prints it
      e\\  Pushes e and terminates the program, printing implicitly

How it works

nine.png

Input starts on the blue path, storing the value n then printing it with ;. It picks up the value i, then jumps to the third line where it hits a mirror. This takes it to the diagonal path, reentering the value i then printing it with ;.

From the bottom left corner, since the current value of i is truthy, it jumps to the red stream starting in the top-left corner, taking n then printing it with ;. The two mirrors redirect it and then it jumps to the e. Finally, it jumps from the middle of the bottom edge to the middle of the top edge, printing the e with ; and terminating with @.


Thanks to Timwi for their HexagonyColorer.

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

Turing Machine Code, 60 50 bytes

0 _ f r 1
1 _ i r 2
2 _ f r 3
3 _ t r 4
4 _ y r 50

Try it online!

As an added bonus, if that counts for anything, it has the number in the code as well.

Edit: Found a shorter solution which still contains the number of bytes in the code.

\$\endgroup\$
1
  • \$\begingroup\$ It doesn't count but nice stuff. \$\endgroup\$ Commented Oct 19, 2019 at 17:29
4
\$\begingroup\$

TI-Basic, 5 bytes

"FIVE

Also works with "SEVEN".

\$\endgroup\$
1
  • \$\begingroup\$ One that's shorter (but not really) "Six \$\endgroup\$
    – kamoroso94
    Commented Jan 16, 2023 at 7:03
3
\$\begingroup\$

Lua, 10 bytes

print"ten"

Also works in many BASIC dialects that don't have a ? shortcut for PRINT

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

Japt, 4 bytes

`fr

Test it here

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

Backhand, 6 bytes

"s"xiH

Try it online!

Outputs "six".

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

GolfScript, 6 bytes

Push six. Implicit print.

 'six'

Try it online!

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

R, 7 6 bytes

 "six" #space before the text

Previously:

"seven"
\$\endgroup\$
1
  • \$\begingroup\$ Also works in PHP without the opening PHP tag. In fact, with PHP you could have simply four \$\endgroup\$ Commented Oct 21, 2019 at 13:53
3
\$\begingroup\$

Whitespace, 151 60 bytes

[S S S T    T   S N
_Push_6_Y][S S S T  N
_Push_1_T][S S S T  S T N
_Push_5_X][S S T    T   S T S N
_Push_-10_I][S S S S S N
_Push_0_S_(with_two_additional_no-op_spaces)[N
S S N
_Create_Label_LOOP][S S S T S T S S T   T   N
_Push_constant_83][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).

Whopping -91 bytes thanks to @JoKing by using an < instead of == check in my Java program below and adding no-ops.

Shortest program generated with this Java program, which uses the printing approach of this Whitespace tip to output in full uppercase.

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

Ruby, 6 bytes

Ruby has an extremely convenient builtin p that prints the string.

p'six'

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Are the quotes allowed? \$\endgroup\$ Commented Oct 20, 2019 at 7:00
2
\$\begingroup\$

Red, 10 bytes

print 'ten

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Japt, 5 bytes

"five

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Japt :) I'll be reopening my bounty (with slightly lower rep) for new users on Monday or Tuesday if you'd like to try for it. I'll count any solutions you post between now and then towards it, including this one. You're welcome to my solution, if you'd like; didn't see yours before posting. \$\endgroup\$
    – Shaggy
    Commented Oct 19, 2019 at 22:01
  • \$\begingroup\$ Thank you @Shaggy ! I'll try it for sure even if I'm scared by the characters used since I do everything from a phone.. Btw I was sure there was some compression available in Japt, my bad I didn't checked. \$\endgroup\$
    – AZTECCO
    Commented Oct 20, 2019 at 8:22
  • 1
    \$\begingroup\$ This also works in TI-Basic (with all caps) "FIVE \$\endgroup\$ Commented Oct 20, 2019 at 21:31
2
\$\begingroup\$

Zsh, 6 bytes

<<<six

Try it online!

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 25 20 bytes

f(){puts("twenty");}

Try it online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ "twenty" works \$\endgroup\$
    – 12Me21
    Commented Oct 19, 2019 at 21:19
  • \$\begingroup\$ @12Me21 I am a fool. \$\endgroup\$ Commented Oct 19, 2019 at 22:08
2
\$\begingroup\$

R, 10 bytes

cat("ten")

Try it online!

Prints ten. This simple answer is much shorter than all the other options I could think of.

If a bit of fluff around the answer is allowed, we can go with

R, 6 bytes

"six";

Try it online!

which prints [1] "six".

If a lot of fluff is allowed, we could even go with

R, 4 bytes

four

Try it online!

which prints to STDERR Error: object 'four' not found.

\$\endgroup\$
2
\$\begingroup\$

Brain-Flak, 80 bytes

((((((((()()()())))((({({}){}}()){}){}()))[[]])())[][][])[]){({}<>)<>}<>........

Try it online!

The code to push eighty is 72 bytes and we add an extra 8 bytes to bring it to the correct amount.

Brain-Flak, 80 bytes

(((())()()()())((([]())())[][][])){({}(([]([]<>[])[]{}()){}){})<>}<>............

Try it online!

This version pushes EIGHTY and requires 12 bytes of padding.

\$\endgroup\$
2
\$\begingroup\$

Commodore BASIC (TheC64/Mini, C64/128, VIC-20, PET, C16/+4) 25 tokenised and BASIC bytes

 0 print"seventeen

I could use the abbreviated ? but when listed the program will show the full print keyword. In any case it would make no difference to the byte count as ? and print use the same number of BASIC tokens.

\$\endgroup\$
2
\$\begingroup\$

Perl 5, 9 bytes

say"nine"

Try it online!

\$\endgroup\$
2
\$\begingroup\$

cat, 4 bytes

four

There are plenty of literal "four" answers already, but not one written in cat yet.

\$\endgroup\$
1
  • \$\begingroup\$ Also works in Text \$\endgroup\$ Commented Nov 18, 2019 at 14:54
2
\$\begingroup\$

APL (Dyalog Unicode), 12 9 6 bytes

Took me a little searching and I don't like requiring the extra spaces, but such are the vagaries of English numbers.

Edit: -3 bytes thanks to Night2. -3 bytes thanks to ngn.

⊢'six'

Try it online! And a slightly different version to get it to work on Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ is ⎕← required? dyalog prints results by default. if not: ⊢'six' \$\endgroup\$
    – ngn
    Commented Nov 18, 2019 at 0:35
  • \$\begingroup\$ @ngn Not in TIO tio.run/##SyzI0U2pTMzJT////1HXIvXizAr1//8B \$\endgroup\$
    – Sherlock9
    Commented Nov 18, 2019 at 5:50
  • \$\begingroup\$ but. or. generally, in kolmogorov complexity challenges we don't add ⎕←. \$\endgroup\$
    – ngn
    Commented Nov 18, 2019 at 11:25
  • \$\begingroup\$ @ngn In that case, I've added both. \$\endgroup\$
    – Sherlock9
    Commented Nov 18, 2019 at 13:08
2
\$\begingroup\$

VTFF, 1524 600 bytes

-924 bytes thanks to Jo King

New answer:


Readable version:

VVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVFVFVFVVVVVVVVVVVVFVFVFVVVFVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVV

For info on how the lang works, I can't be bothered to rewrite it all, so see the old answer:


Those bytes can be seen in the source code of this answer. They could be earlier, but they're apparently gone now. Alternatively, here it is with Vertical Tab characters replaced with Vs and Form Feeds replaced with Fs:

VVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV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VVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVV

Try it out here by putting the string "ONE THOUSAND FIVE HUNDRED TWENTY FOUR" in "Generate", then copying the output of that into "Interpret".

Explanation: VTFF is a language I found by hitting Random page on the Esolangs wiki a lot. The only characters are the vertical tab (0x0b) and form feed (0x0c), hereafter referred to as just V and F. Each block of V characters separated by F characters represents a number in unary. 32 is then added to that number and it is then converted into a character. This repeats until a string is built. That string is then sent to a JS eval statement, the output of which is the output of the program. Because the positions of out characters on the Unicode code table matter, capital letters are preferable to lowercase ones, because their unary representations are 32 bytes shorter. That said, if it ended up being 32 or 64 low I was happy to sprinkle in some lowercases if need be, but thankfully that didn't turn out to be the case. I obtained this with 15 minutes or so of manual brute forcing, where it quickly became clear that the 1500s would be easiest. If you automated the process, I imagine you could dip into the 1400s. Maybe there's even a really lucky one where you don't need all four digits. "FIVE HUNDRED" comes out at a frustrating 499 characters, for example.

Bonus fact: if you did this in binary VTFF (an imaginary language I just made up where it's just VTFF encoded in binary), you could get this down to just "FOURTY" bytes.

\$\endgroup\$
3
  • \$\begingroup\$ Would binary work for "FORTY" as well? :P \$\endgroup\$
    – Jo King
    Commented Sep 22, 2020 at 22:00
  • 1
    \$\begingroup\$ By adding some excess code, you can get this to "six" + " HUNDRED" \$\endgroup\$
    – Jo King
    Commented Sep 22, 2020 at 22:19
  • \$\begingroup\$ @JoKing Awesome, I changed it. I might give this another shot later today to see if there's something yet more clever to be done. Five hundred feels so close! \$\endgroup\$ Commented Sep 22, 2020 at 22:31
2
\$\begingroup\$

Zsh, 6 bytes

<<<six

Try it online!

\$\endgroup\$
2
2
\$\begingroup\$

Vyxal, 3 bytes

`∧ḭ

Try it Online!

Pushes "three" as a dictionary-compressed string and implicitly outputs.

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 5 bytes

"five

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf! Nice first answer. \$\endgroup\$
    – rydwolf
    Commented May 24, 2021 at 23:18
2
\$\begingroup\$

Red, 10 bytes

prin "ten"

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Factor, 9 bytes

[I nineI]

Attempt This Online!

\$\endgroup\$
2
\$\begingroup\$

Cascade, 9 bytes

"
n
i
n
e

Try it online!

Don't know why I didn't think of this earlier.

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

Rattle, 5 bytes

five|

Try it Online!

This is pretty simple - it takes "five" as a variable then outputs it implicitly

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