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

2
\$\begingroup\$

Go, 45 40 bytes, to STDERR

package main
func main(){print("forty")}

Attempt This Online!

  • -5 bytes for using forty, by @The Thonnu

Go, 59 bytes, to STDOUT

package main
import."fmt"
func main(){
Print("fifty nine")}

Attempt This Online!

An extra character is needed here (in this case a newline on line 3) because if it is not, then the byte count cycles between fifty eight (59 bytes) and fifty nine (58 bytes).

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

Befunge-98 (PyFunge), 9 bytes

"NINE,,@#

Try it online!

Explanation

"            Start stringmode
 NINE,,@#    Push "NINE,,@#", wrap to left
"            End stringmode
 N           Reflect (no fingerprint loaded)
"            Start stringmode, wrap to right
 NINE,,@#    Push "#@,,ENIN"
"            End stringmode, wrap to right
       @#    Jump over halt
     ,,      Print "NI"
    E        Reflect
     ,,      Print "NE"
       @     Halt

Slightly different (maybe nicer) solution

"Nine@,k3

Instead of bouncing back and forth over ,,, this just iterates it with 3k,. Also allows the subjectively nicer "Nine" instead of "NINE".

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

Forth (gforth), 16 bytes

S" sixteen" TELL

Try it online!

I tried doing ." <number>" but that didn't line up with anything under 20. I guess I could have padded with whitespace or a 0 DROP or something but that feels like cheating. Also this should work with any sane forth, not just gforth.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ "any sane forth" Are there insane forths? \$\endgroup\$
    – merrybot
    Apr 2, 2023 at 22:20
1
\$\begingroup\$

Python 2, 10 bytes

print'ten'

Try it online!

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

Lua, 16 bytes

print('sixteen')

Try it online!

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

Retina 0.8.2, 5 bytes


five

Try it online! Simply substitutes the empty input with the word five, which is the first word to have one fewer letter than its value.

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

BASIC, 6 bytes

?"SIX"

(Specifically tested in SmileBASIC: should work in most dialects, though ? is often expanded to PRINT, I think it's usually still stored as one byte)

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

Cascade, 9 bytes

"
n
i
n
e

Try it online!

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

Scheme, 5 bytes

This works in any Scheme implementation, but Chicken Scheme is what I used.

'five

EDIT: Alternative 4-byte solution

four outputs this:

Error: unbound variable: four

I think this counts, but if you don't like errors, the above solution is for you.

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

bit**, 30 bytes

#116/#104/#105/#114/#116/#121/

Try it online!

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

Husk, 3 bytes

¨◊ė

Try it online!

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

PowerShell, 6 bytes

Note the space before the first quotation mark.

 "six"

Try it online!

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

Ruby, 9 bytes

puts:nine

Try it online!

Longer than the other answer, but does not output extra characters

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

Ceylon (Web IDE), 18 bytes

The Ceylon Web IDE allows to omit all the boilerplate which makes up a normal program, so we can use just the actual print statement:

print("eighteen");

Try it online!

Ceylon (with run function), 30 bytes

void run() { print("thirty");}

Try it online!

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

Cubix, 20 bytes

/o;."uytnewT.p^@!<..

Try it online!

This wraps onto the cube as follows

    / o
    ; .
" u y t n e w T
. p ^ @ ! < . .
    . .
    . .

Watch it run

  • "uytnewT open string and start pushing uytnewT onto the stack
  • "u close the string and u-turn onto the lower line
  • p bring the bottom of the stack to the top
  • <! beginning of the print loop and test for 0
    • @ halt if tested 0
    • ^y;/oe redirect up, no-op, pop TOS, reflect right, output character, no-op and then onto the beginning of the print loop
\$\endgroup\$
1
\$\begingroup\$

Erlang, 5 bytes

five.

Enter this code at interpreter prompt.

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

dc, 6 bytes

[six]P

prints:

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

Hexadecimal Stacking Pseudo-Assembly Language, 80 bytes

200079400000200074400000200068400000
200067400000200069400000200045400000
140000

Try it online!

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

T-SQL, 10 bytes

print'ten'

I guess is correct, right? :)

\$\endgroup\$
4
  • \$\begingroup\$ What kind of SQL is this? I'm not aware of such a command/query, but I know you can do SELECT'fifteen'. \$\endgroup\$
    – Night2
    Oct 21, 2019 at 17:45
  • 1
    \$\begingroup\$ @Night2 It's Microsoft SQL Server. And yes, but that's 5 bytes more :P \$\endgroup\$
    – JuanCa
    Oct 21, 2019 at 18:01
  • \$\begingroup\$ you should probably make this T-SQL as the language \$\endgroup\$
    – MickyT
    Oct 21, 2019 at 20:53
  • \$\begingroup\$ @MickyT Thank you! \$\endgroup\$
    – JuanCa
    Oct 22, 2019 at 16:01
