# Question
Title: Create a program that prints the number of characters it has, in words
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?

# Answer
# 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.
> 67 votes

# Answer
# 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*".
> 38 votes

# Answer
# 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.
> 35 votes

# Answer
# 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!
> 30 votes

# Answer
# Python 3, 15 bytes

```
exit("fifteen")

```

...prints to STDERR.

**Try it online!** (see the "debug" panel)
> 17 votes

# Answer
# 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`
> 17 votes

# Answer
# 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

```
> 16 votes

# Answer
# PHP, 4 bytes

```
four

```

Try it online!

---

# PHP, 9 bytes

```
<?= nine;

```

Try it online!
> 15 votes

# Answer
# Malbolge, 40 bytes

```
(CB%#9]~}5:3Wyw/4-Qrqq.'&Jkj(h~%|Bd.-==;

```
> 15 votes

# Answer
# 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

```
> 12 votes

# Answer
# Piet, 90 codels

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

```
> 11 votes

# Answer
# Emoji, 18 bytes

```
⛽eighteen➡

```

Try it online!

---

# Emoji, 8 chars

```
⛽eight➡

```

Try it online!
> 10 votes

# Answer
# Piet \+ ascii-piet, 40 bytes (3×14=42 codels)

```
ttllldabknmEmqusbeeeeeute_rbacqtuljvff ?

```

Try Piet online!

Prints `FORTY`. A fantastic use case of a white trap :) Also I like the fact that the program is packed so perfectly.

### How it works

A classic 3-row layout with a `1 DP+` at the left edge.

```
Commands        Stack
2 3 dup dup *   [2 3 9]
dup dup 1 - *   [2 3 9 72]
2 -             [2 3 9 70]   Setup the stack so that repeatedly adding and
                             printing gives FORT
dup outC + dup outC +
dup 1 DP+ outC + dup outC
                [84]   Print FORT, turning right at R2C1
>               [84]   No-op (stack underflow) to take care of the crossing
5 + outC        []     Finally print Y

```

---

# Piet \+ ascii-piet, 50 bytes (4×13=52 codels)

```
ttttliametf M tt iillldedMnjlvjcfll i Mkmuuljcbjjj

```

Try Piet online!

Prints `fifty`. Not sure if I can do 40, but I guess pretty much unlikely.

### How it works

The execution path: First row -\> (turn right) -\> 3rd-to-last column -\> (turn right) -\> last row in reverse -\> (turn right twice) -\> 3rd row -\> transfer to 2nd row at the red 5 block -\> end.

```
...>>>>>>>v X
 .. ....>>+>X
>>>>>>>.. v X
^<<<<<<<<..

```

Commands:

```
Commands          Stack
6 dup 3 * 1 - *   [102]   Push 102 ('f')
dup outC          [102]   Print 'f'
dup 3 + outC      [102]   Print 'i' (= 'f' + 3)
dup outC          [102]   Print 'f'
2 dup dup +       [102 2 4]
dup * - -         [116]   Add 14 to 'f' (= 't')
dup outC          [116]   Print 't'
5 inC + outC      []      Add 5 and print 'y'
                          (inC is ignored; it is to reuse the crossing purple cell)

```
> 10 votes

# Answer
# Hexagony, 6 bytes, 17 cycles

```
s;i>x@

```

Try it online!

Now the letters `six` are in more natural order, and the program finishes one cycle faster.

### How it works

For more thorough explanation, see the previous answer below.

```
 A B
C > D
 E .
Execution path: ABC>CBAD>ADB.>.CE
                ^^  ^^    ^^    ^
                s;  i;    x;    @

```

---

# Hexagony, 6 bytes, 18 cycles

```
x>i;s@

```

Try it online!

Inspired by boboquack's 9-byte solution. The following quote was a big hint:

> 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*).

### How it works (or, How I got to this solution)

A 6-byte program is laid out on a hexagon of side length 2, and the 7th instruction is necessarily a no-op:

```
 ? ?
? ? ?
 ? .

```

Since I needed at least one mirror, I tried out various mirrors placed at various places, until I found this:

```
 A >
B C D
 E .

```

Assuming the current memory is always positive (and there are no branches/mirrors/IP changers among `ABCDE`), the IP follows the path

```
A>ADCB>.CAD>DAC.BE

```

The cell `C` is run exactly three times, and the cells right before `C` are `D`, `B`, and `A` respectively. And the cell `E` is first run after three runs of `C`. This is exactly what we want: write one of `s`, `i`, or `x` on the memory and print it, and then terminate!

Now back to the actual source code:

```
 x >
i ; s
 @ .

```

And the execution path, linearized, with significant instructions emphasized:

```
x>xs;i>.;xs>sx;.i@
   ^^^  ^    ^^  ^
   ^^              Print 's'
     ^  ^          Print 'i'
             ^^    Print 'x'
                 ^ Terminate

```
> 9 votes

# Answer
# SOGL V0.12, 3 bytes

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

```
@0‘

```

Try it Here!
> 8 votes

# Answer
# Brainf\***, 90 bytes

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

```

Try it online!
> 8 votes

# Answer
# 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.
> 7 votes

# Answer
## 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`;

```
> 6 votes

# Answer
# 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

```
> 6 votes

# Answer
# Jelly, 4 bytes

```
“Ɱ9»

```

**Try it online!**
> 6 votes

# Answer
# C# (.NET Core), 64 bytes

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

```

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

Try it online!
> 6 votes

# Answer
# 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 twice the sum ofa big cat a 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. Little improvement saving 2 bytes in the actual code because I missed out on optimizing 2\*(4+2) to 2\*2\*(2+1) for some reason.
> 6 votes

# Answer
# Excel, 4 bytes

```
four

```

Uninteresting answer, not using a formula.

---

### Excel, 5 bytes

```
'five

```

Using a formula, requires at least 3 extra bytes (`=`, `"`, `"`).

### Excel, 6 bytes

```
="six"

```

### Excel, 12 bytes

```
="tw"&"elve"
=T("twelve")

```

### Excel, 14 bytes

```
=T("fourteen")

```

### Excel, 16 bytes

```
=IF(1,"sixteen")

```

### Excel, 18 bytes and upwards

```
=TRIM(" % ")

```

Insert required text, padded with required whitespace.
> 5 votes

# Answer
# Taxi, ~~164~~ 160 bytes

```
"One hundred sixty" 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.
> 5 votes

# Answer
# vemf, ~~6~~ 5 bytes

```
"five

```

Outputs `five`. try it online
> 5 votes

# Answer
# Python 3, 16 bytes

```
print("sixteen")

```

Try it online!

Also works in Proton.
> 4 votes

# Answer
# ink, 4 bytes

```
Four

```

Try it online!

Predictably enough, it prints `Four`
> 4 votes

# Answer
# 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.*
> 4 votes

# Answer
## Batch, 10 bytes

```
@ echo ten

```

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

```
@echo twelve

```
> 4 votes

# Answer
# 05AB1E (legacy), 3 bytes

```
“„í

```

Try it online!

Using dictionary
> 4 votes

# Answer
# Bash, ~~15~~ 9 bytes

```
echo nine

```

Try it online!

Thanks to:
\- @Night2 for saving me 6 bytes
> 4 votes

# Answer
# 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

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.
> 4 votes

# Answer
# TI-Basic, 5 bytes

```
"FIVE

```

Also works with `"SEVEN"`.
> 4 votes

# Answer
# GolfScript, 6 bytes

Push `six`. Implicit print.

```
 'six'

```

Try it online!
> 3 votes

# Answer
# Lua, 10 bytes

```
print"ten"

```

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

# Answer
# Japt, 4 bytes

```
`fr

```

Test it here
> 3 votes

# Answer
# Backhand, 6 bytes

```
"s"xiH

```

Try it online!

Outputs "six".
> 3 votes

# Answer
# 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.
> 3 votes

# Answer
# R, ~~7~~ 6 bytes

```
 "six" #space before the text

```

Previously:

```
"seven"

```
> 3 votes

# Answer
# Ruby, 6 bytes

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

```
p'six'

```

Try it online!
> 2 votes

# Answer
# Red, 10 bytes

```
print 'ten

```

Try it online!
> 2 votes

# Answer
# Japt, 5 bytes

```
"five

```

Try it online!
> 2 votes

# Answer
# Zsh, 6 bytes

```
<<<six

```

Try it online!
> 2 votes

# Answer
# C (gcc), ~~25~~ 20 bytes

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

```

Try it online!
> 2 votes

# Answer
# 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!
> 2 votes

# Answer
# , 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

# , 6 bytes

```
"six";

```

Try it online!

which prints `[1] "six"`.

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

# , 4 bytes

```
four

```

Try it online!

which prints to STDERR `Error: object 'four' not found`.
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# Perl 5, 9 bytes

```
say"nine"

```

Try it online!
> 2 votes

# Answer
# cat, 4 bytes

```
four

```

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

# Answer
# 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 `V`s and Form Feeds replaced with `F`s:

```
VVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVFVVV

```

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.
> 2 votes

# Answer
# Zsh, 6 bytes

```
<<<six

```

Try it online!
> 2 votes

# Answer
# Vyxal, 3 bytes

```
`∧ḭ

```

Try it Online!

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

# Answer
# 05AB1E, 5 bytes

```
"five

```

Try it online!
> 2 votes

# Answer
# Red, 10 bytes

```
prin "ten"

```

Try it online!
> 2 votes

# Answer
# Cascade, 9 bytes

```
"
n
i
n
e

```

Try it online!

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

# Answer
# Rattle, 5 bytes

```
five|

```

Try it Online!

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

# Answer
# Factor, 9 bytes

```
[I nineI]
```

Attempt This Online!
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# Minecraft Command Blocks, 11 bytes

```
w @a eleven

```

Whispers `eleven` to every player

If `@ whispers to you:`  is not allowed

```
tellraw @a "twenty four"

```

outputs just `twenty four` and is **24** bytes.
> 2 votes

# Answer
# 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).
> 2 votes

# Answer
# 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".
> 2 votes

# Answer
# 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.
> 2 votes

# Answer
# Python 2, 10 bytes

```
print'ten'

```

**Try it online!**
> 1 votes

# Answer
# Lua, 16 bytes

```
print('sixteen')

```

Try it online!
> 1 votes

# Answer
# 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.
> 1 votes

# Answer
# 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)
> 1 votes

# Answer
# Cascade, 9 bytes

```
"
n
i
n
e

```

Try it online!
> 1 votes

# Answer
# 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.
> 1 votes

# Answer
# bit\**, 30 bytes

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

```

Try it online!
> 1 votes

# Answer
# Husk, 3 bytes

```
¨◊ė

```

Try it online!
> 1 votes

# Answer
# PowerShell, 6 bytes

Note the space before the first quotation mark.

```
 "six"

```

Try it online!
> 1 votes

# Answer
# Ruby, 9 bytes

```
puts:nine

```

Try it online!

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

# Answer
# 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!
> 1 votes

# Answer
# Java 8 (full program), ~~75~~ 70 bytes

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

```

-5 bytes thanks to *@CommandMaster*.

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.
> 1 votes

# Answer
## **T-SQL, 10 bytes**

```
print'ten'

```

I guess is correct, right? :)
> 1 votes

# Answer
# 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
> 1 votes

# Answer
**Erlang, 5 bytes**

```
five.

```

Enter this code at interpreter prompt.
> 1 votes

# Answer
## dc, 6 bytes

```
[six]P

```

prints:

```
six

```
> 1 votes

# Answer
# Hexadecimal Stacking Pseudo-Assembly Language, 80 bytes

```
200079400000200074400000200068400000
200067400000200069400000200045400000
140000

```

Try it online!
> 1 votes

# Answer
# 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.
> 1 votes

# Answer
# C (gcc), 29 bytes

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

```

It's an actual program...

Try it online!
> 1 votes

# Answer
# 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?
> 1 votes

# Answer
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!
> 1 votes

# Answer
# Gaia, 5 bytes

```
five”

```

Just a string literal that gets implicitly output.

Try it online!
> 1 votes

# Answer
# 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

```
> 1 votes

# Answer
# 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.
> 1 votes

# Answer
# , 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!
> 1 votes

# Answer
# Malbolge, 30 bytes

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

```

Try it online!

Created with ZB3's Malbolge Tools
> 1 votes

# Answer
# Underload, 6 bytes

Try it online! `(six)S`

# Explanation

```
(six)  Puts the text "six" onto the stack.
S      Prints it.

```
> 1 votes

# Answer
# Charcoal, 4 bytes

```
four

```

Try it online

The program just implicitly prints the string literal.
> 1 votes

# Answer
# International Phonetic Esoteric Language, 8 bytes

```
"eight"o

```

Pushes and prints the string "eight".
> 1 votes

# Answer
# Pip, 6 bytes

```
"six";

```

Try it online!

`;` is a comment.
> 1 votes

# Answer
# MAWP, 30 bytes

```
99W3M!;98W!;1M;2A!;2M!;11MM3M;

```

Try it!

prints in capitals.
> 1 votes

# Answer
# naz, 30 bytes

```
9a9m3a1o9s3s1o1a1o9a1o2a1o5a1o

```

Outputs `THIRTY`.
> 1 votes

# Answer
# StupidStackLanguage, <sup>~~55~~</sup> 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.
> 1 votes

# Answer
# Pxem, Filename: 6 bytes + Content: 0 bytes = 6 bytes.

* Filename: `six.px`
* Content is empty.

Sorry for a boring post.

Try it online!
> 1 votes

# Answer
# BRASCA, 5 bytes

```
`five

```

Try it!

## Explanation

```
`five      - Push "five" on the stack, char by char
<implicit> - Print the stack, reversed

```
> 1 votes

# Answer
# 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.
> 1 votes

# Answer
# Duocentehexaquinquagesimal, ~~39~~ 32 bytes

```
ÖtΛ‰[WåÙUYr™{—*l”î)‘RçÊí¹©ÓûŽUQ‹

```

Try it online!
> 1 votes

# Answer
# Knight, 6 bytes

```
O"six"

```

Try it online!

Not much to explain; `O` is shorthand for OUTPUT.
> 1 votes

# Answer
# 8086 DOS .COM file, 16 bytes

Hexdump:

```
0CD5:0100  B4 09 BA 08 01 CD 21 C3-73 69 78 74 65 65 6E 24 ......!.sixteen$

```

Assembly source:

```
        // NASM syntax with C comments because no SE highlighting
        [org 0x100]
        section .text
        global start
start:
        // int 21:09: write $-terminated string in ds:dx
        mov     ah, 0x09
        mov     dx, str
        int     0x21
        // exit
        ret
str:
        db      "sixteen$"

```

---

# 8086 DOS .COM file, dirty exit, 10 bytes

This one prints "ten" and then does whatever, likely in the form of a crash.

```
0CD5:0100  B4 09 BA 07 01 CD 21 74-65 6E                   ......!ten

```

```
        // NASM syntax with C comments because no SE highlighting
        [org 0x100]
        section .text
        global start
start:
        // int 21:09: write $-terminated string in ds:dx
        // but it prints even if it isn't $-terminated so why bother?
        // It's real mode, it'll find a $ eventually™
        mov     ah, 0x09
        mov     dx, str
        int     0x21
        // exit
        // jk
str:    // not $ terminated
        db      "ten"

```
> 1 votes

# Answer
# Vyxal, 3 bytes

```
`∧ḭ

```

Try it Online!

Dictionary compression FTW!!!
> 1 votes

# Answer
# Barrel, 4 bytes

```
four

```

Implicitly prints the unknown instructions "four". However, this could potentially be voided by later modifications, so here's a safe 5-byter that uses a string:

```
'five

```
> 1 votes

# Answer
# AWK, 20 bytes

```
BEGIN{print"twenty"}

```

Try it online!
> 1 votes

# Answer
# Emmental, 30 bytes

```
#84.#72.#73.#82.#84.#89.######

```

Try it online!
> 1 votes

# Answer
# tinylisp, 6 bytes

Very simple solution, `(q` quotes the name after it to prevent it from being evaluated, the parentheses are implicitly closed at the end of the line, and the result of the top-level statement is implicitly outputted,

```
(q six

```

Try it online!
> 1 votes

# Answer
# EEL - 78 Bytes

```
=83 !>=69 !>=86 !>=69 !>=78 !>=84 !>=89 !>=32 !>=69 !>=73 !>=71 !>=72 !>=84

```

**Explanation**

EEL (Easy Esoteric Lang) is an esoteric programming language created by me, easy to manage, hence the name. Below is a brief description of the language.

.-EEL is based on a vector of bytes initialized to zero, on which basic arithmetic operations can be performed, whose length is equal to 64Kb.

.-EEL allows the reading and writing of one byte at a time in the form of an ASCII character in the standard input and output respectively.

.-EEL has a brief help section which can be viewed from the interpreter.

.-EEL is extremely sensitive, so a wrong input byte can cause a wrong output.

.-EEL does not have an error/exception handling system, so it may crash unexpectedly if a fatal error such as division by zero occurs.

**Defined operations:**

**=000** -\> Copy the value of number 000 to the current byte.

**+000** -\> Add to the current byte, the value of number 000.

**-000** -\> Subtract to the current byte, the value of number 000.

***000** -\> Multiply to the current byte, the value of number 000.

**/000** -\> Divide to the current byte, the value of number 000 (cannot be zero).

**%000** -\> Calculate the modulo of the current byte and the value of number 000 (cannot be zero).

**\>** -\> Go to the next byte of the vector.

**\<** -\> Go to the previous byte of the vector.

**?** -\> Read a ASCII character from STDIN and assign it to current byte.

**!** -\> Write to current byte in STDOUT as an ASCII character.

**:** -\> Open/close the space for comments.

**.** -\> Exit the program.

**$** -\> Reference to current byte.

*NOTES:*

The 000 number can be s current byte reference operator ($).

The 000 number (x) must be an integer number, such 0 \< x \<= 255.

There must be a space character u+0020 after each number 000.

Try the EEL interpreter!
> 1 votes

# Answer
# Thunno, \\$ 5\log\_{256}(96)\approx \\$ 4.12 bytes

```
"five

```

Attempt This Online!

Pretty simple.
> 1 votes

# Answer
# Z80Golf, 10 bytes

```
00000000: 3e74 ff3e 65ff 3e6e ff76                 >t.>e.>n.v

```

Try it online!

```
  ld a, 't'
  rst 38h
  ld a, 'e'
  rst 38h
  ld a, 'n'
  rst 38h
  halt

```
> 1 votes

# Answer
# Nim, 10 bytes

```
echo "ten"

```

Attempt This Online!
> 1 votes

# Answer
# Aheui (esotope), 52 bytes

```
발밦밞발밞다받받밞밞따댜먛뻐더희xxxx

```

Try it online!

Contains 20 chars (16 hangul and 4 unused ascii) and prints `TWenty`. 19 seems to be out of reach. `NINTeen` barely fits, but the correct spelling of 19 is "nineteen".

```
밞바밣밞다밦발바발타밞밞따받탸먛뻐더희

```

Try it online!

---

# Aheui (esotope), 40 bytes, solves for bytes instead

```
발박받밞밝발박따땨먛뻐더희

```

Try it online!

Prints `FORTY`. The strictly increasing nature of `FORTY` is useful again.

Each Hangul character costs 3 bytes, so 40 bytes can fit 13 chars and a newline. Luckily `FORTY` can be printed in exactly 13 chars (4 for charcode differences, 5 for the value 70, 3 for "dup; print; add" loop, and 1 for halt).

```
발박받밞    Push 5, 2, 3, 9
밝발박따따  Push 70 (7 * 5 * 2)
빠맣다      Loop: dup; print as char; add
            Break when add fails
희          Halt

```
> 1 votes

# Answer
# Julia 1.0, 15 bytes

```
print(:fifteen)

```

Try it online!
> 1 votes

# Answer
# \>\<\>, 9 bytes

```
"ooooENIN

```

Try it online!

Prints `NINE` and halts with error (`E` is not a valid command).
> 1 votes

# Answer
# Zalgo, 54 bytes

```
t̝̐̄̇h̝̐̈̆i̝̐̉̆r̝̐̂̇t̝̐̄̇y̝̐̉̇

```

Escaped with each cluster per line:

```
t\u031d\u0310\u0304\u0307
h\u031d\u0310\u0308\u0306
i\u031d\u0310\u0309\u0306
r\u031d\u0310\u0302\u0307
t\u031d\u0310\u0304\u0307
y\u031d\u0310\u0309\u0307

```

Prints `thirty`. Pushing a constant and printing takes 4 characters, and the first number whose length in English is strictly smaller than 1/4 of its value is 30. For stylistic reasons, each grapheme cluster in this code prints its root character (e.g. `t̝̐̄̇` prints `t`). Python code used to generate the source.

---

# Zalgo, 25 bytes, 1 grapheme cluster

```
I̝̝̝̐̏̆̐̎̆̐̅̆

```

Escaped:

```
I\u031d\u031d\u031d\u0310\u030f\u0306\u0310\u030e\u0306\u0310\u0305\u0306

```

Prints `one`. Validity of this answer depends on the definition of "character" in this challenge. Python code used to generate the source.
> 1 votes

# Answer
# Stax, 5 bytes

```
äφ╓Dr

```

Run and debug it

Just unpacks to `"five"`, which is then implicitly output
> 1 votes

# Answer
## 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
> 0 votes

# Answer
## SWI-Prolog, 15 bytes

```
write(fifteen).

```

Try it online!
> 0 votes

# Answer
# 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.
> 0 votes

# Answer
# Pepe, 50 bytes

```
reeEEeeEEereeEEeEeeEreeEEeeEEereeEEEeEeereeEEEEeeE

```

Try it online!
> 0 votes

# Answer
# C# (Visual C# Interactive Compiler), 18 bytes

```
Write("eighteen ")

```

Try it online!
> 0 votes

# Answer
# rusty\_deque, 12 bytes

```
"twelve"~ol~

```
> 0 votes

# Answer
# Vyxal, 3 bytes

```
3∆ċ

```

Try it Online!

Simply push the number 3 and convert it to words.
> 0 votes

# Answer
# FerNANDo, 80 bytes

```
1 1
01
10 01
0 1 1 0 01 10 0 10
0 1 1 01 10 01 0 10
0 1 1 01 01 10 10 1
01 01
01

```

Try it online!

Loops twice, printing "eig" on the first loop and "hty" on the second. Coincidentally, using the two-character names `01` and `10` increased the code to exactly the right length.
> 0 votes

# Answer
# \>\<\> (Fish), 9 bytes

```
"enin">o<

```

Try it

Finishes with an error.

## \>\<\> (Fish), 10 bytes

```
"net"ooo ;

```

Try it
> 0 votes

# Answer
# Code Beautify Number to Word Converter, 1 Byte

If you input this:

```
1

```

You get `one`.
> 0 votes

# Answer
# Thunno 2, 3 bytes

```
‘ċŀ

```

Attempt This Online!

Compressed string literal.
> 0 votes

# Answer
# StackCell, 10 bytes

`"net":[;:]`

Explanation:

* `"net"`: Push the letters 'n', 'e', and 't' to the stack
* `:`: Duplicate the top element of the stack ('t')
* `[`: Consume the top element of the stack, and if zero jump to the next `]` in the source
* `;`: Consume and print the top element of the stack ('t' on the first iteration, then 'e', then 'n')
* `:`: Duplicate the top element of the stack ('e' on the first iteration, 'n' on the second iteration, and 0 on the third iteration)
* `]`: Consume the top element of the stack, and if non-zero jump to the previous `[` in the source
> 0 votes

---
Tags: code-golf, self-referential
---


title: Unique half rainbows

text:
# Question
Title: Unique half rainbows
If we take a positive integer \\$n\\$ and write out its factors. Someone can determine \\$n\\$ just from this list alone. In fact it is trivial to do this since the number is its own largest factor.

However if we take \\$n\\$ and write only the first half of its factors (factors that are smaller than or equal to \\$\sqrt{n}\\$), it becomes a lot more difficult to tell the original number from the list alone. In fact, it frequently becomes impossible to tell at all. For example both \\$28\\$ and \\$16\\$ give

\\$ \begin{array}{ccc} 1 & 2 & 4 \end{array} \\$

as the first half of their factors (along with an infinite number of other solutions). So if you show this list to someone they cannot know for sure what your original number was.

But some special cases do have a single unique solution. For example

\\$ \begin{array}{ccc} 1 & 2 & 3 & 5 \end{array} \\$

is unique to \\$30\\$. No other number has these as its smaller factors.

---

The goal of this challenge is to write a program or function which takes as input an integer \\$n\\$ and determines if the first half of its factors are unique or not.

Your output should be one of two consistent values, one corresponding to inputs that are unique and one to inputs that are not.

This is so answers will be scored in bytes with fewer bytes being the goal.

---

## Test cases

The first 120 truthy values are:

```
24 30 40 50 56 60 70 80 84 90 98 100 105 108 112 120 126 132 135 140 150 154 162 165 168 176 180 182 189 192 195 196 198 208 210 220 231 234 240 242 252 260 264 270 273 280 286 288 294 297 300 306 308 312 315 320 324 330 336 338 340 351 352 357 360 363 364 374 378 380 384 385 390 396 399 408 416 418 420 429 432 440 442 448 450 455 456 459 462 468 476 480 484 494 495 504 507 510 513 520 528 532 540 544 546 552 560 561 570 572 576 578 585 588 594 595 598 600 608 612

```

If you want more test cases I've written a reasonably fast generator (generates the first 500 in under 3 seconds on TIO).

Try it online!

For falsy values I recommend you check everything under 50 not on this list, but in particular 12.

# Answer
# Charcoal, 31 bytes

```
Ｎθ≔ＥＸ⊕θ²Φ⊕ι∧λ¬∨›Ｘλ²ι﹪ιλη⁼¹№η§ηθ

```

Try it online! Link is to verbose version of code. Inefficiently outputs a Charcoal boolean, i.e. `-` for unique, nothing if not. Explanation:

```
Ｎθ

```

Input `n`.

```
≔ＥＸ⊕θ²Φ⊕ι∧λ¬∨›Ｘλ²ι﹪ιλη

```

For all integers up to `(n+1)²`, list those factors that do not exceed its square root.

```
⁼¹№η§ηθ

```

See whether the `n`th list is unique.

Edit: Switching from `(2n)²` to `(n+1)²` made the code an order of magnitude faster without generating false positives. At a cost of 3 bytes, `2+⁴√n⁵` would be even faster; this works because the worst case scenario is of the form `p₁²p₂` where `p₁<p₂<p₁²`; the next integer with the same half rainbow is `p₁p₂²`, and since `p₂<p₁²` we have `p₂³<p₁⁶` and therefore `(p₁p₂²)⁴<(p₁²p₂)⁵`.
> 4 votes

# Answer
# , 40 bytes

```
1=1#.]-:&(([#~0=|)~i.#~%:>:i.)"+[:i.1+*:

```

Try it online!

Here are all test cases, with squaring replaced by `5*x` so it finishes on TIO:

Try it online!
> 4 votes

# Answer
# Haskell, 68 bytes

```
f n=[x|x<-[1..n],x*x<=n,n`mod`x<1]
g n=[1|x<-[2..n*n],f n==f x]==[1]

```

Try it online!

* thanks to @ovs for fixing an error at no cost!

all test cases with 5n instead of n squared to finish on Tio ( @Jonah trick )
> 3 votes

# Answer
# Python 3, <sup>~~103~~</sup> 97 bytes

Saved 6 bytes ~~stealing~~ "borrowing" good golf ideas from ovs's answer!!!

```
lambda n,d=lambda x:[a for a in range(x)if x>=a*a>1>x%a]:all(d(n)!=d(a)for a in range(n*n)if a-n)

```

Try it online!
> 2 votes

# Answer
# Wolfram Language (Mathematica), 80 bytes

```
(l=#;Tr[1^(S=Select)[Range[l^2+1],d@#==d@l&]]<2)&
d@n_:=S[Divisors@n,#<=Sqrt@n&]

```

Try it online!
> 2 votes

# Answer
# Python 3.8, 85 bytes

Based on Noodle9's answer.

The `1<<n` is only necessary for `n=1`, otherwise `n*n` would be shorter and a lot more efficient.

```
lambda n:2>(w:=[[a for a in range(x)if x>=a*a>1>x%a]for x in range(1<<n)]).count(w[n])

```

Try it online! or Try it with `n*n`!
> 2 votes

# Answer
# JavaScript (Node.js), 80 bytes

```
n=>(q=t=>t&&q(t-1)+(g(t)==g(n)))(n*n+9)<2
g=n=>(h=i=>i*i>n||h(~-i)+[n%i?'':i])()

```

Try it online!

Can replace `n*n+9` to `2**n` in theory but not practical. `i` in `h` is negative so concatting lead to something like `true-3-2-1` for 12
> 2 votes

# Answer
# Excel, 127 bytes

```
=LET(L,2+A1^1.3,x,SEQUENCE(L),y,SEQUENCE(L^0.5),u,TRANSPOSE(y),z,MMULT((MOD(x,u)=0)*(u<=SQRT(x)),2^y),SUM((INDEX(z,A1)=z)*1)=1)

```

modified Neil's upper bound to use n^1.3 instead of 1.25 to save a byte. n^2 would use too much memory with this solution.
> 1 votes

# Answer
# Jelly, 13 bytes

```
²‘½ḍƇ$€ċⱮ`⁸ịỊ

```

A monadic Link accepting a positive integer, \\$n\\$, that yields `1` if \\$n\\$ is a unique half rainbow or `0` if not.

**Try it online!** Or see those up to 60

### How?

```
²‘½ḍƇ$€ċⱮ`⁸ịỊ - Link: integer, n
²             - square (n)
 ‘            - increment
     $€       - for each i in [1..n²+1]:
  ½           -   square root (i)
    Ƈ         -   filter [1..⌊√i⌋] keeping those which:
   ḍ          -     divide (i)
        Ɱ`    - map across itself with:
       ċ      -   count occurrences
          ⁸ị  - get entry at index n
            Ị - is insignificant (effectively = 1?)

```
> 1 votes

# Answer
# Vyxal `MAB`, ~~17~~ 13 bytes

```
²›ƛ₌K√ɾ↔;~iOṅ

```

-4 thanks to @lyxal!
Try it Online!
> 1 votes

# Answer
# Scala, 97 bytes

Golfed version. Try it online!

```
def f(n:Int)=(1 to n).filter(x=>x*x<=n&&n%x==0)
def g(n:Int)={(2 to n*n).count(x=>f(n)==f(x))==1}

```
> 1 votes

# Answer
# , ~~104 88 83 78~~ 74 bytes

```
m=scan();n=1:m^.5;for(i in 2:m^2)F=F+all(n[!m%%n]==(a<-1:i^.5)[!i%%a]);F<2

```

Try it online!

following Neil's solution checking for all integers till n².
> 0 votes

---
Tags: code-golf, math, number, decision-problem
---


title: Detect sonar imposters

text:
# Question
Title: Detect sonar imposters
You are the sonar captain aboard an underwater submarine. The way sonar works is that every submarine sends out a ping at regular intervals. Each interval is a whole number of seconds. Each submarine has an identifying amplitude, that is no two submarines send out pings at the same amplitude. The amplitude is always a positive integer, so when two submarines send out pings at the same time, they constructively interfere and it appears on your ship's readout as a single ping at the sum of the amplitudes.

However, there are imposters in the deep sea. An imposter will send out pings at a different submarine's amplitude to imitate them. That means that when there's an imposter in the midst there will be two submarines pinging at the same amplitude.

If you see the following readout over a 10 second interval

```
0,1,1,0,1,1,0,1,1,0

```

Then you know there must be an imposter. The `1` pings don't occur at regular intervals. However if you see the following:

```
0,3,3,0,3,3,0,3,3,0

```

You can't be certain there's an imposter. There might be an imposter imitating the `3` submarine:

```
0,3,0,0,3,0,0,3,0,0
0,0,3,0,0,3,0,0,3,0

```

Or there might be 3 submarines with two of them interfering:

```
0,1,0,0,1,0,0,1,0,0
0,2,0,0,2,0,0,2,0,0
0,0,3,0,0,3,0,0,3,0

```

Now the interference can make things pretty complicated. Can you tell quickly whether there's an imposter in the following readout:

```
5,7,5,3,9,4,5,7

```

It's possible, but it's also possible there's no imposter:

```
0,4,0,0,4,0,0,4
3,3,3,3,3,3,3,3
0,0,0,0,0,1,0,0
2,0,2,0,2,0,2,0

```

So you'd like to write a computer program which takes a readout and tells you quickly, without having to do any working by hand, whether there is definitely an imposter.

## Task

Given a readout of your submarine's sonar as a list of non-negative integers, output a value if there is definitely an imposter, and output a different distinct value otherwise.

Your submarine is under a lot of pressure so your code should be pressurized as well. This is the goal is to minimize the size of your source code as measured in bytes.

## Test cases

### Imposter

```
[0,1,1,0,1,1,0,1,1,0]
[0,1,1]
[1,1,2]
[9,2,8,7,3,6,1,1]
[9,10,7,3,8,8,2,2]
[2,9,2,6,1]

```

### Maybe imposter

```
[9]
[9,9]
[9,9,9]
[9,9,9,9]
[0,3,3]
[3,1,1]
[1,2,3,4,5,6,7,8]
[9,9,9,9,9,9,9,9,1]
[5,7,5,3,9,4,5,7]

```

# Answer
> 8 votes
# Python, ~~180~~ ~~173~~ ~~169~~ 166 bytes

*-7 bytes thanks to @gsitcia*
*-3 bytes thanks to @naffetS*

```
lambda a,r=range:(l:=len(a))!=a in[[*map(sum,zip(*s))]for s in product(*[[((*i//l*[0],-~p)*l)[i%l:i%l+l]for i in r(l*l+1)]for p in r(max(a))])]
from itertools import*

```

Attempt This Online!

*Very* inefficient for inputs with larger maximum values.

Brute force solution -- goes through every set of submarines which does not contain an imposter and checks if any of them produce the given input.

# Answer
> 7 votes
# JavaScript (ES10), 198 bytes

Returns *true* for *imposter* or *false* for *maybe imposter*.

Looks like this code could be pressurized some more...

```
f=([v,...a],c=[],F=(n,l=[],i=1)=>n?i>n||F(n-i,[i,...l],++i)&&F(n,l,i):f(a,[...c,l]))=>v+1?F(v):c.flat().some(v=>(m=(s=c.map(l=>l.includes(v)|!++a).join``).match(/(10*)1/))&&!m[1].repeat(a).match(s))

```

Try it online!

# Answer
> 4 votes
# Python3, 677 bytes:

```
lambda b:next(C(b),0)!=0
R,T,U,M=range,sorted,lambda x:''.join(map(str,x)).lstrip('0'),lambda r,k:any(all(j==K for j,K in zip(U(i),U(k)))for i in r)
def C(b):
 q,S=[([],0)],[]
 while q:
  r,c=q.pop(0);L=len(b)
  if all(a==sum(j)for a,j in zip(b,zip(*r)))and r:yield r
  if c==L:continue
  if not b[c]:q+=(r,c+1),;continue
  for i in{*R(1,b[c]+1)}-{j for k in r for j in k}:
   for g in R(1,L+1):
    k=[0]*L;k[c]=i;I=1
    while I*g+c<L or-I*g+c>=0:
     if-I*g+c>=0:k[-I*g+c]=i
     if I*g+c<L:k[I*g+c]=i
     I+=1
    if all(a>=sum(j)for a,j in zip(b,zip(*r+[k])))and not M(r,k)and T(r+[k])not in S:
     q+=(K:=r+[k],c+1),;S+=T(K),
     if b[c]>sum(j[c]for j in K):q+=(K,c),

```

Try it online!

# Answer
> 3 votes
# Python, ~~157~~ 155 bytes

*-2 bytes thanks to @97.100.97.109*

```
f=lambda p,n=1:all(x>=0for x in p)and(sum(p)<1or n<=max(p)and any(f([p-n*(i%h==o)for i,p in enumerate(p)],n+1)for h in range(1,len(p)+2)for o in range(h)))

```

Attempt This Online!

# Answer
> 1 votes
# Desmos, 220 bytes

```
m=l.max
g(N,K,b)=mod(floor(bN/b^{[1...K]}),b)
A=[1...m][g(a,m,2)=1]
L=l.length
B=A.length
P=g(p,B,L)+1
M=P.max
f(l)=0^{∑_{a=1}^{2^m}∑_{p=0}^{L^B}∑_{d=0}^{M^B}0^{∑_{i=1}^L(total(0^{mod(i-g(d,B,M)-1,P)}A)-l[i])^2}}

```

Guys please tell me if there is anything wrong... I have spent a while planning out this answer (I literally wrote out all my steps on a txt file before doing any of the desmos coding lol) but I may have missed some crucial details.

Because of the very inefficient brute force methods used in this answer, it can only handle the smallest of test cases, so I went ahead to make some of my own. I did test those new test cases against other answers here to compare and they seem to match, so this gives me a little more confidence that this answer should mostly be correct. The test cases given in the question that the code could run in a reasonable amount of time also do match as well.

As an aside, it actually did not come out as long as I expected; I was expecting at least 300 bytes when I initially started planning this out.

Try It On Desmos!

Try It On Desmos! - Prettified

# Answer
> 1 votes
# Scala, 202 bytes.

Golfed version. Try it online!

```
def f(p:List[Int],n:Int=1):Boolean=p.forall(_>=0)&&(p.sum<1||(n<=p.max&&{for(h<-1 to p.length+1;o<-0 until h)yield f(p.zipWithIndex.map{case(p,i)=>p-n*((i%h==o).compare(false))},n+1)}.exists(identity)))

```

Ungolfed version. Try it online!

```
object Main {
  def f(p: List[Int], n: Int = 1): Boolean = {
    def helper(p: List[Int], h: Int, o: Int, n: Int): Boolean = {
      val updatedP = p.zipWithIndex.map { case (p, i) => p - n * (if((i % h == o))1 else 0) }
      f(updatedP, n + 1)
    }
    p.forall(_ >= 0) && (p.sum < 1 || (n <= p.max && (for (h <- 1 to p.length + 1; o <- 0 until h) yield helper(p, h, o, n)).exists(identity)))
  }

  def main(args: Array[String]): Unit = {
    val tests = List(
      List(0, 1, 1, 0, 1, 1, 0, 1, 1, 0),
      List(0, 1, 1),
      List(1, 1, 2),
      List(2, 9, 2, 6, 1),
      List(),
      List(9),
      List(9, 9),
      List(9, 9, 9),
      List(9, 9, 9, 9),
      List(0, 3, 3),
      List(3, 1, 1)
    )

    for (x <- tests) {
      if (x.isEmpty)
        println()
      else
        println(f(x))
    }
  }
}

```

---
Tags: code-golf, decision-problem
---


# Question
Title: Is this string a palindrome (in Morse Code)?
# Challenge

Inspired by this video.

As you may know, a palindrome is a word that is spelled the same forward as it is backward. The word "PULP" is not a palindrome, but when translated into Morse Code (with the spacing between letters removed), "PULP" becomes ".--...-.-...--." which is a palindrome. Your task is to write a program or function which takes a string and returns whether that word is a palindrome in International Morse Code.

```
A: .-
B: -...
C: -.-.
D: -..
E: .
F: ..-.
G: --.
H: ....
I: ..
J: .---
K: -.-
L: .-..
M: --
N: -.
O: ---
P: .--.
Q: --.-
R: .-.
S: ...
T: -
U: ..-
V: ...-
W: .--
X: -..-
Y: -.--
Z: --..

```

# Rules

## Input

Input can be taken in any reasonable format. The input string will contain only letters in any case you prefer. The string will not contain spaces, numbers, or punctuation.

## Output

Your program should output 1 of 2 constant distinct results based on whether the input is a palindrome, e.g. True/False, 1/0, HOTDOG/NOTHOTDOG

## Scoring

This is so shortest answer in bytes wins. Standard loopholes are forbidden.

# Test Cases

| Input | Output |
| --- | --- |
| "PULP" | True |
| "RESEARCHER" | True |
| "HOTDOGS" | True |
| "" | True |
| "A" | False |
| "RACECAR" | False |
| "PROGRAMMING" | False |
| "PUZZLES" | False |

# Answer
# Jelly, 28 bytes

```
ØAŻŻ“¡9o|çṫ¡X1ỴỌġQ’œ?iⱮḃ2FŒḂ

```

Try it online!

```
ØA                             The uppercase alphabet.
  ŻŻ                           Prepend two zeroes.
    “¡9o|çṫ¡X1ỴỌġQ’œ?          Get the 73540211105102870315464559332nd permutation.
                                  (= “ETIANMSURWDKGOHVF0L0PJBXCYZQ”)
                     iⱮ        Find indices of input letters in this list.
                       ḃ2      Bijective base 2: map [1,2,3,4,5…] to
                                 [1], [2], [1,1], [1,2], [2,1], …
                         F     Flatten.
                          ŒḂ   Is palindrome?

```

I wrote this answer looking at one of these (read the rows from right-to-left, and you get my magic string!):
> 9 votes

# Answer
# Jelly,  ~~35 32 27~~  25 bytes

-2 thanks to Dennis (shift the permutation to avoid `%32`)

```
Oị“¡\ḣḶɼz3ç³ƝMƒ§’Œ?¤ḃ2FŒḂ

```

Takes input in upper-case; output is `1` for true, `0` for false.

**Try it online!** Or see the test-suite.

### How?

```
Oị“...’Œ?¤ḃ2FŒḂ - Link: list of characters (in [A-Za-z]), S   e.g. 'FoOl'
O               - to ordinals                                      [70,111,79,108]
 %32            - modulo by 32 (A->1, a->1, ...)                   [6,15,15,12]
         ¤      - nilad followed by link(s) as a nilad:
  “...’         -   base 250 literal = 41482574787853596522350494865
       Œ?       -   first permutation of [1,N] which resides at that
                -   index when all permutations of [1,N] are sorted
                -   = [8,16,10,24,26,27,18,20,4,23,25,11,1,17,13,15,3,22,12,19,6,5,14,21,28,9,7,2]
                - index into (modular-indexing & vectorises)       [17,14,14,19]
          ḃ2    - to bijective base 2 (vectorises)                 [[1,1,2,1],[2,2,2],[2,2,2],[1,2,1,1]]
            F   - flatten                                          [1,1,0,1,0,0,0,0,0,0,1,0,1,1]
             ŒḂ - is palindromic?                                  1

```

---

Previous 35 byte solution (also takes input in upper-case)...

```
ØẠḣ29“...’œ?iⱮ⁸d⁴BnⱮ/€FŒḂ - Link: list of characters (in [A-Z] only), S
ØẠ                        - alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  ḣ29                     - head to index 29 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabc'
     “...’                - base 250 literal = 1222276956185766767980461920692
          œ?              - permutation at index = 'EAIWRUSJPaLbFVHcTNMDKGOBXCYZQ'
              ⁸           - chain's left argument = S       e.g. 'FOOL'
             Ɱ            - map with:
            i             -   first index of (char in 'EAI...')  [13,23,23,11]
                ⁴         - literal 16                           16
               d          - divmod                               [[0,13],[1,7],[1,7],[0,11]]
                 B        - to binary (vectorises)               [[[0],[1,1,0,1]],[[1],[1,1,1]],[[1],[1,1,1]],[[0],[1,0,1,1]]]
                     €    - for each:
                    /     -   reduce by:
                   Ɱ      -     map with:
                  n       -       not equal                      [[1,1,0,1],[0,0,0],[0,0,0],[1,0,1,1]]
                      F   - flatten                              [1,1,0,1,0,0,0,0,0,0,1,0,1,1]
                       ŒḂ - is palindromic?                      1

```
> 7 votes

# Answer
# Python 3, ~~172~~ ~~148~~ 104 bytes

*First code golf ever. Please be kind and offer any help :)*

This is based off the C# answer: https://codegolf.stackexchange.com/a/175126/83877. I took the same ideas and applied it to Python 3. I tried my best to golf-ify the code, but I am sure there is a lot more I can do.

EDIT 1: Thanks @Stephen and @Cowabunghole for helping me remove some whitespace and unnecessary code.

EDIT 2: Thanks @JoKing for the suggestion to do it in binary. This is a really neat trick where '-' and '.' are not even necessary. This led to a huge byte decrease.

## Solution

```
def b(w):x=''.join(map(lambda c:bin('  ETIANMSURWDKGOHVF L PJBXCYZQ'.index(c))[3:],w));return x==x[::-1]

```

Try it online!
> 4 votes

# Answer
# Dyalog APL, 24 bytes

```
⎕CY'dfns'
⎕←(⌽≡⊢)∊morse⍞

```

Try it online!

`dfns` never ceases to amaze
> 3 votes

# Answer
# MBASIC, 325 bytes

*First attempt, before the big guns get here* :-)

```
1 DATA .-,-...,-.-.,-..,.,..-.,--.,....,..,.---,-.-,.-..,--,-.,---,.--.,--.-,.-.,...,-,..-,...-,.--,-..-,-.--,--..
2 DIM C$(26):FOR I=1 TO 26:READ C$(I):NEXT:INPUT T$:FOR I=1 TO LEN(T$):N=ASC(MID$(T$,I,1))-64:S$=S$+C$(N):NEXT:L=LEN(S$):FOR I=1 TO L:IF MID$(S$,I,1)<>MID$(S$,(L+1)-I,1) THEN 4
3 NEXT:PRINT"True":END
4 PRINT"False

```

Output

```
? PULP
True

? RESEARCHER
True

? HOTDOGS
True

?
True

? A
False

? RACECAR
False

? PROGRAMMING
False

? PUZZLES
False

```
> 2 votes

# Answer
# JavaScript (Node.js), 111 bytes

```
x=>(u=[...x.replace(/./g,_=>"**ETIANMSURWDKGOHVF*L*PJBXCYZQ".indexOf(_).toString(2).slice(1))])+''==u.reverse()

```

Try it online!
> 2 votes

# Answer
# Perl 6, 87 bytes

```
{$_ eq.flip}o*.trans(/./=>{S/.//}o{'  ETIANMSURWDKGOHVF L PJBXCYZQ'.index($/).base(2)})

```

Try it online!

Converts the word to a series of 1s and 0s and checks if it is palindromic.

### Explanation:

```
             *.trans(/./=>  # Translate each letter of the input to
                                   '...'.index($/)   # The index of the letter in the lookup string
                                                  .base(2)  # Converted to binary
                          {S/.//}o{                       } # With the first digit removed
{$_ eq.flip}o   # Return if the string is equal to its reverse

```
> 2 votes

# Answer
# Pyth, ~~35~~ 33 bytes

The code contains unprintable characters, so here's a hexdump.

```
00000000: 5f49 7358 7a47 632e 2207 0901 3f08 82ee  _IsXzGc."...?...
00000010: bd3f c256 9d54 c381 7dac 6590 37d3 c8f5  .?.V.T..}.e.7...
00000020: 52                                       R

```

Try it online. Test suite.

### Explanation

Starting from `."` the end of the code generates the Morse alphabet, with dots as `\x08` and dashes as `\x07`, and separated by tabs.

`c` splits the string by the tabs.

`XzG` translates (`X`) the input (`z`) from the alphabet (`G`) to this "Morse alphabet".

`s` sums (joins) the Morse symbols together. For empty inputs, returns 0, but this is not a problem.

`_I` checks if the result does not change (`I`) when reversed (`_`). For empty input, checks if 0 does not change when negated.
> 1 votes

# Answer
# Wolfram Language (Mathematica), 107 bytes

```
PalindromeQ[##2&@@@(IntegerDigits[Tr@StringPosition[" ETIANMSURWDKGOHVF L PJBXCYZQ",#],2]&/@Characters@#)]&

```

Try it online!

Similar to this Jelly answer: we think of Morse code as binary, and write down a string `" ETIANMSURWDKGOHVF L PJBXCYZQ"` where the position of a character, in binary, gives us its Morse code. But with an extra 1 prepended because we want to distinguish `S = 000` and `H = 0000`, for instance. Then `##2&@@@` simultaneously gets rid of this leading 1 and flattens.
> 1 votes

# Answer
# PowerShell, ~~204~~ 187 bytes

```
param($a);$a|% t*y|%{$b+=[convert]::ToString("  ETIANMSURWDKGOHVF L PJBXCYZQ".IndexOf($_),2).substring(1)};$c=($b=($b|% *ce 0 .|% *ce 1 -)).ToCharArray();[array]::Reverse($c);$b-eq-join$c

```

Try it online!

**Errors on null string... Can anyone help with this?**

Test code (After wrapping the code in a Script Block and assigned to variable $Z...):

```
$tests = @(
    "PULP", "True"
    "RESEARCHER", "True"
    "HOTDOGS", "True"
    "A", "False"
    "RACECAR", "False"
    "PROGRAMMING", "False"
    "PUZZLES", "False"
)
$outputs = @()
for($i = 0; $i -lt $tests.length/2; $i++){
    $output = New-Object "PSObject"
    $output  | Add-Member -MemberType NoteProperty -Name Name -Value "`"$($tests[2*$i])`""
    $output | Add-Member -MemberType NoteProperty -Name Expected -Value $tests[2*$i + 1]
    $output | Add-Member -MemberType NoteProperty -Name Result -Value $(&$Z -a $tests[2*$i])
    $outputs += $output
}
$outputs | Format-Table

```

Output:

```
Name          Expected Result
----          -------- ------
"PULP"        True       True
"RESEARCHER"  True       True
"HOTDOGS"     True       True
"A"           False     False
"RACECAR"     False     False
"PROGRAMMING" False     False
"PUZZLES"     False     False

```
> 1 votes

# Answer
# Retina 0.8.2, 87 bytes

```
[B-ILNPRSZ]
$&.
[AJKMOQT-Y]
$&-
}T`L`\EDKN_UMS\EWNRTTMWGAI_ISADKG
+`^(.)(.*)\1$
$2
^.?$

```

Try it online! Link includes test cases. Explanation:

```
[B-ILNPRSZ]
$&.

```

All the Morse codes for the letters in this set end with `.`.

```
[AJKMOQT-Y]
$&-

```

All the Morse codes for the letters in this set end with `-`.

```
T`L`\EDKN_UMS\EWNRTTMWGAI_ISADKG

```

Replace each letter with the letter whose Morse code is the prefix of that letter (here `E` and `T` are simply deleted via the unescaped `_`, but normally they would be turned into spaces). For instance, `P` is the Morse code for `W` with an extra `.` on the end; we added the `.` above so now all that remains is to decode the `W`.

```
}

```

Repeat the above stages until there are no letters left.

```
^(.)(.*)\1$
$2

```

If the first and last characters are the same, delete them both.

```
+`

```

Repeat for as many characters that match.

```
^.?$

```

If this was a palindrome, then there is at most one character left.
> 0 votes

# Answer
# 05AB1E, 37 bytes

```
v•1êÿµµÈ∞Ƶipδ8?a¡š%=тîδ/•3B0¡Aykè}JÂQ

