35
\$\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 at 12:14

81 Answers 81

64
\$\begingroup\$

Google, 11 9 8 6 bytes

-3 bytes thanks to 12Me21.

-2 bytes thanks to Deckerz.

6=wrds

Try it online!

Just in case Google changes something in the future, this is how it looks like now:

Google six in words

\$\endgroup\$
45
\$\begingroup\$

Poetic, 400 bytes

Type fourhundred chars? I say, I think I have an angle.
I say "Gosh, could I just go create some poem? Clearly it comes a long way, writing stuff I say."
I compose the entire written poem, and someone reads a tiny, tiny portion.
"Surely, it all is garbage," cried a big fat crybaby.
Would HE frankly notice how many long, tedious hours I took?
The crybaby whined a lot. I watched, then I ignored him.

Try it online!

Prints Four HunDrED. (I tried to make it print some number in the 300s, but I can't seem to do so in under 400 bytes.)

Poetic is an esolang I made in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols.

\$\endgroup\$
  • 3
    \$\begingroup\$ Clearly it comes a long way, writing stuff I say. Beautiful poem, have a +1. \$\endgroup\$ – A̲̲ Oct 20 at 1:56
  • 2
    \$\begingroup\$ @A_ Thanks, it's always fun to create coherent sentences based on pre-determined word lengths. \$\endgroup\$ – JosiahRyanW Oct 20 at 2:01
30
\$\begingroup\$

brainfuck, 40 bytes

+[+++++>++<]>.+++++++++.+++.++.+++++.+++

Try it online!

The last three characters don't actually do anything useful, but it's easier to output forty than thirty seven.

The ascii code for f is 102, which is 2/5 of 255, found by the initial loop. After that, all the characters in the output just happen to be in ascending alphabetical order.

\$\endgroup\$
  • \$\begingroup\$ Whoops, I don't know why I was trying to use different cells for each letter... Nice \$\endgroup\$ – HiddenBabel Oct 19 at 18:46
  • \$\begingroup\$ @HiddenBabel Thanks. forty turned out really well. I think for NINETY the optimum would be one cell for NNTY and one cell for IE \$\endgroup\$ – Level River St Oct 20 at 2:16
  • \$\begingroup\$ So I guess you already looked for thirty with one cell for trty and one for hi? I can't find a singular loop that will set both of them close by. \$\endgroup\$ – HiddenBabel Oct 20 at 2:33
  • 2
    \$\begingroup\$ Indeed, forty is the only number whose letters are in ascending alphabetical order. \$\endgroup\$ – Neil Oct 20 at 9:45
27
\$\begingroup\$

MathGolf, 2 bytes

Well, MathGolf has a string compression library that seems to compress "two" to 1 byte. You need a command to decompress this.

╩_

Try it online!

\$\endgroup\$
  • 7
    \$\begingroup\$ Now we're looking for a language where there's a 1-char command that prints one, or where the empty program prints zero. That's going to be interesting. \$\endgroup\$ – my pronoun is monicareinstate Oct 19 at 14:03
  • 1
    \$\begingroup\$ @Nat MathGolf can use Code Page 437, in which is one byte (0xCA) \$\endgroup\$ – pizzapants184 Oct 20 at 20:39
  • 2
    \$\begingroup\$ @Nat MathGolf has a built-in dictionary, the first 256 words of which can be accessed using followed by one byte. The word at index 95 (the code point for _) is "two", so "two" is pushed to the stack and implicitly printed when the program exits. (I think, I haven't used MathGolf) \$\endgroup\$ – pizzapants184 Oct 20 at 21:25
17
\$\begingroup\$

Google Translate (3 bytes)

Try it online!

It's the Chinese character for "one" (matching the number of characters in the source code), though the score's due to the character itself being 3 bytes.


Google Translate (3 bytes)

tre

Try it online!

It's Italian for "three".

\$\endgroup\$
  • 2
    \$\begingroup\$ You can add a &tl=en at the end of your URLs to force it to show in English. My Google translate was set to English to Persian from a previous translation and after opening your links, it was showing the resulting numbers in Persian :P Here is also a 2 chars version, converting Persian دو to English Two. \$\endgroup\$ – Night2 Oct 20 at 13:59
  • 2
    \$\begingroup\$ ...also (Latin-ised) Hindi "do". \$\endgroup\$ – Jonathan Allan Oct 20 at 22:11
  • 1
    \$\begingroup\$ and albanian dy \$\endgroup\$ – ev3commander Oct 20 at 22:36
  • 1
    \$\begingroup\$ to is Norwegian and Danish for two (and we also say tre for three). Google translate doesn't autodetect that one, though. \$\endgroup\$ – Arthur Oct 21 at 16:17
  • 1
    \$\begingroup\$ cinco, that means five in Spanish \$\endgroup\$ – JuanCa Oct 22 at 19:43
15
\$\begingroup\$

CSS, 30 bytes

body::after{content:'thirty';}


CSS (Google Chrome only), 26 bytes

This should be saved in an empty file between <style> and </style> tag, doesn't work on FireFox or Stack Exchange's code snippets. Tested on Windows Chrome 77.

:after{content:'twenty six
\$\endgroup\$
  • 1
    \$\begingroup\$ Never would have thought of this one: +1 \$\endgroup\$ – Redwolf Programs Oct 19 at 13:44
14
\$\begingroup\$

PHP, 4 bytes

four

Try it online!


PHP, 9 bytes

<?= nine;

Try it online!

\$\endgroup\$
14
\$\begingroup\$

Python 3, 15 bytes

exit("fifteen")

...prints to STDERR.

Try it online! (see the "debug" panel)

\$\endgroup\$
  • 1
    \$\begingroup\$ I had print('sixteen'), you win :) \$\endgroup\$ – Jylo Oct 22 at 6:52
  • 1
    \$\begingroup\$ print'ten', in Python 2? \$\endgroup\$ – JuanCa Oct 22 at 19:47
  • 1
    \$\begingroup\$ @JuanCa yes \$\endgroup\$ – Jonathan Allan Oct 22 at 20:05
14
\$\begingroup\$

COW, 800 bytes

MoO!!
MoO MoO!!
MoO MoO MoO!!
MoO MoO MoO MoO!!
MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO MMM MoO MoO MoO!!
MoO MoO MoO MoO MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO Moo MoO MoO MoO MoO Moo MOo MOo!!
Moo MoO Moo MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO!!
MoO MoO Moo MMM Moo MoO MoO MoO MoO MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO!!
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO!!
Moo MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO Moo MOo MOo!!
MOo MOo MOo MOo MOo Moo MOo MOo MOo MOo MOo MOo MOo MOo MOo MOo Moo MMM!!
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO Moo MMM MoO Moo MOo Moo!

Try it online!

Prints EIGHT HUNDRED

\$\endgroup\$
  • 4
    \$\begingroup\$ I think ONE THOUSAND is expected. \$\endgroup\$ – A̲̲ Oct 20 at 8:08
  • 1
    \$\begingroup\$ @A_ EIGHT HUNDRED then! Mooooo! \$\endgroup\$ – Night2 Oct 20 at 8:47
12
\$\begingroup\$

Wolfram Alpha, 6 bytes

Apparently Wolfram Alpha isn't a language according to our meta, but we have a Google entry in this challenge and part of the argument against Wolfram Alpha is "What's preventing me from solving something in google".

spell6

Try it

Note that this returns a single result, unlike most Wolfram Alpha "queries".

enter image description here

\$\endgroup\$
11
\$\begingroup\$

Malbolge, 40 bytes

(CB%#9]~}5:3Wyw/4-Qrqq.'&Jkj(h~%|Bd.-==;
\$\endgroup\$
  • 3
    \$\begingroup\$ Is it possible to add a code break-down, or if you can't say how it works then how it was produced? \$\endgroup\$ – Jonathan Allan Oct 22 at 8:55
  • \$\begingroup\$ There exists a certain Malbolge generator. It is very useful in generating short Malbolge code. :) \$\endgroup\$ – dingledooper Oct 22 at 22:26
10
\$\begingroup\$

Labyrinth, 10 bytes

84.69.78.@

Try it online!

How?

  - initially the main stack contains infinite zeros    [0,0,0,...]
8 - multiply the top of the stack by ten and add eight  [8,0,0,...]
4 - multiply the top of the stack by ten and add four   [84,0,0,...]
. - pop, mod 256, print character                       T
6 - multiply the top of the stack by ten and add six    [6,0,0,...]
9 - multiply the top of the stack by ten and add nine   [69,0,0,...]
. - pop, mod 256, print character                       E
7 - multiply the top of the stack by ten and add seven  [7,0,0,...]
8 - multiply the top of the stack by ten and add eight  [78,0,0,...]
. - pop, mod 256, print character                       N
@ - exit
\$\endgroup\$
  • 11
    \$\begingroup\$ As an IP address range this answer geolocates to the United Kingdom with Vodafone wireless broadband. \$\endgroup\$ – Purple P Oct 19 at 16:38
  • \$\begingroup\$ @PurpleP Ha ha awesome. \$\endgroup\$ – Jonathan Allan Oct 19 at 16:42
  • 5
    \$\begingroup\$ @PurpleP First thing I thought of when seeing this answer (IP address, not UK Vodafone) \$\endgroup\$ – Redwolf Programs Oct 19 at 19:18
10
\$\begingroup\$

Emoji, 18 bytes

⛽eighteen🚘➡

Try it online!


Emoji, 8 chars

⛽eight🚘➡

Try it online!

\$\endgroup\$
  • 5
    \$\begingroup\$ ⛽🚘➡ ...gasoline makes the car go? \$\endgroup\$ – Darrel Hoffman Oct 21 at 17:11
8
\$\begingroup\$

Brainf***, 90 bytes

+[+[>>+<+<-]>]>[>+>+>+>+>+>+<<<<<<-]>.>-----.>.>---------.>++++++.>+++++++++++.<+><><><><>

Try it online!

\$\endgroup\$
7
\$\begingroup\$

SOGL V0.12, 3 bytes

Well, SOGL has a string compression library that seems to compress "three" to 3 bytes.

@0‘

Try it Here!

\$\endgroup\$
  • \$\begingroup\$ Gratz, unless a language exists which prints zero, nowt, or nought with an empty program this is probably as good as it'll get. \$\endgroup\$ – Jonathan Allan Oct 19 at 13:56
  • 1
    \$\begingroup\$ ...I stand corrected! \$\endgroup\$ – Jonathan Allan Oct 19 at 14:04
6
\$\begingroup\$

Jelly, 4 bytes

“Ɱ9»

Try it online!

\$\endgroup\$
6
\$\begingroup\$

Keg, 3 bytes

-1 from Jono2906 for reminding me the string compression

2 can play the 3 byte game!

‘0⅀

TIO

Old answer, 4 bytes

You can't get shorter than 4. (Without using string compression of course.) 4 is the smallest English word that is the same length as the number it represents.

Just some good old-fashioned Ascii/auto-pushing Keg golfing!

four

Try it online!

Explanation

four#   Push 4 onto the stack
#Implicit Print
\$\endgroup\$
  • \$\begingroup\$ Ah, didn't see your answer when I posted mine. Good job! \$\endgroup\$ – Jono 2906 Oct 20 at 0:31
5
\$\begingroup\$

JavaScript, 16 10 bytes

-6 each from Night2's suggestion in the comments

Try it online! (alert doesn't work in TIO, so I'm using print)

alert`ten`

Javascript, 26 20 bytes

Try it online!

console.log`twenty`;
\$\endgroup\$
  • \$\begingroup\$ @Night2 The JS print function is used for printers, not console output, I think. \$\endgroup\$ – Redwolf Programs Oct 19 at 19:10
  • 1
    \$\begingroup\$ @Night2 Ah, makes sense. I'll update the TIO, but keep it as alert on here since it's more recognizable (sort of) \$\endgroup\$ – Redwolf Programs Oct 19 at 20:11
  • \$\begingroup\$ Where can I find some explanation regarding the syntax used here? I've never seen this before (ommiting the brackets), but it indeed works with any function. What's it called? \$\endgroup\$ – Tomáš Zato - Reinstate Monica Oct 21 at 13:50
  • 1
    \$\begingroup\$ @TomášZato They're called tagged templates. I found some info on them here, in the Tagged templates section \$\endgroup\$ – Redwolf Programs Oct 21 at 15:42
5
\$\begingroup\$

C# (.NET Core), 64 bytes

class P{static void Main(){System.Console.Write("sixty four");}}

I had to see what a non-competative language would score.

Try it online!

\$\endgroup\$
  • 3
    \$\begingroup\$ sixty? \$\endgroup\$ – Night2 Oct 20 at 6:53
  • 1
    \$\begingroup\$ Would be nine if lambdas were allowed. \$\endgroup\$ – Neil Oct 20 at 9:44
5
\$\begingroup\$

Piet, 90 codels

enter image description here

Try it online!

In pseudo-code:

The characters are pushed onto stack. To save space, their ASCII values minus 100 are stored. When the string is built, a loop pops, adds 100 to, and prints each character to STDOUT.

    ; Place sentinel 0 on stack
    push 1
    not

    ; Place 21 (y) on stack
    push 7
    push 3
    mul

    ; Place 16 (t) on stack
    push 4
    dup
    mul

    ; Place 1, 10, 5, 10 (e, n, i, n) on stack
    push 1
    push 10
    push 5
    push 10

    ; Check if top of stack is non-zero
    ; Place a 1 if it is, a 0 otherwise
    dup
    not
    not

write_loop:
    ; Turn DP (Direction Pointer) as many steps
    ; clock-wise as value on top of stack
    ; If we had a zero on stack, we continue into
    ; the yellow area and get trapped, ending execution
    pointer

    ; If not, we continue
    ; Add 100 to top of stack
    push 5
    push 4
    push 5
    mul
    mul
    add

    ; Pop and print character
    outc

    ; Turn DP one step to the right
    push 1
    pointer

    dup
    not
    not

    ; Check if top of stack is non-zero
    ; Place a 1 if it is, a 0 otherwise
    dup
    not
    not

    ; We're now back at beginning of the writing loop, sort of like a jmp write_loop
\$\endgroup\$
  • \$\begingroup\$ How many bytes is this? \$\endgroup\$ – Jo King Oct 22 at 22:56
  • 1
    \$\begingroup\$ @JoKing Depends on the fileformat for the image, which is why Piet is generally counted in codels. \$\endgroup\$ – gastropner Oct 22 at 23:24
  • \$\begingroup\$ Yes, but this is code-golf, so it is measured in bytes \$\endgroup\$ – Jo King Oct 22 at 23:29
  • \$\begingroup\$ @JoKing That is curious. I have not seen that comment on any other Piet answers. \$\endgroup\$ – gastropner Oct 22 at 23:36
5
\$\begingroup\$

Lost, 30 bytes

v<<<<<<<>>>>>>>
>%?"thirt/J"+@

Contains the unprintable character ESC with unicode value 27 after the ^ on the second line. Thanks to @JoKing getting rid of the unprintable (for the same byte-count).

Try it online or verify that it's deterministic.

Explanation:

Explanation of the language in general:

Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that both the start position AND starting direction it travels in is completely random. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky.

A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up/north, down/south, left/west, or right/east.

In Lost you therefore want to lead everything to a starting position, so it'll follow the designed path you want it to. In addition, you'll usually have to clean the stack when it starts somewhere in the middle.

Explanation of the program:

All arrows, including the reflect / in the string, will lead the path towards the leading > on the second line. From there the program flow is as follows:

  • >: travel in an east/right direction
  • %: Put the safety 'off'. In a Lost program, an @ will terminate the program, but only when the safety is 'off'. When the program starts, the safety is always 'on' by default, otherwise a program flow starting at the exit character @ would immediately terminate without doing anything. The % will turn this safety 'off', so when we now encounter an @ the program will terminate (if the safety is still 'on', the @ will be a no-op instead).
  • ?: Clean the top value on the stack. In some program flows it's highly likely we have a partial string on the stack, so we use this to wipe the stack clean of that potential string.
  • ": Start a string, which means it will push the integer code-points of the characters used.
  • thirt/J: Push the code-points for these characters, being 116 104 105 114 116 47 74 respectively
  • ": We're done pushing code-points of this string
  • +: Add the top two values together: (47+74=) 121
  • @: Terminate the program if the safety is 'off' (which it is at this point). After which all the values on the stack will be output implicitly. Using the -A program argument flag, these code-points will be output as characters instead.

Two things to note:

The top part could also have been v<<<<<<<<<<<<<< instead. Lost will wrap around to the other side when moving in a direction. So using v<<<<<<<>>>>>>> could be a slightly shorter path, and since it's the same byte-count anyway, why not use it. :)
Also, the first line contains an additional trailing > to make the byte-count from 29 to 30.

\$\endgroup\$
  • \$\begingroup\$ This is a nice find! \$\endgroup\$ – ouflak Oct 21 at 13:07
  • \$\begingroup\$ @ouflak Thanks, although I must admit it's very similar as the Hello World! answer in Lost. It took a while before I realized I could use an unprintable to output thirty, though. Otherwise I would have had to settle with forty with a bunch more no-op trailing >. \$\endgroup\$ – Kevin Cruijssen Oct 22 at 7:23
  • \$\begingroup\$ You can do /J to avoid the unprintable if you like \$\endgroup\$ – Jo King Oct 22 at 23:02
  • \$\begingroup\$ @JoKing Ah, I tried some combinations with both addition and subtraction of the arrow, but forgot about the reflects / and ``. Thanks, that indeed looks better. :) \$\endgroup\$ – Kevin Cruijssen Oct 23 at 6:19
4
\$\begingroup\$

Batch, 10 bytes

@ echo ten

If you think the extra space after the @ is ugly, the next possible answer is:

@echo twelve
\$\endgroup\$
  • \$\begingroup\$ Why not just echo nine? \$\endgroup\$ – Night2 Oct 19 at 15:20
  • \$\begingroup\$ @Night2 Because that echos the command echo nine as well as its output. \$\endgroup\$ – Neil Oct 19 at 16:36
  • \$\begingroup\$ But running directly from command prompt, doesn't do that (unless it doesn't count as Batch). \$\endgroup\$ – Night2 Oct 19 at 17:38
  • 1
    \$\begingroup\$ @Night2 No, that would be a snippet, or a REPL, or something along those lines. \$\endgroup\$ – Neil Oct 19 at 18:33
