36
\$\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\$
  • \$\begingroup\$ Proper spacing is also required. Does this mean no trailing spaces in the output? \$\endgroup\$ – Engineer Toast Oct 23 '19 at 12:14

83 Answers 83

1 2 3
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\$

Taxi, 164 bytes

"One hundred sixty four" is waiting at Writer's Depot.
Go to Writer's Depot:w 1 r 3 l 2 l.
Pickup a passenger going to Post Office.
Go to Post Office:n 1 r 2 r 1 l.

Try it online!

This also throws an error because I don't return the taxi to the garage so my boss fires me. It's not a requirement to not throw errors, though, so I guess I'm fired.

\$\endgroup\$
  • \$\begingroup\$ Yeah, that's all and well. \$\endgroup\$ – Andrew Oct 22 '19 at 14:52
  • \$\begingroup\$ Surely you can just.. remove the four \$\endgroup\$ – Jo King Oct 22 '19 at 22:55
  • \$\begingroup\$ @JoKing Ha! You're right. I'll fix that tomorrow. (And don't call me Shirley.) \$\endgroup\$ – Engineer Toast Oct 22 '19 at 23:57
1
\$\begingroup\$

T-SQL, 10 bytes

print'ten'

I guess is correct, right? :)

\$\endgroup\$
  • \$\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 '19 at 17:45
  • 1
    \$\begingroup\$ @Night2 It's Microsoft SQL Server. And yes, but that's 5 bytes more :P \$\endgroup\$ – JuanCa Oct 21 '19 at 18:01
  • \$\begingroup\$ you should probably make this T-SQL as the language \$\endgroup\$ – MickyT Oct 21 '19 at 20:53
  • \$\begingroup\$ @MickyT Thank you! \$\endgroup\$ – JuanCa Oct 22 '19 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\$
  • \$\begingroup\$ Does this output a hyphen? If so, that's against spec unfortunately. \$\endgroup\$ – boboquack Oct 24 '19 at 7:12
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
    \$\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 '19 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 '19 at 8:42
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\$
  • 1
    \$\begingroup\$ For Haskell you could do main=putStr"twenty four" \$\endgroup\$ – Sara J Oct 25 '19 at 11:05
  • \$\begingroup\$ @SaraJ Thanks! Fixed. \$\endgroup\$ – trolley813 Oct 25 '19 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 '19 at 4:55
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\$

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\$
  • \$\begingroup\$ The number of quotes in your first program is definitely not odd... \$\endgroup\$ – Hello Goodbye Nov 18 '19 at 15:02
  • \$\begingroup\$ W automatically "prepends" a quote z. \$\endgroup\$ – user85052 Nov 18 '19 at 23:15
  • \$\begingroup\$ Ah, that makes sense. Interesting! \$\endgroup\$ – Hello Goodbye Nov 19 '19 at 20:39
0
\$\begingroup\$

SWI-Prolog, 15 bytes

write(fifteen).

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Ten: write(ten)? \$\endgroup\$ – Night2 Oct 20 '19 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 '19 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 '19 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
\$\begingroup\$

Husk, 3 bytes

¨◊ė

Try it online!

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

Java 8 (full program), 75 bytes

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

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

Gaia, 5 bytes

five”

Just a string literal that gets implicitly output.

Try it online!

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

Java, 168 bytes

An all too trivial answer, I know. But I'm a noob.

System.out.println("thirtytwo");

Edit: Wow I just realized this does not have the right spacing!

I also wrote these map/reduce ones instead.

byte b[] = "One Hundred Sixty Seven".getBytes();
System.out.println(IntStream.range(0, b.length).mapToObj(x->new String(new byte[] {b[x]})).reduce((x, y)->x+y).get());
System.out.println(IntStream.range(0, 23).mapToObj(x->"One Hundred Twenty Five".substring(x,x+1)).reduce((x, y)->x+y).get());

In response to Jo King, I have added a method declaration.

public static void main(String[] args) { System.out.println(IntStream.range(0, 23).mapToObj(x->"One Hundred Sixty Eight".substring(x,x+1)).reduce((x, y)->x+y).get()); }
\$\endgroup\$
  • 1
    \$\begingroup\$ I don't think any of these work without the boilerplate, which needs to be included \$\endgroup\$ – Jo King Oct 27 '19 at 12:10
  • \$\begingroup\$ You mean I need to put a function? Or the main method? Sorry I am new. \$\endgroup\$ – Disco Mike Oct 27 '19 at 14:31
  • \$\begingroup\$ It needs to be either a full program or a function. Only the last one is a function, though I don't think it counts as a serious attempt at golfing \$\endgroup\$ – Jo King Oct 27 '19 at 21:09
0
\$\begingroup\$

Malbolge, 30 bytes

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

Try it online!

Created with ZB3's Malbolge Tools

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

Underload, 6 bytes

Try it online! (six)S

Explanation

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

Charcoal, 4 bytes

four

Try it online

The program just implicitly prints the string literal.

\$\endgroup\$
1 2 3

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.