```

Try it online!

---

Encodes the alphabet in base 3, converted to base 255:

```
12021110212102110101121022101111011012220212012110220210222012210221201210111020112011120122021120212202211

```

Base 255:

```
•1êÿµµÈ∞Ƶipδ8?a¡š%=тîδ/•

```

Then basically, I break it apart on the 0's, construct the string by position and check for palindrome.
> 0 votes

# Answer
# C# (.NET Core), 191 bytes

```
a=>{var s="";int r=1,x=0,i;foreach(var t in a){var c="";for(i=" ETIANMSURWDKGOHVF L PJBXCYZQ".IndexOf(t);i>0;i/=2)c="-."[i--%2]+c;s+=c;}i=s.Length;for(;x<i;x++)r=s[x]==s[i-x-1]?r:0;return r;}

```

Try it online!

Part of this answer was adapted from Nick Larsen's morse code golf. Based on the comments on the answer, this could potentially be golfed further.

Ungolfed:

```
a => {
    var s = "";                 // initialize s
    int r = 1, x = 0, i;        // initialize r, x, and i

    /*
        This portion was adapted from Nick Larsen. He described it as follows:
            -- The string of characters is a heap in which the left child is a dot and the right child is a dash.
            -- To build the letter, you traverse back up and reverse the order.
        I have edited it to remove number support, which saves 34 bytes.
    */
    foreach(var t in a)
    {
        var c = "";
        for(i = " ETIANMSURWDKGOHVF L PJBXCYZQ".IndexOf(t); i > 0; i /= 2)
            c = "-."[i-- % 2] + c;
        s += c;
    }

    i = s.Length;               // reuse i and set to the length of the morse code string
    for(; x < i; x++)           // increment x until x reaches i
        r = s[x] == s[i - x - 1] ?      // if the xth character on the left side of s is equal to the xth character on the right side of s
                                    r :     // true: do not change r
                                        0;  // false: set r to zero (set to false)

    return r;
}