1
\$\begingroup\$

Inform 7, 21 bytes

To q:say 21 in words.

This creates a function which takes no arguments and returns nothing, which prints the word "twenty-one".

Some boilerplate showing how to call the function:

X is a room.
When play begins: q.

Unfortunately, hardcoding the string tends to put me at a number of characters that's harder to print.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Does this output a hyphen? If so, that's against spec unfortunately. \$\endgroup\$
    – boboquack
    Oct 24, 2019 at 7:12
1
\$\begingroup\$

C (gcc), 29 bytes

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

It's an actual program...

Try it online!

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

Python, 20 bytes

print("twenty")#lol.

hey! that's python code length is actually 20 characters. I know, It's cheating but the comment is still a text.

print("twenty") 

prints the number. (15 chars)

#lol.

a useless comment. (5 chars)

so 5+15=20 and 20 is twenty, right?

\$\endgroup\$
3
  • 4
    \$\begingroup\$ Please include the byte count in your submission. There's no reason to think that comments are cheating. As a hint, can you think of a smaller number that has a longer word, but fits without the comments? \$\endgroup\$
    – Jo King
    Oct 23, 2019 at 6:25
  • \$\begingroup\$ Welcome to CGCC, I have updated your answer to include bytes count in the title and look better. If you like, you can use tio.run to provide an online working example of your code too. It also allows you to copy an auto generated answer with all the formatting ready to be posted. When you are done with your code, you can click on 🔗 icon and copy "Code Golf submission (Stack Exchange)" section here to post as an answer. \$\endgroup\$
    – Night2
    Oct 23, 2019 at 8:42
  • 1
    \$\begingroup\$ print("sixteen") \$\endgroup\$
    – Jo King
    Sep 16, 2020 at 1:18
1
\$\begingroup\$

Some answers with "production" (i.e. non-golfing) languages still not mentioned here:

C++ (clang), 55 bytes

#include<iostream>
int main(){std::cout<<"fifty five";}

Try it online!

Scala, 23 bytes

println("twenty three")

Try it online!

Haskell, 27 24 bytes

main=putStr"twenty four"

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ For Haskell you could do main=putStr"twenty four" \$\endgroup\$
    – Sara J
    Oct 25, 2019 at 11:05
  • \$\begingroup\$ @SaraJ Thanks! Fixed. \$\endgroup\$
    – trolley813
    Oct 25, 2019 at 11:12
  • 2
    \$\begingroup\$ For all of these you can remove the digits part and just leave the fifty/twenty \$\endgroup\$
    – Jo King
    Oct 26, 2019 at 4:55
  • \$\begingroup\$ this is years old, but the C++ answer can be easily golfed down to print fifty, and the Scala answer seems to throw an error in TIO \$\endgroup\$
    – des54321
    Apr 18, 2022 at 4:49
1
\$\begingroup\$

Gaia, 5 bytes

five”

Just a string literal that gets implicitly output.

Try it online!

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

Runic Enchantments, 6 bytes

"Six"@

Try it online!

This ended up being both much shorter and much less interesting than I anticipated. 3 bytes are required for syntax, making it impossible to go lower.

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

Tcl, 9 bytes

puts nine

prints

nine

Try it online!

Tcl, a lot more bytes (not finished yet) currently 42

this will read the source code counts the characters and convert the number into an actual number word.

content of c.tcl:

puts [string length [read [open c.tcl r]]]

prints:

% 42
\$\endgroup\$
1
\$\begingroup\$

Malbolge, 30 bytes

('B;_#!~[|:9zVw/.uQrOqon&Jl6"'

Try it online!

Created with ZB3's Malbolge Tools

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

W, 5 bytes

five"

Implicitly prepends a quote. In order to specify your input, find prog.py and do this:

read = []

prog = 'five"'

Wren, 26 bytes

Just a method that outputs a string literal.

System.write("twenty six")

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ The number of quotes in your first program is definitely not odd... \$\endgroup\$ Nov 18, 2019 at 15:02
  • \$\begingroup\$ W automatically "prepends" a quote z. \$\endgroup\$
    – user85052
    Nov 18, 2019 at 23:15
  • \$\begingroup\$ Ah, that makes sense. Interesting! \$\endgroup\$ Nov 19, 2019 at 20:39
1
\$\begingroup\$

Underload, 6 bytes

Try it online! (six)S

Explanation

(six)  Puts the text "six" onto the stack.
S      Prints it.
\$\endgroup\$
1
\$\begingroup\$

Charcoal, 4 bytes

four

Try it online

The program just implicitly prints the string literal.

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