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

110 Answers 110

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

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

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.