```
> 0 votes

# Answer
# Scala 3, 121 bytes.

Golfed version. Try it online!

```
_.map(c=>Integer.toBinaryString("  ETIANMSURWDKGOHVF L PJBXCYZQ".indexOf(c)).substring(1)).mkString.pipe(x=>x==x.reverse)

```

Ungolfed version. Try it online!

```
object Main {
  def b(w: String): Boolean = {
    val x = w.map(c => Integer.toBinaryString("  ETIANMSURWDKGOHVF L PJBXCYZQ".indexOf(c)).substring(1)).mkString
    x == x.reverse
  }

  def main(args: Array[String]): Unit = {
    println(b("PULP"))
    println(b("RESEARCHER"))
    println(b("HOTDOGS"))
    println(b(""))
    println(b("A"))
    println(b("RACECAR"))
    println(b("PROGRAMMING"))
    println(b("PUZZLES"))
  }
}

```
> 0 votes

# Answer
# GNU sed -E, 139 bytes

```
:r
s/[AFHIJLPRSUVW]/E&/g
s/[BCDGKMNOXYZ]/T&/g
y/ABCDFGHIJKLMNOPQRSUVWXYZ/TSRIRNSEOADTEMGKNIAUMUWD/
tr
:p
s/^(.)(.*)\1$/\2/
tp
/../c0
/0/!c1