4
\$\begingroup\$

05AB1E (legacy), 3 bytes

“„í

Try it online!

Using dictionary

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

Shakespeare Programming Language, 800 bytes

Try it online!

(Whitespace added for readability)

800 Bytes-- filler.Ajax,.Puck,.Act I:.
Scene I:.[Enter Ajax and Puck]Ajax:
You is the sum ofthe sum ofthe cube ofa big big cat a big big cat a cat.Speak thy.
You is the sum ofyou a big big cat.Speak thy.
You is the sum ofyou a big pig.Speak thy.
You is the sum ofyou a cat.Speak thy.
You is the sum ofyou twice the sum ofa big big cat a big cat.Speak thy.
You big big big big big cat.Speak thy.
You is twice the sum ofyou a big big cat.Remember you.Speak thy.
You is the sum oftwice you the cube ofthe sum ofa big pig a pig.Speak thy.
You is the sum ofyou the sum ofa big big big pig a cat.Speak thy.
Recall.You is the sum ofyou a big big pig.Remember you.Remember you.Speak thy.
You is the sum ofyou twice the sum ofa big big big cat a pig.Speak thy.
Recall.You is the sum ofyou a cat.Speak thy.
Recall.Speak thy.

Prints EIGHT HunDRED. The math to get from one letter to another was very complicated and there was little room for error. This is probably improvable in terms of code, but 700 is most likely impossible.

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

Python 3, 16 bytes

print("sixteen")

Try it online!

Also works in Proton.

\$\endgroup\$
  • 1
    \$\begingroup\$ I think you just beat me to this. Same code works in both Python 3 and Lua. \$\endgroup\$ – ouflak Oct 19 at 15:41
3
\$\begingroup\$

ink, 4 bytes

Four

Try it online!

Predictably enough, it prints Four

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

GolfScript, 6 bytes

Push six. Implicit print.

 'six'

Try it online!

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

Bash, 15 9 bytes

echo nine

Try it online!

Thanks to:
- @Night2 for saving me 6 bytes

\$\endgroup\$
  • 3
    \$\begingroup\$ 9 bytes. By the way you can click on 🔗 icon in tio.run and copy/paste "Code Golf submission (Stack Exchange)" section here to have auto generated answer with correct formatting. \$\endgroup\$ – Night2 Oct 19 at 17:41
  • \$\begingroup\$ @Night2 Thank your for the improvment and the tip :) \$\endgroup\$ – Delta Oct 19 at 18:05

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.