```

This program transforms each line of input (must be upper-case) to either `1` (for a Morse palindrome) or `0` (otherwise).

The first loop (`r`=reduce) converts to Morse, represented using `T` for dash and `E` for dot (so we don't need to convert those two letters).

The second loop (`p`=palindrome) removes matching start and end characters.

If there are two or more symbols remaining, it's not a palindrome, so output `0`.

If we didn't produce `0`, then the result should be `1`.

---

I did attempt to convert to an easier alphabet to work with (so we could use character ranges in the `s` command), but none saved enough to outweigh the conversion cost.
> 0 votes

---
Tags: code-golf, decision-problem, palindrome, morse
---


title: Basic Calculator

text:
# Question
Title: Basic Calculator
You must write a program to evaluate a string that would be entered into a calculator.

The program must accept input and output the correct answer. For languages that do not have standard input/output functions, you may assume the functions `readLine` and `print`.

**Requirements**

* Does not use any kind of "eval" functions
* Can handle floating point and negative numbers
* Supports at least the +, -, \*, and / operators
* Can handle input containing one **or more** spaces between the operators and numbers
* Evaluates the expression from left to right

The program that is the shortest wins. In the event of a tie, the program that was submitted first wins.

**You can assume that the input is valid and follows the correct format**

## Test Cases

Input

```
-4 + 5

```

Output

```
1

```

---

Input
```
-7.5 / 2.5

```

Output

```
-3

```

---

Input
```
-2 + 6 / 2 * 8 - 1 / 2.5 - 18

```

Output

```
-12

```

# Answer
# Ruby - ~~74~~ ~~69~~ ~~67~~ 65 characters

```
a=0
("+ "+$<.read).split.each_slice 2{|b,c|a=a.send b,c.to_f}
p a

```
> 8 votes

# Answer
## Befunge - 37 x 5 = 185 38 x 3 = 114 characters

This is limited to integer numbers as Befunge has no floating point support.

```
&v      /& _ #`&# "-"$# -#<          v
 >~:0`!#v_:" "`! #v_:","`#^_"*"`#v_&*>
 ^      ># $ .# @#<              >&+

```

### Explanation

The biggest distinguishing feature of Befunge is that instead of being a linear set of instructions like most languages; it is a 2d grid of single character instructions, where control can flow in any direction.

The first `&` simply inputs the first number. The `v` and `>` then redirect control to the main path on the second row.

```
~:0`!#v_

```

This inputs a character (`~`), duplicates it (`:`), pushes zero onto the stack (`0`), pops the top two elements and determines if the second is greater than the first (``` *I'm surprised you can't use \`\`\` to get code backticks.*), inverts the truthiness of the top element (`!`), then goes right if it is zero, down otherwise (`#v_`).

Basically it's checking whether the input is `-1` representing no more input.

```
># $ .# @

```

If the input was `-1` then the duplicated input value is discarded (`$`), the top of the stack is output as an integer (`.`) and the program is halted (`@`).

```
:" "`! #v_

```

Otherwise a similar process is repeated to determine if the input is less than or equal to a space. If it is a space then control goes down, otherwise control heads right.

```
^      ># $ .# @#<

```

If it is a space then it's redirected left (`<`); the program halt (`@`), output (`.`) and right redirection (`>`) are all skipped using `#`; but the discard is executed to remove the space from the stack. Finally it's redirected up to begin the next execution (`^`).

```
:","`#^_

```

If it wasn't a space the same process is used to split on if it is in `[+, *]` or in `[-, \]` going right and up respectively.

```
 >~                         "*"`#v_&*>
 ^                               >&+

```

For `[+, *]` it is again split to determine whether it is a `+` or a `*`. If `+` it is directed down then the next number is input (`&`) and they are added (`+`), the control then wraps around and is redirected up to the main path for the next character. If `*` then it inputs (`&`) and multiplies (`*`) then directly wraps around.

```
/& _ #`&# "-"$# -#<

```

For `[-, \]` it starts on the right heading left. The `#`'s skip the character after them so the initial path is `"-"`_` which simply determines if it is `-` or `/`. If it is `/` then it continues left to input (`&`) and divide (`/`). If it is `-` then it heads right, again skipping characters so that it executes `&"-"$-` resulting in the number being input (`&`) the `-` character being pushed onto the stack then discarded (`"-"$`) and then the subtraction being calculated (`-`). The control is then redirected back to the main path.
> 9 votes

# Answer
# Python 3, 105 bytes

Manages the four basic operations, but it only costs 5 characters each to add `^` or `%`.

```
f=float
x,*l=input().split()
while l:o,y,*l=l;x,y=f(x),f(y);x=[x+y,x-y,x*y,x/y]['+-*/'.find(o)]
print(x)

```

Precedence of operations is left to right.
> 6 votes

# Answer
## Python (156)

```
from operator import*
while 1:
 l=raw_input().split();f=float
 while len(l)>2:l[:3]=({'*':mul,'/':div,'+':add,'-':sub}[l[1]](f(l[0]),f(l[2])),)
 print l[0]

```
> 5 votes

# Answer
# C - ~~168~~ 126 characters

```
main(c){float a,b;scanf("%f",&a);while(scanf("%s%f",&c,&b)!=-1)c=='+'?a+=b:c=='-'?(a-=b):c=='*'?(a*=b):(a/=b);printf("%f",a);}

```
> 5 votes

# Answer
# Tcl 8.6, ~~57~~ 48 chars.

* Input from arguments:

```
lm o\ b [las $argv a] {set a [exp $a$o$b]};pu $a

```
* From Stdin (~~64~~ **53**)

```
lm o\ b [las [ge stdin] a] {set a [exp $a$o$b]};pu $a

```

**You have to use the interactive shell for both solutions.**

I treat the input as list (Tcl uses spaces as delimiter) take the first element and assign it to `a`, then I walk over the rest, taking 2 elements each time, the operator and a second number, apply the operator on `$a` and `$b` and assign the result to `a`. At the end the result is in `a`.
> 5 votes

# Answer
### C++0x 205 203 198 194 chars

```
#include<iostream>
#define P [](F l,F r){return l
int main(){typedef float F;F r,v,(*a[])(F,F)={P*r;},P+r;},0,P-r;},0,P/r;}};std::cin>>r;for(char o;std::cin>>o>>v;)r=a[o-42](r,v);std::cout<<r;}

```

Nicely formatted:

```
#include<iostream>

int main()
{
    float r,v;
    float (*a[])(float,float)   ={  [](float l,float r){return l*r;},
                                    [](float l,float r){return l+r;},
                                    0,
                                    [](float l,float r){return l-r;},
                                    0,
                                    [](float l,float r){return l/r;}
                                 };

    std::cin>>r;
    for(char o;std::cin>>o>>v;)
        r=a[o-42](r,v);

    std::cout<<r;
}

```
> 4 votes

# Answer
# Haskell: 124 114 characters

```
j[o]=o
j(u:m:b:o)=j$show((case m of{"+"->(+);"-"->(-);"*"->(*);"/"->(/)})(read u)(read b)):o
main=interact$j.words

```

A rather straight-forward answer, using pattern matching and a simple case statement for the heavy lifting. Usage:

```
> ./calc <<< "123 - 12 + -12 / 12.124 * 9.99 - 1"
80.57456285054437

```
> 4 votes

# Answer
# C: 111 108 characters

```
main(c){float a,b;for(scanf("%f ",&a);~scanf("%c%f ",&c,&b);a=c^43?c%5?c%2?a/b:a*b:a-b:a+b);printf("%f",a);}

```

It fulfills all the requirements, usage:

```
> ./calc <<< "-43 - 56 + 14.123 / -13.22"
6.420348

```
> 4 votes

# Answer
# Perl (97)

```
$b=shift;eval"\$b$r=$s"while($r=shift,$s=shift);print$b

```

read from arguments

```
$b=shift;$b=($r eq'+'?$b+$s:$r eq'-'?$b-$s:$r eq'*'?$b*$s:$b/$s)while($r=shift,$s=shift);print$b;

```

read from input

```
@_=split/ /,<>;$b=shift@_;$b=($r eq'+'?$b+$s:$r eq'-'?$b-$s:$r eq'*'?$b*$s:$b/$s)while($r=shift@_,$s=shift@_);print$b

```
> 3 votes

# Answer
**PostScript (145)**

Another PostScript entry (thanks to luser droog for digging the golfs interesting for PostScript!):

```
[/+{add}/-{sub}/*{mul}/{div}>>begin(%stdin)(r)file
999 string readline
pop{token not{exit}if
count 4 eq{3 1 roll
4 1 roll
cvx exec}if
exch}loop
=

```

Un-golfed:

```
[/+{add}/-{sub}/*{mul}/ {div}>>begin
% Read the input
(%stdin)(r)file 999 string readline pop
{                        % .. string
  token not{exit}if      % .. string token
  % If we have 4 objects on the stack, we have two operands, one operator
  % and the input string. This means, we can calculate now.
  count 4 eq{            % a op string b
    % perform operation a op b = c (where op can be +,-,*,/)
    3 1 roll             % a b op string
    4 1 roll             % string a b op
    cvx exec             % string c
  }if                    % string token (or c)
  exch                   % token string
}loop
=

```
> 3 votes

# Answer
# Python - 308

```
import sys;i=sys.argv[1].split();o=[];s=[];a=o.append;b=s.pop;c=s.append
for t in i:
 if t in"+-*/":
  if s!=[]:a(b())
  c(t)
 else:a(t)
if s!=[]:a(b())
for t in o:
 if t=="+":c(b()+b())
 elif t=="-":m=b();c(b()-m)
 elif t=="*":c(b()*b())
 elif t=="/":m=b();c(b()/m)
 else:c(float(t))
print(b())

```

Readable version:

```
# Infix expression calc

import sys

# Shunting-yard algorithm
input = sys.argv[1].split()
output = []
stack = []

for tkn in input:
    if tkn in "+-*/":
        while stack != []:
            output.append(stack.pop())
        stack.append(tkn)
    else:
        output.append(tkn)

while stack != []:
    output.append(stack.pop())

# Eval postfix notation
for tkn in output:
    if tkn == "+":
        stack.append(stack.pop() + stack.pop())
    elif tkn == "-":
        tmp = stack.pop()
        stack.append(stack.pop() - tmp)
    elif tkn == "*":
        stack.append(stack.pop() * stack.pop())
    elif tkn == "/":
        tmp = stack.pop()
        stack.append(stack.pop()/tmp)
    else:
        stack.append(float(tkn))

print(stack.pop())

```

Takes expression as command-line argument, output on standard output.
> 3 votes

# Answer
## C# ~~(234)~~ ~~(231)~~ ~~(229)~~ ~~(223)~~ (214)

```
class A{void Main(string[]s){var n=1;var o="";var r=0F;foreach(var t in s){if(n>0){var v=float.Parse(t);if(o=="")r=v;if(o=="+")r+=v;if(o=="-")r-=v;if(o=="*")r*=v;if(o=="/")r/=v;}o=t;n=-n;}System.Console.Write(r);}}

```

---

```
class A{
    void Main(string[] s)
    {
      var n = 1;
      var o = "";
      var r = 0F;

      foreach (var t in s)
      {
        if (n > 0)
        {
          var v = float.Parse(t);
          if (o == "") r = v;
          if (o == "+") r += v;
          if (o == "-") r -= v;
          if (o == "*") r *= v;
          if (o == "/") r /= v;
        }
        o = t;
        n = -n;
      }
      System.Console.Write(r);
    }
}

```
> 2 votes

# Answer
**Postscript (340)**

```
/D<</+{add}/-{sub}/*{mul}/ {div}>>def/eval{/P null def{token not{exit}if exch/rem exch def
dup D exch known{/P load null ne{D/P load get exch/P exch def exec}{/P exch def}ifelse}if
rem}loop/P load null ne{D/P load get exec}if}def {(> )print flush{(%lineedit)(r)file
dup bytesavailable string readline pop eval == flush}stopped{quit}if}loop

```

And a little more readable:

```
%!
/oper<</+{add}/-{sub}/*{mul}/ {div}>>def

/eval{
    /op null def
    {
        token not {exit} if
        exch /rem exch def
        dup oper exch known {
            /op load null ne {
                oper /op load get
                exch /op exch def
                exec
            }{
                /op exch def
            } ifelse
        } if
        rem
    } loop
    /op load null ne { oper /op load get exec } if
} def

{
    (> )print flush
    {
    (%lineedit)(r)file
    dup bytesavailable string readline pop
    eval == flush
    } stopped { quit } if
} loop

```
> 2 votes

# Answer
## JavaScript (208 characters compacted)

For clarity, this is the code *before* I compacted it down (JS-Fiddle of it):

```
function math(match, leftDigit, operator, rightDigit, offset, string) {
    var L = parseFloat(leftDigit)
    var R = parseFloat(rightDigit)
    switch (operator)
    {
        case '*': return L*R;
        case '/': return L/R;
        case '+': return L+R;
        case '-': return L-R;
    }
};

str = prompt("Enter some math:", "-2 + 6 / 2 * 8 - 1 / 2.5 - 18").replace(/ /g, "");
var mathRegex = /(\-?\d+\.?\d*)([\*\/\+\-])(\-?\d+\.?\d*)/;
while(mathRegex.test(str)) {
    str = str.replace(mathRegex, math);
}
alert(str)

```

Here it is compacted down to 208 characters (JS-Fiddle of it):

```
function m(x,l,o,r){
    L=(f=parseFloat)(l);
    R=f(r);
    return o=='*'?L*R:o=='/'?L/R:o=='+'?L+R:L-R;
};

M=/(\-?\d+\.?\d*)([\*\/\+\-])(\-?\d+\.?\d*)/;
for(s=prompt().replace(/ /g, "");M.test(s);s=s.replace(M,m)){};
alert(s)

```

Since I'm ending lines with semi-colons, all *removable* whitespace was ignored for character counting, but left in for clarity.
> 2 votes

# Answer
# Haskell - 124

```
let p=let f[x]=Just$read x;f(x:o:r)=lookup o[("-",(-)),("+",(+)),("*",(*)),("/",(/))]<*>f r<*>Just(read x)in f.reverse.words

```

The result will be wrapped in `Maybe` monad

```
λ: p"-2 + 6 / 2 * 8 - 1 / 2.5 - 18"
Just (-12.0)

```

Also it requires importing `<*>` from `Control.Applicative`, but imports can be done outside the code, so I hope it's allowed.
> 2 votes

# Answer
# JavaScript (87 characters)

```
alert(prompt().split(/ +/).reduce((a,b,i)=>i%2?(o=b,a):o+1-0?a-b*-(o+1):o<'/'?a*b:a/b))

```
> 1 votes

# Answer
# Java 10, ~~151~~ 145 (as lambda function)

```
s->{float r=0,t,o=0,q;for(var x:s.split(" ")){if(x.length()>1|(q=x.charAt(0)-43)>4){t=new Float(x);r=o<0?r*t:o<1?r+t:o<3?r-t:r/t;}o=q;}return r;}

```

-6 bytes thanks to *@ceilingcat*.

Lambda function taking a String input and outputting a float.

Try it online.

# Java 10, ~~241~~ 235 bytes (as full program with asked I/O)

```
interface M{static void main(String[]a){float r=0,t;int o=43,q;for(var x:new java.util.Scanner(System.in).nextLine().split(" ")){if(x.length()>1|(q=x.charAt(0))>47){t=new Float(x);r=o<43?r*t:o<44?r+t:o<46?r-t:r/t;}o=q;}System.out.print(r);}}

```

Full program taking a String-line through STDIN and outputting to STDOUT.

Try it online.

**Explanation:**

```
interface M{                  // Class
  static void main(String[]a){//  Mandatory main-method
    float r=0,                //   Result float, starting at 0
          t,                  //   Temp float
          o=0,                //   Operator flag, starting at '+'
          q;                  //   Temp operator flag
    for(var x:new java.util.Scanner(System.in)
                              //   Create an STDIN-reader
               .nextLine()    //   Get the user input
               .split(" ")){  //   Split it on spaces, and loop over it:
      if(x.length()>1         //    If the current String length is larger than 1
                              //    (work-around for negative values)
         |(q=x.charAt(0)-43)>4){
                              //    Or the first character is an operator
                              //    (and set `q` to this first character at the same time)
        t=new Float(x);       //     Convert the String to a float, and set it to `t`
        r=                    //     Change `r` to:
          o<0?                //      If `o` is a '*':
            r*t               //       Multiply `r` by `t`
          :o<1?               //      Else-if `o` is a '+':
            r+t               //       Add `r` and `t` together
          :o<3?               //      Else-if `o` is a '-':
            r-t               //       Subtract `t` from `r`
          :                   //      Else (`o` is a '/'):
            r/t;}             //       Divide `r` by `t`
      o=q;}                   //    And at the end of every iteration: set `o` to `q`
    System.out.print(r);}}    //    Print the result `r` to STDOUT

```
> 1 votes

# Answer
# 05AB1E, 30 bytes

```
#ćs2ôívy`…+-*sk©i-ë®>i+ë®<i*ë/

```

Try it online or verify all test cases.

**Explanation:**

```
#           # Split the (implicit) input-string by spaces
 ć          # Pop the list, and push the remainder and first item separated to the stack
  s         # Swap so the remainder is at the top of the stack
   2ô       # Split it into parts of size 2 (operator + number pairs)
     í      # Reverse each pair so the numbers are before the operators
v           # Loop over each of the pairs:
 y`         #  Push the number and operator separated to the stack
   …+-*     #  Push a string "+-*"
       sk   #  Get the index of the operator in this string
         ©  #  Store this index in the register (without popping)
   i        #  If the index is 1 (the "-"):
    -       #   Subtract the numbers from each other
   ë®>i     #  Else-if the index is 0 (the "+"):
       +    #   Add the numbers together
   ë®<i     #  Else-if the index is 2 (the "*"):
       *    #   Multiply the numbers with each other
   ë        #  Else (the index is -1, so "/"):
    /       #   Divide the numbers from each other
            # (and output the result implicitly)

```

---

If an `eval` builtin was allowed, this could be an alternative approach (**16 bytes**):

```
#ćs2ôJv…(ÿ)y«}.E

```

Try it online or verify all test cases.

**Explanation:**

```
#ćs2ô    # Same as above
     J   # Join each operator+number pair together to a single string
v        # Loop over the operator+number strings:
 …(ÿ)    #  Surround the top of the stack in parenthesis
     y«  #  And append the operator+number string
}.E      # After the loop: evaluate the string using a Python-eval

```

This would change `"-2 + 6 / 2 * 8 - 1 / 2.5 - 18"` to `"((((((-2)+6)/2)*8)-1)/2.5)-18"` before using the `eval` builtin (using `.E` directly would give operator precedence of `*/` over `+-`, hence the conversion with parenthesis first).
> 1 votes

# Answer
# ZX81 BASIC (might be cheating, so just for fun/non-competing), ~14 Tokenised BASIC bytes, 6 key entries without *new line* (ZX81 speak for enter)

```
1 INPUT A
2 PRINT A

```

Whilst this does not explicitly use any kind of "eval" functions, ZX81 BASIC evaluates any mathematical expressions in its ROM *if you are inputing to a floating point variable* of which `A` would be (like most 8-bit BASIC variants, string variables will have a `$` at the end of the variable name). So when you enter the program and `RUN` it, you can type like `12+10*6` and this will output `72` (note the ZX81 keyboard has some odd key placements for +, /, - and * etc).

The byte count is as follows: as I recall, each line number is stored as 4 bytes, and `INPUT` is a single token, as is `PRINT` (you cannot free type in ZX81 BASIC to enter BASIC commands, so to enter the `INPUT` command, press I, and to enter the `PRINT` command, press P). I don't recall how many bytes are stored at the end of each BASIC line entered, but let's assume that it is a single byte, hence my estimate of 14 tokenised BASIC bytes. I'll find out the exact number at a later time (if this is not cheating).

You may try this online with the JtyOne Online ZX81 Emulator which helpfully has an interactive keyboard below the running emulator.
> 1 votes

---
Tags: code-golf, math, arithmetic
---