# Question
Title: Print the phrase "And she said, 'But that's his.'" using only the alphabet
Print the phrase `And she said, 'But that's his.'` using only the following characters: `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ` No punctuation or non-alphabetic characters whatsoever. You can use whatever programming language you want. Whitespace is completely allowed. Shortest program wins.

# Answer
> 81 votes
# Whitespace, ~~417~~ ~~414~~ ~~349~~ 265 bytes

265 bytes thanks to Kevin Cruijssen

```

```

Try it online!

Explained:

```
[S S T  T   T   T   T   T   T   N
_Push_-63_'][S S T  T   T   T   S S S N
_Push_-53_.][S S S T    T   S T N
_Push_13_s][S S S T T   N
_Push_3_i][S S S T  S N
_Push_2_h][S S T    T   S S S T T   S N
_Push_-70_space][S T    S S T   T   N
_Copy_0-based_3rd_s][S T    S S T   T   S N
_Copy_0-based_6th_'][S S S T    T   T   S N
_Push_14_t][S S T   T   S T N
_Push_-5_a][S S S T S N
_Push_2_h][S T  S S T   S N
_Copy_0-based_2nd_t][S T    S S T   T   S N
_Copy_0-based_6th_space][S T    S S T   N
_Copy_0-based_1st_t][S S S T    T   T   T   N
_Push-15_u][S S T   T   S S T   S S N
_Push_-36_B][S S T  T   T   T   T   T   T   N
_Push_-63_'][S T    S S T   S S N
_Copy_0-based_4th_space][S S T  T   T   T   S T S N
_Push_-58_,][S S T  T   S N
_Push_-2_d][S S S T T   N
_Push_3_i][S S T    T   S T N
_Push_-5_a][S S S T T   S T N
_Push-13_s][S T S S T   S T N
_Copy_0-based_3rd_space][S S T  T   N
_Push_-1_e][S S S T S N
_Push_2_h][S T  S S T   T   N
_Copy_0-based_3rd_s][S T    S S T   T   N
_Copy_0-based_3rd_space][S S T  T   S N
_Push_-2_d][S S S T S S S N
_Push_8_n][S S T    T   S S T   S T N
_Push_-37_A][N
S S N
_Create_Label_LOOP][S S S T T   S S T   T   S N
_Push_102][T    S S S _Add][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

```

# Answer
> 67 votes
# Perl 5, ~~133~~ ~~102~~ 95 bytes

```
s qqAnd she saidZ ZBut thatZs hisZZGjGGfq x
s qZqchr oct oct oct ord chopqge x
y qGjfqqdx
print

```

Try it online!

Explanation:

Regexes, print, and chop all apply to the variable `$_` by default.

```
s qqAnd she saidZ ZBut thatZs hisZZGjGGfq

```

Replaces the empty string with `And she saidZ ZBut thatZs hisZZGjGGf`.

```
s qZqchr oct oct oct ord chopqge

```

Replaces each `Z` with the result of evaling `chr oct oct oct ord chop`. This removes the last character of `$_`, takes its keycode, interprets it as octal thrice, and converts it back to a character. For example, `j` → 106 → 70 → 56 → 46 → `.`.

Due to the way replacement works, the modifications to `$_` that happen while evaluating the replacement are lost, so `$_` is now `And she said, 'But that's his.'GjGGf`.

```
y qGjfqqd

```

Deletes all `G`, `j`, and `f` in `$_`.

# Answer
> 35 votes
# \>\<\>, ~~916~~ ~~915~~ 903 bytes

At first I thought a solution in \>\<\> was impossible, but then I realized... who needs conditionals or logic control? :D

```
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffloffffffffffffffffffffffffffffffffffffffffffffflopppgloppppppppppppppppppppppggloffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffflopppggloploppppppppppppppppppppppploffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffflopppppplofffffffflopggloppppppppppppppppppgglopppplofffffffloffffffffffffffffffffffffffflofffffffffffffffffffffffffffffffffffffffffffffffffffloglopppppppppppppppppppppppppppplofffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffflopppploppgloffffffffffffffffffflopppppppppppppppppppppppppgglofffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffflopppppppppppppppppppppppppppgglofffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffflofloffffffffffloppppppppppppppppppppppploppgloio

```

**Try it Online**

I repeatedly push numbers (the number 15) to the stack, then push the length of the stack and print the character with that ASCII value. If I need to shrink the length of the stack, I shrink the stack three values at a time using `p`, or one at a time using `g` if I'm within three of the target. The program ends by calling `i` (input), which pushes a `-1` since there's no input, then prints it to cause an error.

This is the Python 3 program I used to create the solution once I'd thought of how to do it:

```
s = "And she said, 'But that's his.'"
L = [0]+[ord(c) for c in s]
#print(L)
M = L[1:]+[0]
D = [x[1]-x[0] for x in zip(L,M)]
#print(D)
while D:
	n=D.pop(0)
	if not D:print('io',end='');exit()
	if n>0:print('f'*n,end='lo')
	else:
		while n<-2:print('p',end='');n+=3
		print('g'*-n,end='lo')

```

**Try it Online**

# Answer
> 30 votes
# 8086 Assembly on IBM PC, 1463 845 664 bytes

**Clarification: The actual assembly language source is the entry, not the generated machine code.**

The difficulty is that most x86 instructions (like ADD, SUB, JMP, conditional jumps, memory access) have two arguments and thus need a comma, or need a memory address. So, we can't use addition, subtraction, ifs, or loops!

During my first attempt I was able to "construct" numbers using a combination of increment, decrement, multiplication, division, byte-tricks, and the obscure BCD instructions (like AAA, DAS). After that, I realised that this idea could be used to create self-inspecting and self-modifying code.

* **Attempt 1.** (1463 bytes)

Used the available instructions to construct ASCII codes and the 0xb800 address of the screen buffer. The calculation of each character in the sequence was golfed by hand.
* **Attempt 2.** (not complete)

Realised that there is an opcode for *every* integer in the range 0x40-0x5f. This range includes A-Z. So for example INC CX corresponds to 0x41 = 'A'. (This opcode table is very handy.)

I attempted to construct 3 "data" strings, and layer them on top of one another. The first as-is (uppercase), the second "shifted" into the 0x60-0x7f zone (lowercase) and the last "shifted" into the 0x20-0x3f zone (punctuation).

Self-modifying code would produce a loop or three to iterate over the data.
* **Attempt 3.** (845 bytes)

Like previous approach but to cut down on data, the string would only be encoded once, with "control characters" mixed in to switch character sets.
* **Attempt 4.** (664 bytes)

How to get rid of the control characters which require a whole lot of patched instructions to deal with branching? Given that only two uppercase letters are used, I wondered whether I could "flip" the opcode table to encode lowercase letters using the 0x40-0x4f range and punctuation using the 0x90-0x9f range (by subtracting from 0xc0). The "A" and "B" could get put in separately.

However only half the opcodes in the 0x90-0x9f range are usable and they didn't line up with the needed ones. Then I thought maybe I could shuffle them around using a XOR, and I found one that worked. And here it is.

Golfed:

```
REP LODSB
PUSH CX
PUSH CX
POP AX
INC CH
PUSH CX
POP DI
DEC AX
DEC AX
REPNE SCASB
REPNE SCASB
PUSH DI
REPNE SCASB
PUSH DI
REPNE SCASB
PUSH DI
POP SI
POP DI
DEC DI
LODSB
NOT AL
STOSB
POP CX
DEC CH
LODSB
NOT AL
STOSB
LODSB
AAA
STOSB
INC DI
LODSB
NEG AL
STOSB
LODSB
NOT AL
PUSH AX
PUSH AX
INC SP
POP ES
INC SP
POP DI
LODSB
NOT AL
PUSH AX
POP BX
NEG AL
STOSB
INC DI
LODSB
DEC AL
NEG AL
DIV BH
PUSH AX
POP DI
LODSB
STOSB
RET
DEC BL
PUSH CS
STOSB
PUSH DS
INC DI
INC AX
POP SI
PUSH SP
NOP
INC BP
POP AX
PUSH DI
NOP
INC BP
PUSH BX
POP BX
PUSH SP
PUSHF
NOP
CWD
PUSH DX
INC DI
INC SP
NOP
INC SP
POP AX
PUSH BX
INC SP
CWD
INC BP
NOP
POP AX
POP BX
INC BP
SAHF
CWD
SCASB
INC DX

```

Assemble with

```
nasm golf.asm -o golf.com

```

and run in DOSBOX (run CLS first). Looks like this:

Commented:

```
; ASSUME DS = ES = CS
; ASSUME IP = 0x0100
; true for .COM file

; We treat 0xFE as a special marker that we scan for
; This marks our patch zone and the start of our data

; We also use it as a cheap trick to get a constant 0x1f
; into CX

; 0xFE is the first byte of INC or DEC instructions
; that operate on half-word registers (AL, BL, CH etc.)
; WATCH OUT! Adding these breaks the scan

; Can't assume any register contains zero
; so use this trick to zero out CX
REP LODSB

PUSH CX ; needed later

; zero AX
PUSH CX
POP AX

INC CH
PUSH CX
POP DI ; 0x100, where our code starts

DEC AX
DEC AX ; AL = 0xFE, our marker (AH = 0xFF)

REPNE SCASB ; skip the INC CH above
REPNE SCASB ; find the DEC CH located at 0x10E

; we will later need 0xF, the char count minus the 'A'
PUSH DI ; DI = 0x10F

REPNE SCASB ; find the patch position
PUSH DI

REPNE SCASB ; find the next 0xfe; our data section
PUSH DI
POP SI ; load data from here

POP DI ; store data to the patch position
DEC DI

; patch in XOR
; XOR is 0x34, start with 0xCB
; second byte of DEC BL is 0xCB
LODSB
NOT AL
STOSB

POP CX ; get 0x0f in CX for our strlen
DEC CH

; patch in our XOR arg
; it is 0xF1 (take 0x0E and NOT it)
LODSB ; 0x0E (PUSH CS)
NOT AL
STOSB

; ADD is 0x00 (take 0xAA, apply weird AAA behaviour)
; this also zeroes AH
LODSB ; 0xAA (STOSB)
AAA
STOSB

INC DI ; skip next instruction byte

; LOOP is 0xE2
LODSB ; 0x1E PUSH DS
NEG AL
STOSB

; get b800 in ES (address of screen buffer)
; first get 0x47 in AL (INC DI)
LODSB  ; get 0x47 (INC DI)
NOT AL ; NOT 0x47 = 0xb8
; AX = 0x00b8 (bytes backwards)

PUSH AX
PUSH AX
; stack contains 0xb8 0x00 0xb8 0x00
; stack off-by-1 trick
INC SP
; now POP gives you 0xb800
POP ES
INC SP ;and clean up after ourselves

; store 0 in DI ***** PUSHED AT START OF PROGRAM ***
POP DI

LODSB ; get our magic 0xC0 (0x40 INC AX)
NOT AL
PUSH AX
POP BX

NEG AL ; NOT and +1 to get 0x41 ("A")

; charloop:
STOSB
INC DI
LODSB
DEC AL ; XOR
NEG AL ; modify this into an ADD AL, BL
DIV BH ; modify this to LOOP back to charloop

; doesn't print the last character
; but the last character turns into the address where 'B'
; is supposed to go

PUSH AX
POP DI
LODSB ; "B"
STOSB

; graceful exit this time ;)
RET

; *** DATA SECTION ***

         ; PURPOSE

DEC BL   ; 0xFE marks data section, 0xCB for XOR
PUSH CS  ; for XOR arg
STOSB    ; for ADD
PUSH DS  ; for LOOP
INC DI   ; 0x47 -> for 0xb800

INC AX   ; for magic number but also "A"

POP     SI ;n
PUSH    SP ;d
NOP        ;
INC     BP ;s
POP     AX ;h
PUSH    DI ;e
NOP        ;
INC     BP ;s
PUSH    BX ;a
POP     BX ;i
PUSH    SP ;d
PUSHF      ;,
NOP        ;
CWD        ;'
PUSH    DX ;B
INC     DI ;u
INC     SP ;t
NOP        ;
INC     SP ;t
POP     AX ;h
PUSH    BX ;a
INC     SP ;t
CWD        ;'
INC     BP ;s
NOP        ;
POP     AX ;h
POP     BX ;i
INC     BP ;s
SAHF       ;.
CWD        ;'

SCASB     ; treated as char but turns into screen address!
INC DX    ; "B"

```

# Answer
> 25 votes
# Perl 6, ~~1299~~ ~~1272~~ ~~1220~~ 1215 bytes

*Thanks to Grimy for -27 bytes.*

*-52 bytes because we didn't need the rabbit ears in the first place.*

*Thanks to Jo King for -5 bytes.*

```
print chr flip chars i x chars i xx pi
and print lc chr chars NaN x chars cis pi
and print lc chr chars e x e x e
and print chr chars i x e x e x e
and print lc chr flip chars exp i
and print lc chr chars NaN x tau x e x e
and print chr chars chop NaN x e lcm chars e
and print chr chars i x e x e x e
and print lc chr flip chars exp i
and print lc chr flip chars i x chars i xx pi
and print chr chars False x pi x ceiling tau
and print lc chr chars e x e x e
and print chr chars i xx chars NaN x pi
and print chr chars i x e x e x e
and print chr chars chop False x e x e x e
and print chr chars chop NaN xx chars e
and print lc chr chars e x chars False
and print lc chr chars chop e x chars False
and print chr chars i x e x e x e
and print lc chr chars chop e x chars False
and print lc chr chars NaN x tau x e x e
and print lc chr flip chars i x chars i xx pi
and print lc chr chars chop e x chars False
and print chr chars chop False x e x e x e
and print lc chr flip chars exp i
and print chr chars i x e x e x e
and print lc chr chars NaN x tau x e x e
and print chr chars False x pi x ceiling tau
and print lc chr flip chars exp i
and print chr chars NaN xx tau x e
and say chr chars chop False x e x e x e

```

Try it online!

Outputs the string with a trailing newline. If you don't want that, then replace the last `say` with a `print`. You can also replace the newlines in the source with spaces.

## Explanation

This code prints the string character by character. Each character is formed by feeding the appropriate character code into the `chr` function and lowercasing it with `lc` if needed.

Currently, all of the values are generated by generating a string with the correct number of characters in it; in some cases, the number of characters is the reverse of the target character code. It should be theoretically possible to use mathematical functions such as `log` and `exp` directly, but I didn't find it very easy to use those.

For use as numbers, we have `e`, `pi` and `tau`; in the right side of `x` or `xx`, they are implicitly floored. They all have 17 characters in their string representations, so we use `e` for minimal character count. We also have `i` (4 characters), `False` (5 characters) and `NaN` (3 characters). We can multiply string lengths with `x`; `xx` multiplies one plus the string length by the right hand side and adds one. `chop` removes one character from the string in case we're one away from the target.

The print statements are chained together using `and`, which has quite a low precedence. It's almost a miracle it exists; otherwise, we would have to use illegal semicolons.

I found the expressions for the characters by hand. It might be worth searching for them programmatically to find shorter expressions.

# Answer
> 18 votes
# Width, ~~66~~ 64 bytes

```
QaaGmwmiimaGcwWiimawAGawmfciiiGaFmAmFiimFGcwAmFiGmaiiGcGamafFiGQ

```

Try it online!

Prints to debug. To print to stdout, append `ww` to the end of the code, which pops and outputs the top of the stack.

# Explanation

In Width, each letter correlates to a number, based on how "wide" it is, according to this table. This assigns each letter a number from 0 to 9. Then, those numbers are used to actually execute code.

In particular, a letter than matches `7` will start a string literal. It will read sets of two letters at once, until it reads the original letter again. Each set of two letters will be converted to their width numbers, read as a decimal number between 0 and 99, and the character they equal will be their index in the following string:

```
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~\n\t

```

For example, the index of `!` is 1, so `01` will be the right width numbers. Thus, `if`, `iI`, `jt`, etc will all correlate to a string literal of `!`.

In this case, I translated the 31 characters of the required output to appropriate letters, using `Q` as the quotation marks. The top of the stack is printed to debug when the program finishes.

# Answer
> 14 votes
# x86 machine code (32-bit), 256 bytes

When I print my code on my codepage 437 console, I see the following:

```
j XI a I a I a jbZ      Q fiQ Gf a f    Q I a I a I a I a h hisZ        Q I a I a I a I a hBP  Z        Q iQ
y       Q  a I a I a I a h thaZ Q I a I a I a Ih ButZ   Q  a I a I a I a fhu fZf        Q iQ g  S       Q  a I a I a I a hsaidZ Q I a I a I a I a hshe Z        Q I a I a I a I a hAnd Z        Q TZBX b

```

This contains some whitespace characters, so here is the same code when I replace all tab characters by  and all nonbreaking space characters (with code 255) by `*`:

```
j XI a I a I a jbZ→Q fiQ Gf a f→Q I a I a I a I a h hisZ→Q I a I a I a I a hBP  Z→Q iQ →→y →Q  a I a I a I a h thaZ→Q I a I a I a Ih ButZ→Q  a I a I a I a fhu fZf→Q iQ g→S →Q  a I a I a I a hsaidZ→Q I a I a I a I a hshe Z→Q I a I a I a I a hAnd Z→Q TZBX*b*

```

Hexdump:

```
6a 20 58 49 20 61 20 49 20 61 20 49 20 61 20 6a
62 5a 09 51 20 66 69 51 20 47 66 20 61 20 66 09
51 20 49 20 61 20 49 20 61 20 49 20 61 20 49 20
61 20 68 20 68 69 73 5a 09 51 20 49 20 61 20 49
20 61 20 49 20 61 20 49 20 61 20 68 42 50 20 20
5a 09 51 20 69 51 20 09 09 79 20 09 51 20 20 61
20 49 20 61 20 49 20 61 20 49 20 61 20 68 20 74
68 61 5a 09 51 20 49 20 61 20 49 20 61 20 49 20
61 20 49 68 20 42 75 74 5a 09 51 20 20 61 20 49
20 61 20 49 20 61 20 49 20 61 20 66 68 75 20 66
5a 66 09 51 20 69 51 20 67 09 53 20 09 51 20 20
61 20 49 20 61 20 49 20 61 20 49 20 61 20 68 73
61 69 64 5a 09 51 20 49 20 61 20 49 20 61 20 49
20 61 20 49 20 61 20 68 73 68 65 20 5a 09 51 20
49 20 61 20 49 20 61 20 49 20 61 20 49 20 61 20
68 41 6e 64 20 5a 09 51 20 54 5a 42 58 ff 62 ff

```

Some explanations on how it works:

Useful instructions are:

* `push imm8`, `push imm16` and `push imm32`, followed by `pop` generate constants. This can also generate zero (in `ah`) when pushing a byte (`imm8`).
* `and [ecx+32], ah` \- assuming ah = 0, this sets the byte to zero. It just so happens that the length of the output string is 32, so the code fills the buffer from end to beginning.
* `or [ecx+32], edx` \- assuming the output byte is set to zero, this copies `edx` (4 bytes) to output. I use a variant with `dx` instead of `edx` near the end of the buffer, because it should not write beyond the output buffer. The restriction on code makes it impossible to write single bytes this way!
* `imul edx, [ecx+32], whatever` \- this is the main scrambling idea. With enough entropy in `[ecx+32]` and the *whatever* number, it can generate any output. I use it to generate 2 or 3 bytes of needed values. Some complication is, when writing it to the output, it must do logical `OR` with whatever is already there. This sometimes made it necessary to zero the memory once again.
* A variant of a `jmp` instruction is used to return. I chose it because its encoding is `0xff`, which corresponds to a non-breaking space in codepage 437. A bit of a stretch on the rules, but otherwise I think the task is impossible...

Assembly source code, together with a C program which runs it (uses Visual Studio syntax):

```
#include <stdio.h>

__declspec(naked) void __fastcall doit(char* buf)
{
    __asm {
        push ' '
        pop eax

        dec ecx
        and [ecx+32], ah    // terminating 0 byte

        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah

        push 98
        pop edx
        or [ecx+32], edx
        imul dx, [ecx+32], 26183
        and [ecx+32], ah
        or [ecx+32], dx    // two bytes: [.']

        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        push 'sih '
        pop edx
        or [ecx+32], edx    // 4 bytes: [ his]

        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        push 538988610
        pop edx
        or [ecx+32], edx
        imul edx, [ecx+32], 544803081
        or [ecx+32], edx // 1 junk byte and 3 good bytes: (t's)

        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        push 'aht '
        pop edx
        or [ecx+32], edx    // 4 bytes: [ tha]

        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        push 'tuB '
        pop edx
        or [ecx+32], edx    // 1 junk byte and 3 good bytes: [But]

        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        push word ptr 8309
        pop dx
        or [ecx+32], dx
        imul edx, [ecx+32], 542312807
        or [ecx+32], edx    // 1 junk byte and 3 good bytes: [, ']

        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        push 'dias'
        pop edx
        or [ecx+32], edx    // 4 bytes: [said]

        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        push ' ehs'
        pop edx
        or [ecx+32], edx    // 4 bytes: [she ]

        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        dec ecx
        and [ecx+32], ah
        push ' dnA'
        pop edx
        or [ecx+32], edx    // 4 bytes: [And ]

        push esp
        pop edx
        inc edx

        pop eax
        jmp dword ptr[edx-1]
    }
}

int main()
{
    char buf[100];
    doit(buf);
    puts(buf);
}

```

# Answer
> 14 votes
# PostScript, ~~889~~ ~~874~~ ~~837~~ 835 bytes

```
currentflat string dup rrand
count dup count count mul mul xor count count mul count dup mul exch count
count copy count copy count copy count copy count copy
add and sub put print
and sub add put print
sub sub add put print
mul or xor put print
idiv xor add put print
or xor add put print
mod idiv add put print
mul or xor put print
idiv xor add put print
sub and add put print
or and add put print
sub sub add put print
pop add sub put print
mul or xor dup copy put print
mod mul sub put print
add or xor put print
idiv add add put print
add or add put print
put print
add or add put print
or xor add put print
sub and add put print
add or add put print
mod mul sub put print
idiv xor add put print
mul or xor put print
or xor add put print
or and add put print
idiv xor add put print
xor add sub put print
mod mul sub put print
quit

```

Try it online!

This uses 32 copies of the integers `89 25 20 6`. All charcodes of the target string can be obtained with operations on those integers, in stack order: for example, 'A' (ASCII 65) is 89 - (25 & (20 + 6)). Many 4-tuples of integers have this property; this one was chosen because they’re particularly easy to generate.

```
currentflat string dup rrand

```

Flat defaults to 1, so this creates a string of length 1 (initialized to `\0`). `dup` is not a deep copy: it creates a second reference to the same string. rrand pushes the random seed, which defaults to 0. Stack is now `["\0", "\0", 0]`.

```
count dup count count mul mul xor

```

`count` pushes the number of items in the stack, so this computes 3 ^ (3 * (5 * 6)) = 89.

```
count count mul count dup mul exch count

```

4 * 5 = 20, 5 * 5 = 25, 6 = 6. The stack is now `["\0", "\0", 0, 89, 25, 20, 6]`.

```
count copy count copy count copy count copy count copy

```

Duplicate the entire stack, five times. Thus we end up with 32 copies of our initial 7-element stack. We only need 31 copies, since the target string is 31 characters long, but the extra copy doesn’t hurt.

```
add and sub put print

```

Compute a charcode from the top four integers, write it at index 0 of the string, then print the string.

```
quit

```

Suppresses the default prompt.

# Answer
> 13 votes
# Ruby, 420 354 338 bytes

```
def P a
print String a
end
def Q a
p String a
end
class String
def inspect
putc sum size
q
end
end
def w
Q def hacked
end
rescue
end
P def And
end
w
P def she
end
w
P def said
end
Q def gadget
end rescue
w
def a
Q def afraid
end
rescue
end
a
P def But
end
w
P def that
end
a
putc String def s
end
w
P def his
end
Q def fierce
end rescue
a

```

Try it online!

In ascending order of jankiness:

Words starting with a capital letter can be printed by defining a class with that name and calling `display` within the class definition body.

Other words can be displayed by defining methods with that name, which returns a Symbol, then casting that to a String to remove the leading colon.

Other characters can be displayed by calling `putc` on their ASCII code. We can generate the appropriate numbers by reusing the `String def` trick to get a string, then taking the sum of its bytes using a modulus determined by its size. Unfortunately, we don't have any way to call methods on an object other than from within the class definition of that object, which makes it difficult to pass in arguments. So the final hack is to redefine `String#inspect`, which gets called implicitly when passing a String in to the `p` method, so that it calculates and outputs the appropriate character as a side effect, before raising an error so that `p` can't actually finish executing and print a newline. Then we need to rescue the error in the main code.

Edit: Jordan made the byte count much less, ahem, high with some clever control flow golfing, and I've cut a few more bytes by replacing `raise` with a one-letter nonexistent method call, which raises a NameError.

Edit 2: Noticed that with `print String` extracted into a method, it's cheaper to just use that with a method definition than to use the class definition trick, since methods are allowed to be title cased.

# Answer
> 13 votes
# \>\<\>, ~~233~~ 122 bytes

```
cdacaabbglccgpcbfbbcaacdebbafbebbcebdbealbcpcdbcccdlcdpacbbalccpaalacpbcfafbaab

       g  sandBe
       o  Aviuth

```

Try it online!

This started as a golf of mbomb's answer, but I discovered a fundamental shift that saves a huge number of bytes, so I'm posting it as my own answer.

Generating non-alphabetic characters to output is done by repeatedly pushing values to the stack, then using `l` to push the stack length. However, this does not need to be output immediately: using `p`, this character can be placed in any cell whose coordinates are both between 10 and 15 inclusive, to be retrieved later with `g`. Similarly, alphabetic characters can be placed in the initial source code and read this way: since the highest non-alphabetic character code in the input is 46 (`.`), this means the stack does not need to be pushed higher than the 62 needed to store all 31 characters of the output.

Additionally, a `v` is placed in the code at column 7. When the instruction pointer wraps around and hits that `v`, the sequence `go` is executed repeatedly to read from the pushed coordinates and output the corresponding characters. Eventually, the stack becomes empty, and `g` terminates the program with an error.

The first 7 bytes of code are reused as both the first 7 and last 7 coordinates pushed. Placing the `v` in column 9 would have theoretically saved two more bytes, but would have forced the characters `Ainsv` into a 2x2 square in the code, which is impossible. An earlier version used column 15, but that required an extra line in the source code and ended up six bytes longer.

# Answer
> 8 votes
# Stax, ~~133~~ ~~95~~ ~~84~~ 79 bytes

```
AHHvcAvSVvNvXvsrDhYcvxvZLcHxVahyvxxZVvHVChAHHvVAHhvZAJyVahxvVvDhZyvxvAJZcASVAhL

```

Run and debug it

# Answer
> 8 votes
# CJam, 262 bytes

```
  KAbScibCmhc  CZbsic          GmQYbsic
S CmfYmeibc    ImqmeKmhcel     AZbAbc
S CmfYmeibc    KAbScibCmhcel   ImqmeKmhAmhcel  GmQYbsic    KAZbYbbBbc
S CGmQbDbc     EYbTYtZbc       FYbGmQbcel      EYbGmQbcel
S EYbGmQbcel   ImqmeKmhcel     KAbScibCmhcel   EYbGmQbcel  CGmQbDbc    CmfYmeibc
S ImqmeKmhcel  ImqmeKmhAmhcel  CmfYmeibc       PYmhmeKmhc  CGmQbDbc

```

Try it online! Newlines are only shown here for clarity; each line represents a character.

Whew, this was fun. Restricting ourselves to alphabetic commands poses some interesting challenges:

* Without `{` and `}`, there's virtually no opportunity for control flow (except `f`, which I didn't find an opportunity to use).
* Without `\`, `_`, `;`, or `$`, we have no means for stack manipulation.

This means that the main goal is going to be getting the relevant code points on the stack and then converting them to characters with `c`.

The problem is that we also lack most basic arithmetic commands, as well as integer literals. This is fine though, as the `m` namespace contains numerous advanced mathematical operations, and there are many variables predefined to useful numbers.

I ended up making heavy use of square roots (`mQ` and `mq`), the exponential function `me`, and base conversion (`b`), which can also be used to emulate multiplication (`[X 0] Yb` computes X\*Y). In addition, sometimes it is easier to construct the uppercase codepoint, in which case we can use `el` (convert to lowercase) on the resulting character.

I'm still not satisfied with some of the longer ones. Oh well.

## Explanation

This is a character-by-character explanation of the output. Before I start, here are a few short ways to make numbers:

* 0, 1, 2, 3 are contained in variables `T`, `X`, `Y`, `Z` respectively.
* Numbers 10 through 20 are contained in variables `A` through `K`.
* 32 can be made using `Sci` (`S` pushes a string containing a space, `c` gets the first character of this string, and `i` converts that character to its code point). `S` is also used for spaces.
* 4 is given by `GmQ` (integer square root of 16).
* 5 is given by `AZbYb` (convert 10 to base 3, yielding `[1 0 1]`, and convert the resulting array of numbers to base 2, yielding 5).
* 7 is given by `Ymei` (compute exp(2) and convert to integer).

### `A`

```
K           - push 20                        | 20
 Ab         - convert to base 10             | [2 0]
   Scib     - convert from base 32           | 64
       Cmh  - hypot(TOS, 12)                 | 65.115
          c - round down and convert to char | 'A

```

### `n`

```
C      - push 12            | 12
 Zb    - convert to base 3  | [1 1 0]
   s   - convert to string  | "110"
    i  - convert to integer | 110
     c - convert to char    | 'n

```

### `d`

```
GmQ      - push 4             | 4
   Yb    - convert to base 2  | [1 0 0]
     s   - convert to string  | "100"
      i  - convert to integer | 100
       c - convert to char    | 'd

```

### `s`

```
C         - push 12         | 12
 mf       - factors         | [2 2 3]
   Ymeib  - base 7          | 115
        c - convert to char | 's

```

### `h`

```
I           - push 18                        | 18
 mq         - sqrt                           | 4.242
   me       - exp                            | 69.591
     Kmh    - hypot(TOS, 20)                 | 72.408
        c   - round down and convert to char | 'H
         el - lowercase                      | 'h

```

### `e`

```
A      - push 10              | 10
 Zb    - convert to base 3    | [1 0 1]
   Ab  - convert from base 10 | 101
     c - convert to char      | 'c

```

### `a`

```
KAbScibCmhc   - push 'A (see above) | 'A
           el - lowercase           | 'a

```

### `i`

```
I              - push 18         | 18
 mq            - square root     | 4.242
   me          - exp             | 69.591
     Kmh       - hypot(TOS, 20)  | 72.408
        Amh    - hypot(TOS, 10)  | 73.095
           c   - convert to char | 'I
            el - lowercase       | 'i

```

### `,`

```
K          - push 20              | 20
 AZbYbb    - convert to base 5    | [4 0]
       Bb  - convert from base 11 | 44
         c - convert to char      | ',

```

### `'`

```
C        - push 12              | 12
 GmQb    - convert to base 4    | [3 0]
     Db  - convert from base 13 | 39
       c - convert to char      | ''

```

### `B`

```
E         - push 14               | 14
 Yb       - convert to base 2     | [1 1 1 0]
   TYt    - replace elem 0 with 2 | [2 1 1 0]
      Zb  - convert from base 3   | 66
        c - convert to char       | 'B

```

### `u`

```
F          - push 15             | 15
 Yb        - convert to base 2   | [1 1 1 1]
   GmQb    - convert from base 4 | 85
       c   - convert to char     | 'U
        el - lowercase           | 'u

```

### `t`

```
E          - push 14             | 14
 Yb        - convert to base 2   | [1 1 1 0]
   GmQb    - convert from base 4 | 85
       c   - convert to char     | 'T
        el - lowercase           | 't

```

### `.`

```
P          - push pi                        | 3.141
 Ymh       - hypot(TOS, 2)                  | 3.724
    me     - exp                            | 41.437
      Kmh  - hypot(TOS, 20)                 | 46.011
         c - round down and convert to char | '.

```

# Answer
> 7 votes
# Deadfish~, 943 bytes

```
iiisdsiciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiicddddddddddcddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsddddddcdddddddddddcdddcdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsddddddcddddddddddddddddddciiiiiiiicdddddcddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddciiiiiiiciiiiiiiiiiiiiiiiiiiiiiiiiiiciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiicdcddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsdddddcddddddddddddcdddddddciiiiiiiiiiiiiiiiiiicdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddddddddddddddddddsddddddcdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddddddddddddsiiiiciciiiiiiiiiicdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddc

```

Try it online!

No loops allowed `:(`

# Answer
> 7 votes
# evil, 198 bytes

```
aeeeannkhhwzuuuuuueaeuekwuuuuuuuuuunkhwzaeeeeehknwgueeywguuuuuuhhknnwuuuwhgwpwnngheeuwguuuuuwngwzaeeeaaaeeeeeewhhgwnguuuueewnngawpaawuwnngwpawhgwhhgeeuwpawhguuuueewpwhgwhgwawpwnngaaaaaaeeeewguuuueew

```

Try it online!

This was quite fun.

# Answer
> 7 votes
# dc, ~~240~~ ~~222~~ 209 bytes

```
OOOOOziOOOOOOOOOOOOOOOOOOOOOOOOOOOzddddddzkdddzasBdzasAdzscdzdasCzsdOOlAxlAxPOBlBxdIlAxoPAdlBxddsrIlAxssPPOPlsIZlCxddspPOZlCxPPOPlrdZlCxPlsPlrPlcPPKPdZlBxdZlAxPOAZlAxdPIZlCxdPrPdPlpPlrdZlCxPPKPOPPlpPlsPOPldPKP

```

Try it online!

My first thought was the same as @seshoumara, just push enough stuff onto the stack to generate all of the characters' ASCII values. Then it occurred to me that since `+`, `-`, and `*` are single-character operators, I can just recreate them and have the ability to use arithmetic! Surely that would be smaller! ~~And, I wouldn't be surprised if I'm able to golf off any more bytes, but for now... this convoluted approach has managed to tie the naïve(ish) one.~~

`OOOOOziOOOOOOOOOOOOOOOOOOOOOOOOOOOzddddddzkdddzasBdzasAdzscdzdasCzsd` is the part of the approach that's similar to @seshoumara's, but we only go up to 46, which is `.`. We do this because we need to go up to 45, `-`, and we also need a period in our string, so just going one further for the period is (I think) cheapest. Along the way, we store some values: 5, 32, 39 all come in handy later. 5 for utilitarian things, 32 and 39 for their ASCII values. Originally I did 1-5, but that was expensive, and I was able to simply avoid using 4; use `Z` (pop a value, push the number of digits it has) on a three-, two-, or one-digit number for those values. At 42, 43, and 45, we convert these to strings (`*`, `+`, and `-` respectively) and store them as macros (`B`, `A`, and `C` respectively). This means that without using the characters `*+-`, we can now use those operators.

From here we basically start generating the ASCII values using the power of math instead of sheer accumulation, storing some of the repeats along the way. 100, 105 and 115 come up enough that storing them (in registers or otherwise) made sense. Originally, I left the stack filled with 10s and used these to make 100s; it ended up saving bytes to fill the stack with 32s and use those as spaces later on. A slightly more readable version of the ASCII section: `OOlAxlAxP OBlBxdIlAxoP AdlBxddsrIlAxssP P OP lsIZlCxddspP OZlCxP P OP lrdZlCxP lsP lrP lcP P KP dZlBxdZlAxP OAZlAxdP IZlCxdP rPdP lpP lrdZlCxP P KP OP P lpP lsP OP ldP KP`.

*Shaved off 18 bytes by: storing the number 5 as the input radix instead of a register; the number 32 as precision instead of a register; the number 115 as output radix instead of a register; then had to change `KZ` to `IZ` to generate 1s and `OZ` to `KZ` to generate 2s.*

*Shaved off 13 more bytes by flooding the stack with 32s; setting precision to 39; using stack manipulation to avoid storing 116; cutting out some double-work I accidentally left in.*

# Answer
> 6 votes
# MATL, ~~187~~ 158 bytes

```
IEWQKEtqhpEqqKQHhthpKWEyQKWEqqYqQQXJwtQQQwKWEJKQthpYqKQHhthptQQQQQwIIhKQhpqKWEIWKQhpqIEWQQJQQtqKWEyIIhIhpYqQXJyKQthpYqwIWKQhpqyqKWEyJtQwhhPIIhKQhpQIWKQhpqvlec

```

Try it online!

More readable version: Try it online! Manual attempt at building the string. There's probably plenty of room for golfing by cutting the string into convenient chuncks, using `P` and `h` to flip and build a string. I hope somebody will take up the challenge to outgolf me. The main challenge is that you cannot use `+` or `-`, so basic arithmetic is often not possible.

Highlights:

* `KQthpYq`: the 25th (`KQthp`) prime `Yq` is 97, corresponding to the letter `a`. The letter `s` (115) is generated similarly from 113, the 30th prime number. It is then extensively re-used in clipboard `J`.
* `his` is shortened by storing the `h` from before in clipboard `J`. Since that previously stored `s`, we build `his` in reverse so we can still retrieve the recent `s` using `y`, and flip it after using `P`.
* A large number of bytes saved thanks to Luis Mendo (mostly by changing a bunch of `h` to `vle`)

# Answer
> 6 votes
# Japt, 87 bytes

```
Bs g caA
HzG
Ts caV
iWisiiihiSisiUitiaihitiSitiuibu iUiSiWcaV idiiiaisiSieihisiSidiniau

```

Try it

## Explanation

The first line generates the `'` and assigns it to variable `U`.

```
Bs g caA
B                            :11
 s                           :To string
   g                         :First character
     c                       :Character code
      a                      :  Absolute difference with
       A                     :  10

```

The second line assigns `2` to variable `V`.

```
HzG
H                            :32
 z                           :Floor divided by
  G                          :16

```

The third line generates the `.` and assigns it to variable `W`.

```
Ts caV
Ts                           :Convert 0 to a string
   caV                       :Absolute difference of its charcode with V (2)

```

The last line, then, builds the string one character at a time in reverse.

```
iW...ibu ...iWcaV ...iau
iW                           :Start by prepending W (.) to U (')
  ...                        :Each i prepends the literal character that follows it to the string, with S being space and U being "'"
     ibu                     :As B is the constant for 11 and it can't be quoted, here i prepends "b" to the string and u uppercases it
         ...                 :As above, each i is prepending the character/constant that follows it to the string
            iWcaV            :Gets the absolute difference of the charcode of W (.) and V (2) to get the "," and prepends that
                  ...        :Some more literals
                     iau     :And, finally, the same trick is used for the "A" as was for the "B", as A is the constant for 10

```

# Answer
> 6 votes
# MATL, 118 bytes

```
KEUQtVQsQKBFZAXHKUqyyhsXJyyhdQtQQQwOJIUEyhdtKEhsHKQYqEEKQyywhdXJKEUQQHKUhstQwOytHKhsKYqyhdbJyqOHKhstQHKUqhsKUqYqqJvlec

```

Try it online!

More readable version (each line corresponds to one character, except stack-rearranging operations).

# Explanation

The program produces the code points of the required characters, as independent numbers. At the end all those numbers are concatenated into a column vector, reshaped as a row vector, and converted to characters. The result is implicitly displayed.

Some of the tricks used:

* Most code points below 32 are displayed as space. So `0` is used for most spaces, because it only costs a byte (`O`).
* For the first space, however, `15` is used (generated as `KUq`), because it can then be reused by adding it to `100` (char `d`) to give `115` (`s`). On another occasion `5` is used for space (generated as `KQ`), so it can be later subtracted from `44` (`,`) to give `39` (`'`).
* Clipboard `J` is used for storing characters that will be repeated: first `s`, then `'`. Similarly, clipboard `H` stores `100`, which is useful for `d` and for generating other characters.
* Extensive use is made of functions `Q` (add `1`), `q` (subtract `1`), `E` (multiply by `2`) and `U` (square), together with the predefined literals in clipboards `I` (`3`) and `K` (`4`).
* Arbitrary addition and subtraction are done by concatenating into a vector (`h`) and computing its sum (`s`) or consecutive differences ( `d`).
* `100` (`d`) is generated as `4` in binary interpreted as a decimal number.
* `110` (`n`) is obtained from `65` (`A`) by converting to string (`'65'`: code points `[54 53]`), adding `1` to the code points (`[55 54]`), summing them together and adding `1`.
* The order in which numbers are generated is sometimes altered for convenience; and they then are reordered by stack-rearranging functions: swap (`w`), bubble up `b`).

# Answer
> 5 votes
# Red, 272 bytes

```
prin quote And prin sp prin quote she prin sp prin quote said prin comma prin sp prin subtract to sp mold quote G sp prin quote But prin sp prin quote that prin subtract to sp mold quote G sp prin quote s prin sp prin quote his prin dot prin subtract to sp mold quote G sp

```

If the double quotes are necessary:

# Red, 344 bytes

```
prin subtract to sp mold quote B sp prin quote And prin sp prin quote she prin sp prin quote said prin comma prin sp prin subtract to sp mold quote G sp prin quote But prin sp prin quote that prin subtract to sp mold quote G sp prin quote s prin sp prin quote his prin dot prin subtract to sp mold quote G sp prin subtract to sp mold quote B sp

```

Doesn't work in TIO but works in the Red interpreter.

## Explanation:

The words are trivial - I prin them (print with no newline) as literals with `quote`. Red has a built-in word for space - `sp`, as well as `comma` and `dot`. `"` and `'` more interesting: I prin them by subtracting a space from `B` and `G` respectively, starting from a literal `B` and `G`, converting them first to string with `mold` and then to character (in order to use subtraction on them) wtih `to sp` (Red has conversion by prototype - convert the string to the type of `sp`, which is character).

# Answer
> 4 votes
# Forth (gforth), 351

```
CHAR A DUP EMIT
CHAR n EMIT
CHAR d EMIT
SPACE
CHAR s DUP EMIT
CHAR h EMIT
CHAR e EMIT
SPACE
EMIT
CHAR a EMIT
CHAR i EMIT
CHAR d EMIT
DUP CHAR m XOR EMIT
SPACE
CHAR f XOR DUP EMIT
CHAR B EMIT
CHAR u EMIT
CHAR t DUP EMIT
SPACE
DUP EMIT
CHAR h EMIT
CHAR a EMIT
EMIT
DUP EMIT
CHAR s EMIT
SPACE
CHAR h EMIT
CHAR i DUP EMIT
CHAR s EMIT
CHAR G XOR EMIT
EMIT

```

Too bad I can't redefine CHAR or EMIT to one-letter words, since that would require using either `:` and `;` (e.g. `: C CHAR ;`) or `'` (e.g `' CHAR ALIAS C`)

In fact, if I could define words, I could do `: P CHAR EMIT ;` and then do `P x` to print `x`. Oh well.

I can't even create a buffer, write that char sequence to there and then use that as the input, since writing to memory requires using `!` or `C!`

# Answer
> 3 votes
# AlphaBeta, ~~180 177 175~~ 163 bytes

```
cccaaggtFgDILrFigggDLjDLCLigggggDLjhDLhhhDLCLiggggDLjjggDLihhDLhhhhhDLcaaCLdbbCLcbbbCLHgDLiiiiigDLhDLdaaaCLDLjhhDLjgggDLiihDLcbbbCLhDLdaaaCLjhDLgDLiDLcaaaaCLdaaaCL

```

Try it online!

WIP

# Answer
> 3 votes
# Pepe, 266 Bytes

I keep the r stack empty, and have 's' on the R stack

```
reeEeeeeeE reeEEeEEEe reeEEeeEee reEe REeEEEeeEE Reee reeEEeEeee reeEEeeEeE reEe Reee reeEEeeeeE reeEEeEeeE reeEEeeEee reeeEeEEee reEe reeeEeeeEe reeEeeeeEe reeEEEeEeE reeEEEeEee reEe reeEEEeEee reeEEeEeee reeEEeeeeE reeEEEeEee reeeEeeEEE Reee reEe reeEEeEeee reeEEeEeeE Reee reeeEeEEEe reeeEeeeEe

```

This isn't on TIO, but you can try it here

# Answer
> 3 votes
# Befunge-98 (FBBI), ~~125~~ ~~124~~ 121 bytes

```
wab

And she said   But that s his

wakekekaayyeapwayyaayybyapayybyapcyabcyaayycayyba
a

b
wayapapoq

```

Try it online! Outputs to a file named `\n` (a single newline). Thanks to Jo King for his script.

Output includes 10 trailing newlines.

For only one trailing newline, **+1 byte** by changing the following line:

```
wakekekaayyeapwayy**d**ayybyapayybyap**y**cyabcyaayycayyba
```

Try it online!

---

### Explanation:

The instruction pointer moves as follows:

The program puts the non-alphabetic characters into position, before outputting that line to a file.

Befunge-98 includes instructions `a`...`f`, which push their corresponding hexadecimal value to the stack. To generate other numbers, it passes those values to `y` ("Get SysInfo") as arguments to obtain:

```
10  y-position
11  x-position
12  y-velocity (= 0)
13  x-velocity (= 1)

23* stack size

```

By placing the bulk of the code at y=23, `ayy` can be used for repeated access to the stack size, which is then used to generate character codes.

# Answer
> 3 votes
## dc, 240 bytes

The main idea is to continuously grow the stack by 1 (`K`), saving (`sX`) the size of the stack (`z`) into custom registers when it matches each unique ASCII code. Printing (`P`) is done throughout.

```
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKzsSKKzsQKKKKKzsqKKKKKzsCKKzsDKKKKKKKKKKKKKKKKKKKzPKzsBKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKzsaKKKzsdKzseKKKzshKzsiKKKKKzPldPlSPKKKKKzsszPlhPlePlSPlsPlaPliPldPlCPlSPlqPlBPKzdstzPdPlSPdPlhPlaPPlqPlsdPlSPlhPliPPlDPlqP

```

Try it online!

I did some optimization, like not saving a letter if it is not used after that, like duplicating (`d`) a letter, e.g. t, on the stack to save a byte, since recall (`lX`) is 2 bytes.

# Answer
> 3 votes
# 80186+ machine code, MS-DOS .COM format, 822 787 bytes

Only tabs and spaces are used in addition to letters. Given that most of the opcodes in the allowed range are certain increments, decrements, pushes, pops, and register-indirect ANDs and ORs, in addition to IMUL, I make use of the fact that the stack register wraps around when it hits the end of the segment to modify the code in reverse! 80186+ assembly is required because I am pushing immediate values.

```
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXjhX   GXkOXYIQSX GXjdX    GXkOXwIIIIIIIIIQhhihs kOXeQh ihutSXH    GXHHHHHH GXSX GYkOXDAAAQSX GXjGX    GXkOXtQhidhsahe hshhd hAnSX GXjTX   GXkOXdIIIQkOXgAQSX GXHHHHHHHHHHHHHHHHHHHHH  GXSX GYkOXbAAAAAAAAAAAAAAQhhlh  Xhh qM

```

Annotated source (TASM format):

```
IDEAL
P186

MODEL   TINY
CODESEG
ORG 100H

MAIN:
REPT 582
    POP AX  ; Set up stack to end of string
ENDM

    PUSH 68H
    POP AX
    OR [BX+58H],AX
    IMUL CX,[BX+58H],59H ; 68H*59H=2428H
    DEC CX ; -1=2427H
    PUSH CX

    PUSH BX
    POP AX
    AND [BX+58H],AL
    PUSH 64H
    POP AX
    OR [BX+58H],AX
    IMUL CX,[BX+58H],77H ; 64H*77H=2E7CH
REPT 9
    DEC CX ; -9=2E73H
ENDM
    PUSH CX

    PUSH 6968H
    PUSH 2073H

    IMUL CX,[BX+58H],65H ; 64H*65H=2774H
    PUSH CX

    PUSH 6920H
    PUSH 7475H

    PUSH BX
    POP AX
    DEC AX
    OR [BX+58H],AX ; FFFFH
REPT 6
    DEC AX
ENDM
    AND [BX+58H],AL ; FFF9H
    PUSH BX
    POP AX
    AND [BX+59H],AL ; 00F9H
    IMUL CX,[BX+58H],44H ; 0F9H*44H=4224H
REPT 3
    INC CX ; +3=4227H
ENDM
    PUSH CX

    PUSH BX
    POP AX
    AND [BX+58H],AL
    PUSH 47H
    POP AX
    OR [BX+58H],AX
    IMUL CX,[BX+58H],74H ; 47H*74H=202CH
    PUSH CX

    PUSH 6469H
    PUSH 6173H
    PUSH 2065H
    PUSH 6873H
    PUSH 2064H
    PUSH 6E41H

;; CODE STARTS:
;; PUSH 0909H
;; POP AX
;; PUSH 046CH
;; POP DX
;; INT 21H
;; INT 20H

    PUSH BX
    POP AX
    AND [BX+58H],AL
    PUSH 54H
    POP AX
    OR [BX+58H],AX
    IMUL CX,[BX+58H],64H ; 54H*64H=20D0H
REPT 3
    DEC CX ; -3=20CDH
ENDM
    PUSH CX

    IMUL CX,[BX+58H],67H ; 54H*67H=21CCH
    INC CX ; 21CDH
    PUSH CX

    PUSH BX
    POP AX
    AND [BX+58H],AL
REPT 21
    DEC AX
ENDM
    OR [BX+58H],AX ; 0FFEBH
    PUSH BX
    POP AX
    AND [BX+59H],AL ; 0EBH
    IMUL CX,[BX+58H],62H ; 0EBH*62H=59F6H
REPT 14
    INC CX ; +14=5A04H
ENDM
    PUSH CX

    PUSH 6C68H
    PUSH 5809H
    PUSH 0968H

    JNO $+4FH

END MAIN
ENDS

```

# Answer
> 3 votes
# Vyxal, 112 bytes

```
kAhkHLnikhtnukWhkgTninukahkfuTikhtkTtnkekbhnuTdikWstnkWstkWhkahkWstkeunkWhkfuTiukekTy_tWnuNIVunkiTdiVkekHLTCVuIj

```

Try it Online!

This was created by hand and it's a mess that I won't explain.

# Answer
> 2 votes
# Pyth, 210 bytes

```
pChyCdpCyhyhlGpCyytlGpdpChFhTyylGpCyylGpChyytlGpdpChFhTyylGpCtytytlGpChyylGpCyytlGpCyyhTpdpCtyyTpCyhCdpCtFyyCdhTpCyhFlGCdpdpCyhFlGCdpCyylGpCtytytlGpCyhFlGCdpCtyyTpChFhTyylGpdpCyylGpChyylGpChFhTyylGpCyhyhTpCtyyT

```

Try it online!

I found a few numbers which could be expressed using only letters (like `T` = 10, `Z` = 0, `lG` = length(alphabet) = 26, `Cd` = charcode(space) = 32), and a few functions that could be performed using only letters (like `t` = decrement, `h` = increment, `hF` = repeated application of increment = addition), and then just ran a brute force search to find the shortest combinations of those functions and numbers that resulted in each of the letters I needed.

# Answer
> 2 votes
# Japt, 74 bytes

```
HdEz
iHdE isiiihiSisiUitiaihitiSitiuibu iUiSiHdC idiiiaisiSieihisiSidiniau

```

Try it

# Answer
> 2 votes
## 16-bit x86 assembly code, 665 bytes

(the binary is alphabetic, not the source)

I somehow forgot about the rule allowing whitespace. Surely the code can be golfed as a result.

Bytecode:

```
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXsBFVKZPFFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPFPXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXkLAFQQZJJJRkDCGPLXDPDJRkDBEPZJJRLZDRDZAAAQPLYDQDYXXDQhishZhDRDhZsDQDhaththRDhuthZBDQDRhidhsaRDhhehZsDRDhndhZADTZPiDEFY
```

Source:

```
    db    63 dup (58h) ;pop ax
    jnb   label1
    dw    5646h      ;magic #1
    dw    5a4bh      ;magic #2
    dw    4650h      ;magic #3
    dw    (42h-6)/2 dup ("PF")

label1:
    db    416 dup (58h) ;more pop ax
    imul  cx,[si+41h],46h ;cl=24h (string sentinel)
    push  cx         ;push string sentinel
    push  cx
    pop   dx         ;dl=24h
    dec   dx
    dec   dx
    dec   dx         ;dl=21h
    push  dx         ;save for later
    imul  ax,[si+43h],47h ;al=0CDh
    push  ax         ;push xxCDh
    dec   sp         ;insert xx
    pop   ax         ;ah=0CDh
    inc   sp         ;discard xx
    push  ax         ;push 0CDxx
    inc   sp         ;discard xx
    dec   dx         ;cl=20h (space)
    push  dx
    imul  ax,[si+42h],45h ;al=2Eh (dot)
    push  ax
    pop   dx         ;dl=2Eh
    dec   dx
    dec   dx         ;dl=2Ch (comma)
    push  dx         ;push xx2Ch
    dec   sp         ;insert xx
    pop   dx         ;dl=2Ch
    inc   sp         ;discard xx
    push  dx         ;push 2Cxxh
    inc   sp         ;discard xx
    pop   dx         ;dx=202Ch
    inc   cx
    inc   cx
    inc   cx         ;cl=27h (quote)
    push  cx         ;push xx27h
    push  ax         ;push xx2Eh
    dec   sp         ;insert xx
    pop   cx         ;ch=2Eh
    inc   sp         ;discard xx
    push  cx         ;push 2Exxh
    inc   sp         ;discard xx
    pop   cx         ;cx=272Eh
    pop   ax         ;discard xxxx
    pop   ax         ;ax=0CD21h
    inc   sp         ;discard xx
    push  cx         ;push ".'"
    push  7369h      ;push "is"
    push  685ah      ;push "h"+xx
    inc   sp         ;discard xx
    push  dx         ;" "+xx
    inc   sp         ;discard xx
    push  735ah      ;push "s"+xx
    inc   sp         ;discard xx
    push  cx         ;push "'"+xx
    inc   sp         ;discard xx
    push  7461h      ;push "at"
    push  6874h      ;push "th"
    push  dx         ;push " "+xx
    inc   sp         ;discard xx
    push  7475h      ;push "ut"
    push  425ah      ;push "B"+xx
    inc   sp         ;discard xx
    push  cx         ;push "'"+xx
    inc   sp         ;discard xx
    push  dx         ;push ", "+xx
    push  6469h      ;push "id"
    push  6173h      ;push "sa"
    push  dx         ;push " "+xx
    inc   sp         ;discard xx
    push  6568h      ;push "he"
    push  735ah      ;push "s"+xx
    inc   sp         ;discard xx
    push  dx         ;push " "+xx
    inc   sp         ;discard xx
    push  646eh      ;push "nd"
    push  415ah      ;push "A"+xx
    inc   sp         ;discard xx
    push  sp
    pop   dx         ;dx=sp
    push  ax
    imul  ax,[si+45h],5946h ;ah=09h
```

It works this way:

* moves the stack pointer to the end of the code, via POP AX (can't POP SP because it's not alphabetic);
* constructs the instruction to dispatch a DOS call (algorithmically because it's not alphabetic);
* constructs the non-alphabetic characters;
* places the string on the stack;
* places the dispatch instruction on the stack at the exact end of the code, so that execution flows directly to that instruction;
* constructs the instruction to print a string;
* displays the string and them promptly crashes. :-/ (A graceful exit would require more code)

# Answer
> 2 votes
# 05AB1E, ~~145~~ ~~121~~ 109 bytes

```
TnVYTOUXZxNJTZXTZZZXYTYxMNYTTMNNNYRYNNYNNNNYTXZMNNYxXRZZZXTYXRZZXZYxTRMRNXRMRMXNNYxYMRNTYxTRYNTZMYXRXXXTZJCXB

```

Try it online!

# Answer
> 2 votes
# Husk, 408 bytes

```
mcJLQtDDQDsisNeJDDDDDisNeJDDDDDisNeJLDQQDDsisNeLtQtDDQDsisNLDDtDtDtDDDsisNJLtQDtDDDsisNeLtDDtDtDDDDsisNLttttQDtDDDsisNJLDDtDtDtDDDsisNeJLtDtDtDtDtDDDsisNeLtDDtDtDDDDsisNLQDtDDDsisNJDDDDDisNeDDiDsisNLtDDQDDsisNJLtDDQDDsisNeJLDDtDtDDDDsisNeJLDDtDtDDDDsisNeLtttPtDQDsisNDDDDDisNJLtDtDtDtDtDDDsisNeLtQDtDDDsisNLDDtDtDDDDsisNJLQDtDDDsisNeJDDDDDisNeLtDDtDtDDDDsisNLtQDtDDDsisNJLDtPDDsisNeLtDDtDtDDDDsisNLtDDQDDsisN

```

Try it online!

Well, that was an adventure.

The code was generated with this Python script. Not sure it's optimal, but it's good enough for me.

### Explanation

So, limiting Husk to using only letters turned out to be a real pain... My first idea was to use `s` to convert a value to string, use `t` (drop first element) and `D` (double) to change the length of this string, then convert it to a number by computing its length with `L`: I could do this to generate the ASCII code of each character in the output string, and the convert them to characters with `c`.

That was complex enough for my tastes, but then I realized that all the builtins associated to letters in Husk are functions (which cannot be converted to string), except for `N`... which is the infinite list of natural numbers, good luck getting the length of that. Fortunately, `i` can take a string and return the first integer found in that string, which for `N` would be 1, so with `sisN` I can get my string of length 1 and I can manipulate that to get all other lengths.

I wrote a python script to bruteforce the shortest way to build strings of every needed length starting from `sisN` and using `t`, `D`, `P` (permutations, works like a factorial), and `Q` (substrings, works like n\*(n+1)/2). I also realized that some values could be built more efficiently by working directly on numbers rather than strings, so `isN` is 1, `DisN` is 2, `iDsisN` is 11 (double the string "1" and read that as a number) and so on... those values were not too many, so I just hardcoded them as alternatives and kept for each the shortest between the hardcoded string and the bruteforced one.

Only after I did all that I realized that I didn't have a way to combine different characters into an output string. Strings are just lists of characters, and `e` can build a list of two arguments, but to build longer lists I would need `:`...

This time I was saved by `J`, join, which (among other things) can take a value and a list and insert that value between each pair in the list. If I want to concatenate three strings a b c I can do it with `Jbeac`. The script does this recursively starting from the desired output by choosing `b` as a single central element and `a` and `c` as the two halves separated by `b`. This was my first attempt an miraculously it worked (if the length of the string was different I could have to join only two strings together, but this doesn't happen here). I have tried other ways to compose the string, but this remains the shortest working result I could produce.

# Answer
> 2 votes
# Pip, 102 bytes

```
ndzshezsaidyutzthatxszhiswxPB AoADtYSTfYDQUWyRMsYyH U UoEoOPOAZkPB CxPBPOAZyRDQzsRDQzkRDQzCxRDQzPIRMXD

```

Attempt This Online!

### Explanation

Eagle-eyed readers will have noticed that the code begins with all the lowercase letters from the target string, plus a few others sprinkled in. We'll get back to that in a minute. For now, Pip treats them as no-ops, except the last one:

```
xPB AoADt
    Ao     ; ASCII code of "1" (49)
      ADt  ; Absolute difference with 10 (39)
xPB        ; Push this result onto variable x (initially "")

```

This sets `x` to 39, the ASCII code of `'`. (Trick borrowed from Shaggy's Japt answer.)

```
YSTf
   f  ; The main function
 ST   ; Stringify
Y     ; Yank into y variable

```

Stringifying the main function formats the code and wraps it in curly braces. This is the result:

```
"{n; d; z; s; h; e; z; s; a; i; d; y; u; t; z; t; h; a; t; x; s; z; h; i; s; w; x PB ((A o) AD t); YP (ST f); Y (DQ (UW (y RM s))); Y (y H ((U (U o)) E o)); O (PO AZ); (k PB (C x)) PB (PO AZ); (((y R (DQ z); s) R (DQ z); k) R (DQ z); (C x)) R (DQ z); (PI RM XD)}"

```

From here, we can extract the leading run of lowercase letters:

```
YDQUWyRMsYyH U UoEo
     yRMs            ; y with spaces removed
   UW                ; Unweave into two every-other-character strings
 DQ                  ; Dequeue the last one, which has the letters in it
Y                    ; Yank that string into y
             U Uo    ; Increment o twice (was originally 1, now is 3)
                 Eo  ; Take that value to the power of o (27)
          yH         ; Get that many characters from the start of y
         Y           ; Yank that string into y

```

Now `y` is `"ndzshezsaidyutzthatxszhiswx"`.

```
OPOAZ
   AZ  ; Uppercase alphabet
 PO    ; Pop the first character ("A")
O      ; Output it without a newline

```

Outputting the initial `A` separately is cheaper than making it part of the string.

```
kPB CxPBPOAZ
k             ; Take k (initially ", ")
 PB           ; Push this onto it:
    Cx        ;  Char(39) ("'")
      PB      ; Then push this onto it:
        POAZ  ;  Pop the first character from AZ ("B")

```

Finally:

```
yRDQzsRDQzkRDQzCxRDQzPIRMXD
                             ; z is preinitialized to the lowercase alphabet
yR                           ; In y, replace
  DQz                        ;  character dequeued from z ("z")
     s                       ;  with space
      R                      ; Replace
       DQz                   ;  character dequeued from z ("y")
          k                  ;  with k (", 'B")
           R                 ; Replace
            DQz              ;  character dequeued from z ("x")
               Cx            ;  with char(39) ("'")
                 R           ; Replace
                  DQz        ;  character dequeued from z ("w")
                             ;  with:
                     PI      ;   Pi
                         XD  ;   with digits
                       RM    ;   removed (".")

```

This expression gives us the rest of our target string, which is autoprinted.

# Answer
> 1 votes
# BRASCA, 213 bytes

```
DoluRlugoHoEoDuRxluxluxMgoldUxgollUxgoEoDuRxluxluxMgoholDUmxMgoHoduxduxgoEoEuxhuxgoDuxDuxgoluxluxhumxMgoluxluxDuxgoEoluxluxDuxgoldUxgoholuxluxDuxgoEuxhuxgoDuRxluxluxMgoEoldUxgolDUmxMgoDuRxluxluxMgoduxDuxgoEuxhuxgo

```

Try it online!

## Explanation

At first I wanted to port the \>\<\> answer, before realizing that stack length wont work with only alphabetical characters. That's when I remembered that BRASCA has some nifty things \>\<\> does not have: The `g` and `u` operators!

Using the `lLeEdDhHK` built-ins for pushing numbers, `u` to seperate them into individual digits, `R`, `m` and `M` to rotate and shift the stack, `x` to discard digits, and then `g` to put them back together I can create and output any string using only the alphabet.

## Breakdown

```
    DoluRlugoHoEoDuRxluxluxMgoldUxgollUxgoEoDuRxluxluxMgoholDUmxMgoHoduxduxgoEoEuxhuxgoDuxDuxgoluxluxhumxMgoluxluxDuxgoEoluxluxDuxgoldUxgoholuxluxDuxgoEuxhuxgoDuRxluxluxMgoEoldUxgolDUmxMgoDuRxluxluxMgoduxDuxgoEuxhuxgo
 +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
A|  Do
n|    luRlugo
d|           Ho
 |             Eo
s|               DuRxluxluxMgo
h|                            ldUxgo
e|                                  llUxgo
 |                                        Eo
s|                                          DuRxluxluxMgo
a|                                                       ho
i|                                                         lDUmxMgo
d|                                                                 Ho
,|                                                                   duxduxgo
 |                                                                           Eo
'|                                                                             Euxhuxgo
B|                                                                                DuxDuxgo
u|                                                                                luxluxhumxMgo
t|                                                                                luxluxDuxgo
 |                                                                                Eo
t|                                                                                luxluxDuxgo
h|                                                                                ldUxgo
a|                                                                                ho
t|                                                                                luxluxDuxgo
'|                                                                                Euxhuxgo
s|                                                                                DuRxluxluxMgo
 |                                                                                Eo
h|                                                                                ldUxgo
i|                                                                                lDUmxMgo
s|                                                                                DuRxluxluxMgo
.|                                                                                duxDuxgo
'|                                                                                Euxhuxgo

```

# Answer
> 1 votes
# Actually, ~~2679~~ ~~2618~~ 2561 bytes

```
 PPuPuPDDc uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuc buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuck D cHj

```

Try it online!

I'll golf each character one by one. So far I've golfed up to `A`.

## Explanation

I'll golf pushing the numbers over time, so I'll only explain `k D cHj` for now.

```
k       # Put all the characters into the list
  D cH  # Push the empty string
      j # Join the list using the empty string

```

# Answer
> 0 votes
# 80186 machine code + DOS, 91 bytes

Text version:

```
hm  j   j   PPjzjzjgaAAA    JSJJ    RU  Sq  ReAA    JdJJJ   RfiJElK JEiS GtI And she said   But that s his

```

Text version, with tabs (code 9) replaced by `9` and spaces (code 32) replaced by `*`:

```
hm9j9j9PPjzjzjgaAAA9JSJJ9RU9Sq9ReAA9JdJJJ9RfiJElK9JEiS*GtI*And*she*said***But*that*s*his***

```

Hexdump:

```
68 6D 09 6A 09 6A 09 50 50 6A 7A 6A 7A 6A 67 61
41 41 41 09 4A 53 4A 4A 09 52 55 09 53 71 09 52
65 41 41 09 4A 64 4A 4A 4A 09 52 66 69 4A 45 6C
4B 09 4A 45 69 53 20 47 74 49 20 41 6E 64 20 73
68 65 20 73 61 69 64 20 20 20 42 75 74 20 74 68
61 74 20 73 20 68 69 73 20 20 20

```

The machine code appears in a file with extension `.com`. When I run it, it prints the required message and then hangs (executing random data).

High-level explanation on what it does:

1. Initializes registers with constant values
2. Replaces spaces in the message by the required special symbols (`,'.$`)
3. Patches the code to generate the `int 21` instruction, which prints the message
4. Calls DOS

Assembly code (can be compiled with `tasm`):

```
my_bp equ 7ah
my_si equ 7ah
my_di equ 67h
my_msg equ 13bh
    .model tiny
    .code
    .startup
    .186
    org 100h
    push 96dh   ; ax (ah = 0; al = don't care, but see below)
    push 9      ; cx
    push 9      ; dx
    push ax     ; bx = don't care
    push ax     ; don't care
    push my_bp
    push my_si
    push my_di
    popa
    inc cx
    inc cx
    inc cx
    or [bp+si+my_msg-my_bp-my_si+12], cx ; ,
    dec dx
    dec dx
    or [bp+si+my_msg-my_bp-my_si+14], dx ; '
    or [bp+di+my_msg-my_bp-my_di+23], dx ; '
    or [bp+si+my_msg-my_bp-my_si+30], dx ; '
    inc cx
    inc cx
    or [bp+si+my_msg-my_bp-my_si+29], cx ; .
    dec dx
    dec dx
    dec dx
    or [bp+si+my_msg-my_bp-my_si+31], dx ; $

    ; 0x2049 * 0x4b6c = 0x98301cc
    ; So this sets cx to 1cc (a temporary constant used to patch code)
    imul cx, [bp+si+my_msg-my_bp-my_si-2], 4b6ch
    ; 0x1cc | 0x2049 = 0x21cd (the instruction which calls DOS int 21)
    ; Here ah = 9 ("print" mode)
    or [bp+si+my_msg-my_bp-my_si-2], cx

    ; At address 101, there is the constant 96d, which was loaded into ax
    ; 0x96d * 0x7447 = 0x448013b
    ; So the following sets dx to 13b (adddress of the message)
    imul dx, [bp+di+101h-my_bp-my_di], 7447h

int21:
    dw 2049h

    db 'And she said   But that s his   '
    end

```

It uses the `popa` instruction to pop all registers, because regular `pop` cannot fill all needed registers (e.g. `pop di` is a forbidden opcode).

Addresses of bytes to patch are in the range 0x100...0x160. By luck, they can be represented as a sum of 3 bytes with allowed values:

* 0x7a in `bp`
* 0x7a or 0x67 in `si` or `di`
* Immediate value

Patching of bytes in the message works by doing logical `OR` on 0x20 (space character) and a small constant (4, 7, 12 or 14). The small constant is obtained by initializing `cx` and `dx` to 9 (tab character) and doing `INC` or `DEC` as needed.

Patching of code uses the `IMUL` instruction. I found the needed 16-bit constants to multiply using brute-force search.

Finally, the address of the message (0x13b) is obtained by multiplication. To save space, I took one of the constants from one of the instructions, which contains an immediate value `0x96d`. Here the `9` part chooses a DOS print function, and the `6d` part is a free parameter. It turns out that `6d` is the only possibility which can give 0x13b after multiplication.

Disassembly of the code part:

```
06BA:0100 686D09            PUSH    096D
06BA:0103 6A09              PUSH    +09
06BA:0105 6A09              PUSH    +09
06BA:0107 50                PUSH    AX
06BA:0108 50                PUSH    AX
06BA:0109 6A7A              PUSH    +7A
06BA:010B 6A7A              PUSH    +7A
06BA:010D 6A67              PUSH    +67
06BA:010F 61                POPA
06BA:0110 41                INC     CX
06BA:0111 41                INC     CX
06BA:0112 41                INC     CX
06BA:0113 094A53            OR      [BP+SI+53],CX
06BA:0116 4A                DEC     DX
06BA:0117 4A                DEC     DX
06BA:0118 095255            OR      [BP+SI+55],DX
06BA:011B 095371            OR      [BP+DI+71],DX
06BA:011E 095265            OR      [BP+SI+65],DX
06BA:0121 41                INC     CX
06BA:0122 41                INC     CX
06BA:0123 094A64            OR      [BP+SI+64],CX
06BA:0126 4A                DEC     DX
06BA:0127 4A                DEC     DX
06BA:0128 4A                DEC     DX
06BA:0129 095266            OR      [BP+SI+66],DX
06BA:012C 694A456C4B        IMUL    CX,[BP+SI+45],4B6C
06BA:0131 094A45            OR      [BP+SI+45],CX
06BA:0134 6953204774        IMUL    DX,[BP+DI+20],7447
06BA:0139 CD21              INT     21 (after the code patches itself)

```

Fun fact: Normally, I would use `offset message` instead of the hard-coded `13bh`, but in this case, because at the time of parsing its address is unknown, tasm generates 16-bit immediate offset, wasting 1 code byte:

```
06BA:0131 098A4600          OR      [BP+SI+0046],CX

```

# Answer
> 0 votes
# CJam, 162 bytes

```
KFmfbcACZbbcDsXbcSFseesicHsXbcEsXbcSFseesicAsXbcIsXbcDsXbcDFmfbcSHAmfbcBsXbceuHseesicGseesicSGseesicHsXbcAsXbcGseesicHAmfbcFseesicSHsXbcIsXbcFseesicSciBbIbcHAmfbc

```

Try it online!

Each letter is outputted individually and all the source codes are concatenated. The individual codes are:

(1 byte)

```
S   e# Space

```

`'` (6 bytes)

```
HAmfbc
HA       e# Push 17 and 10    17 10
  mf     e# Factorization     17 [2 5]
    b    e# Base conversion   39
     c   e# Convert to char   ''

```

`,` (6 bytes)

```
DFmfbc
DF       e# Push 13 and 15    13 15
  mf     e# Factorization     13 [3 5]
    b    e# Base conversion   44
     c   e# Convert to char   ',

```

`.` (8 bytes)

```
SciBbIbc
Sci        e# Push space as an integer   32
   Bb      e# Convert to base 11         [2 10]
     Ib    e# Convert from base 18       44
       c   e# Convert to char            '.

```

`A` (6 bytes)

```
KFmfbc
KF       e# Push 20 and 15    20 15
  mf     e# Factorization     20 [3 5]
    b    e# Base conversion   65
     c   e# Convert to char   'A

```

`B` (7 bytes)

```
BsXbceu
Bs        e# Push 11 as a string   "11"   (i.e. [49 49])
  Xb      e# Convert from base 1   98
    c     e# Convert to char       'b
     eu   e# Uppercase             'B

```

`a` (5 bytes)

```
AsXbc
As      e# Push 10 as a string   "10"   (i.e. [49 48])
  Xb    e# Convert from base 1   97
    c   e# Convert to char       'a

```

The codes for `d`, `e`, `h` and `i` work exactly the same way as for `a`. The codes are:

```
DsXbc -> 'd
EsXbc -> 'e
HsXbc -> 'h
IsXbc -> 'i

```

`n` (6 bytes)

```
ACZbbc
ACZ      e# Push 10, 12 and 3   10 12 3
   b     e# Base conversion     10 [1 1 0]
    b    e# Base conversion     110
     c   e# Convert to char     'n

```

`s` (7 bytes)

```
Fseesic
Fs        e# Push 15 as a string   "15"
  ee      e# Enumerate             [[0 '1] [1 '5]]
    s     e# Convert to string     "0115"
     ic   e# Convert to char       's

```

The codes for `t` and `u` do the same thing but staring with `G`(16) and `H`(17):

```
Gseesic -> 't
Hseesic -> 'u

```

Most of these codes were found using another Cjam program to brute force all possible outputs for a given formula. If you want to use it, type some formula such as `RTsbc`, and it will show you how to get to each possible output by replacing `R`, `T` and `U` in the input by some 1 byte constant.

---
Tags: code-golf, kolmogorov-complexity, restricted-source
---


title: The Cantor Function

text:
# Question
Title: The Cantor Function
The Cantor function is continuous everywhere and constant almost everywhere, but has an average slope of 1:

The function can be found recursively:

\\$f\_0(x)=x\\$

\\$f\_{n+1}(x)=\left\\{\begin{matrix}\frac{1}{2}f\_n(3x)&x\in\[0,\frac{1}{3})\\ \frac{1}{2}&x\in\[\frac{1}{3},\frac{2}{3})\\ \frac{1}{2}+\frac{1}{2}f\_n(3x-2)&x\in\[\frac{2}{3},1\] \end{matrix}\right.\\$

The Cantor function is the limit of this process, \\$\lim\limits\_{n\to\infty} f\_n(x)\\$:

# The Challenge

Given real x (which can assume the form of a float or rational number) of the interval \\$\[0,1\]\\$ and nonnegative integer n, return \\$f\_n(x)\\$.

# Rules

* This is so the shortest answer in bytes wins.
* Assume only valid input will be given.
* Error should be under one ten-thousandth (±0.0001) for the test cases.

# Test Cases

```
In: 0.3 3
Out: 0.3875

In: 0.1 0
Out: 0.1

In: 0.29 4
Out: 0.375

In: 0.11 5
Out: 0.2415625

```

# Answer
> 8 votes
# APL (Dyalog Extended), ~~25~~ 27 bytes

```
{⊥1⊥1⌊⊤1∘≠⍛×\0,3⊤⍵×3*⍺}÷2*⊣

```

Try it online!

Inline tacit function, which can be used as `n f x`.

Uses the method described in Luis Mendo's MATL answer. I changed one part of the algorithm:

* This one doesn't consider integer and fractional parts separately; rather, the fractional part is included in the last digit. (e.g. the base-3 representation of 8.1 is `[2, 2.1]`.) Later, at the step where 2s are changed into 1s, all digits `≥2` are reduced by 1 instead, and **(+2 bytes)** the fractional part of the last digit is removed if its integer part is 1.

```
{⊥1⊥1⌊⊤1∘≠⍛×\0,3⊤⍵×3*⍺}÷2*⊣  ⍝ Left: n, Right: x
{                ⍵×3*⍺}  ⍝ 3^n*x
               3⊤        ⍝ Convert to base 3; last digit may have fractional part
             0,  ⍝ Prepend 0 to avoid error on ⊤ over an empty array
       1∘≠⍛×\    ⍝ Keep each digit unless at least one 1 appears somewhere on its left
      ⊤  ⍝ Convert each digit to binary
    1⌊   ⍝ Clamp all digits >1 to 1 (effectively cuts the fractional part of
         ⍝ the last digit if its integer part is 1)
  1⊥     ⍝ Treat the binary of each digit as base 1 and convert back to a number
         ⍝ Since all numbers are <3, effectively "decrement if ≥2"
 ⊥  ⍝ Treat as base 2 and convert to single number
÷2*⊣  ⍝ Divide by 2^n

```

# Answer
> 7 votes
# MATL, 33 bytes

```
3y^i*1&\3_YAt1=f"O@QJh(wkw]XB+wW/

```

Inputs are `n`, then `x`.

Try it online! Or verify all test cases.

## Approach

The code uses a non-recursive approach, based on the procedure for computing the Cantor function \\$f\_\infty(x)\\$ that appears in Wikipedia, modified so that it computes \\$f\_n(x)\\$ instead:

1. Multiply \\$x\\$ by \\$3^n\\$.
2. Decompose the result into integer part \\$M\\$ and decimal part \\$F\\$.
3. Express \\$M\\$ in base \\$3\\$. Let \\$B\\$ be the resulting sequence of up to \\$n\\$ digits from the set \\$\\{0, 1, 2\\}\\$.
4. If \\$B\\$ contains a \\$1\\$, replace every digit after the first \\$1\\$ by \\$0\\$.
5. Replace any remaining \\$2\\$s with \\$1\\$s.
6. Interpret the result as a binary number.
7. If \\$B\\$ didn't contain \\$1\\$s, add \\$F\\$.
8. Divide by \\$2^n\\$.

## Some golfing tricks

* Using a `for` loop instead of an `if` branch for step 4 saved quite a few bytes. The value for the branch condition (index of first \\$1\\$) needed to be used within the branch code (to replace subsequent digits by \\$0\\$). This is cumbersome in MATL, as the `if` branch consumes (pops) its condition. Instead, the loop solves this more elegantly: since the branch condition was either empty or a vector of indices of \\$1\\$s in \\$B\\$, it can be looped over: if it's empty the loop is simply not entered. And then the loop variable can be used within the loop code. The fact that the loop, unlike the conditional branch, may iterate *several* times (if there are more than one \\$1\\$ digit) is not harmful here, because the substitutions in step 4 are idempotent: they simply overwrite some of the previous \\$0\\$s with new \\$0\\$s.
* Step 7 is partly handled within the `for` loop. Specifically, if the loop is entered, the decimal part \\$F\\$ should not be added later on. To implement this, the loop iteration replaces \\$F\\$ (previously stored in the stack) by \\$0\\$. This is done by a round-down operation (`k`), which is convenient because it uses only 1 byte and is, again, idempotent: the result remains equal to \\$0\\$ in all iterations after the first.
* The MATL function that converts from binary to decimal (`XB`) treats any digit other than \\$0\\$ as if it were \\$1\\$, which is useful for steps 5 and 6.

## Commented code

```
3         % Step 1. Push 3
y         % Implicit input: n. Duplicate from below: pushes n below and
          % above the 3
^         % Power: gives 3^n
i*        % Input: x. Multiply: gives x*3^n
1         % Step 2. Push 1
&\        % Two-output modulus: gives modulus (F) and quotient (M)
3_YA      % Step 3. Convert to base 3, with digis 0, 1, 2
t1=       % Step 4 and part of step 7. Duplicate. Compare each entry with 1
f         % Vector (possibly empty) of indices of true values; that is,
          % positions of digit 1
"         % For each index k
  O       %   Push 0
  @Q      %   Push k+1
  Jh(     %   Write 0 at positions k+1, k+2, ..., end
  wkw     %   Swap, round down, swap. This replaces F by 0
]         % End
XB        % Steps 5 and 6. Convert from binary to decimal, with digit 2
          % interpreted as 1
+         % Part of step 7. Add F, or 0
wW/       % Step 8. Swap (brings n to top), 2 raised to that, divide
          % Implicit display

```

# Answer
> 6 votes
# APL (Dyalog Unicode), 38 bytes

```
{×⍺×1-⍵:2÷⍨(1∘≤+(1≠⌊)×(⍺-1)∇⊢-⌊)3×⍵⋄⍵}

```

Try it online!

Combines the cases of the recurrence using

$$ f\_{n+1}(x) = \frac{1}{2}\begin{cases} 0+1×f\_n(3x-0), x\in\[0,1/3) \\ 1+0×f\_n(3x-1), x\in\[1/3,2/3)\\ 1+1×f\_n(3x-2), x\in\[2/3,1\] \end{cases} $$

which can be condensed (note \\$u=3x\\$) to

$$ f\_{n+1}\left(\frac{1}{3}u\right) = \frac{1}{2}\big( (u\<1)+(\lfloor u\rfloor\neq 1)×f\_n(u-\lfloor u \rfloor)\big) $$ (since comparisons resolve to True=1 or False=0). This fails for `x=1` since then `⌊u` is 3 instead of 2. Using ceiling instead of floor would then fail for `x=0`, so it ends up shorter to check specifically for `x=1`.

```
{ ... } ⍺=n; ⍵=x
×⍺×1-⍵: ⍝ If n>0 or x≠1:
 3×⍵      ⍝ Let u=3x
  (⍺-1)∇⊢-⌊ ⍝ f(n-1, u-floor(u)) (`1∘|` ←→ `⊢-⌊`)
  (1≠⌊)×    ⍝ Multiply by 1 unless floor(u)=1
  1∘≤+      ⍝ Add 1 unless 1 > u
 2÷⍨      ⍝ Half of this
⋄       ⍝ Else:
 ⍵        ⍝ x

```

# Answer
> 5 votes
# Python 3, 54 bytes

```
f=lambda n,x:n and(1<x*3<2or x//.5+f(n-1,3*x%1))/2or x

```

Try it online!

Python 3 is used just for the `/2` to do float division; Python 2 would be a byte longer with `/2.`.

# Answer
> 4 votes
# Wolfram Language (Mathematica), 69 bytes

of course mathematica has a built-in for this: `CantorStaircase[x]` but you cannot choose `n`

```
x_~f~0:=x
x_~f~n_:=If[(y=3x)<1,f[y,n-1]/2,If[y<2,.5,.5+f[y-2,n-1]/2]]

```

Try it online!

*@JonathanAllan saved 2 bytes*

Here is also another approach from @att which is great!

# Wolfram Language (Mathematica), 57 bytes

```
If[#2<1,#,If[1<3#<2,1,(s=Boole[2#>1])+#0[3#-2s,#2-1]]/2]&

```

Try it online!

# Answer
> 4 votes
# Python 3.8 (pre-release), 62 bytes

```
f=lambda n,x:n and[f(n-1,e:=3*x),1+e//2*f(n-1,e-2)][e>1]/2or x

```

Try it online!

# Answer
> 4 votes
# Jelly, 30 bytes

```
_2çH+.
ñH¥.ç<2$?<1$?
×3çɗ⁸⁹?’}

```

A full program accepting \\$x\\$ and \\$n\\$ which prints a floating-point representation of \\$f\_n(x)\\$

**Try it online!**

# Answer
> 4 votes
# JavaScript (ES6), 45 bytes

Expects `(n)(x)`.

```
n=>g=x=>n--?((x*=3)<1?g(x):x<2||1+g(x-2))/2:x

```

Try it online!

### Commented

```
n =>                   // outer function taking n
  g = x =>             // inner recursive function taking x
    n-- ?              // decrement n; if it was not equal to 0:
      (                //   compute f_n(x):
        (x *= 3) < 1 ? //     multiply x by 3; if the result is less than 1:
          g(x)         //       use g(x)
        :              //     else:
          x < 2 ||     //       use 1 if x is less than 2
          1 + g(x - 2) //       otherwise, use 1 + g(x - 2)
      ) / 2            //   in all cases, divide the result by 2
    :                  // else:
      x                //   stop recursion and return f_0(x) = x

```

# Answer
> 4 votes
# C (gcc), <sup>~~73~~ \\$\cdots\\$ ~~69~~</sup> 68 bytes

```
float f(n,x)float x;{x*=3;x=n--?(x<1?f(n,x):x<2?:1+f(n,x-2))/2:x/3;}

```

Try it online!

*Saved 4 bytes thanks to the man himself Arnauld!!!*
*Save a byte thanks to ceilingcat!!!*

# Answer
> 3 votes
# Python 3.8, 70 ~~74~~ bytes

*1 byte saved thanks to @FryAmTheEggman*

```
f=lambda n,x:n and((1<=(t:=x*3))+f(n-1,t-2*(t>=2))*(t>=2or 1>t))/2or x

```

Try it online!

# Answer
> 3 votes
# , ~~76~~ ... ~~60~~ 58 bytes

*-6 bytes thanks to Robin Ryder, +1 byte to fix bug spotted by Neil, -2 bytes thanks to Giuseppe*

```
f=function(x,n,y=x*3)`if`(n,(min(f(y%%2,n-1),1)+!y<2)/2,x)

```

Try it online!

Un-golfed:

```
cantor=f=function(x,n){
    y=3*x                               # define y=3*x
                                        # to save characters later.
    if(n==0){ x }                       # if n==0 just return x
    else {                              # otherwise
        (
         min(                           # whichever is smaller of:
            cantor(y%%2,n-1),           # - call self using y mod 2
                                        #   (this works for the first & last thirds
                                        #   but gives a result >1 for middle third)
            1)                          # - 1 (to fix the middle third)
         +(y>=2)                        # for the top third we need to add 1 to
                                        # the result of the self call
        )
        /2                              # finally, we divide all above results by 2
    }
}

```

# Answer
> 3 votes
# Perl 5, 78 bytes

```
sub f{my$b=pop;my$a=pop;$b--?($a<1/3?f(3*$a,$b):$a<2/3?1:1+f(3*$a-2,$b))/2:$a}

```

Try it online!

# Answer
> 2 votes
# Charcoal, 35 bytes

```
Ｎθ≔↨×ＮＸ³θ³ηＩ∕↨²Ｅη∧¬№…ηκ¹§⟦ι¹⊖ι⟧ιＸ²θ

```

Try it online! Link is to verbose version of code. Based on the Wikipedia entry, I convert the `3ⁿx` to base 3, then massage the digits so that the result can be interpreted as base 2 and divided by `2ⁿ`. Takes input in the order `n`, `x`. Explanation:

```
Ｎθ

```

Input `n`.

```
≔↨×ＮＸ³θ³ηＩ∕

```

Multiply `x` by `3ⁿ` and convert it to base 3. The last entry includes any remaining fractional part.

```
Ｅη∧¬№…ηκ¹§⟦ι¹⊖ι⟧ι

```

Map over the digits. If there was a previous `1` then set this digit to zero, otherwise map the digit to itself, `1`, or subtract `1`, depending on the floor of the digit. This ensures that the last digit (with the remaining fractional part) is converted correctly.

```
Ｉ∕↨²...Ｘ²θ

```

Convert from base 2, divide by `2ⁿ`, and output the final decimal as a string.

Previous 34-byte solution did not work for `x=1`, as it only considered the decimal part of `x`:

```
Ｎθ≔×ＮＸ³θη≔⁻η⌊ηζＦθ≔⊘§⟦ζ¹⊕ζ⟧∕ηＸ³ιζＩζ

```

Try it online! Link is to verbose version of code. Takes input in the order `n`, `x`. Explanation:

```
Ｎθ

```

Input `n`.

```
≔×ＮＸ³θη

```

Multiply `x` by `3ⁿ`.

```
≔⁻η⌊ηζ

```

Take the decimal part of that.

```
Ｆθ

```

Loop `n` times.

```
≔⊘§⟦ζ¹⊕ζ⟧∕ηＸ³ιζ

```

Depending on the next base 3 digit of the above product, replace the decimal part with half of itself, half of 1, or half of the sum.

```
Ｉζ

```

Output the final decimal as a string.

# Answer
> 1 votes
# 05AB1E, 31 bytes

```
3Im*1‰`s3в¹£εTYèsi1V]2βY≠i+}¹o/

```

Takes the loose inputs in the order \\$n,x\\$.

Port of *@LuisMendo*'s MATL answer, so make sure to upvote him as well!

Try it online or verify all test cases.

**Explanation:**

```
3Im              # Push 3 to the power of the first input-integer
   *             # Multiply it by the (implicit) input-decimal
    1‰           # Get the divmod-1 to split the integer and decimal parts
      `s         # Pop and push them separated to the stack in reversed order
3в               # Convert the integer part to base-3 as list
  ¹£             # Only leave the first input-integer amount of base-3 digits
    ε            # Map this list to:
     T           #  Push 10
      Yè         #  Index `Y` into this
                 #  (`Y` is 2 by default, which wraps modulair indices into the 1)
     si          #  If the current digit we're mapping over is 1:
       1V        #   Set `Y` to 1
    ]            # Close both the if-statement and map
     2β          # Convert the resulting list from base-2 to an integer
       Y≠i }     # If `Y` is NOT 1:
          +      #  Add the decimal part that's still on the stack
            ¹o/  # And divide this by 2 to the power the first input-integer
                 # (after which the result is output implicitly)

```

# Answer
> 0 votes
# PARI/GP, 71 bytes

Golfed version. Attempt This Online!

```
f(x,n)={y=3*x;if(n==0,x,if(y<1,f(y,n-1)/2,if(y<2,.5,.5+f(y-2,n-1)/2)))}

```

Ungolfed version. Attempt This Online!

```
f(x, n) = {
  my(y = 3*x);
  if(n == 0, x,
    if(y < 1, f(y, n-1)/2,
      if(y < 2, .5, .5 + f(y-2, n-1)/2)
    )
  );
}

print(f(0.3, 3));
print(f(0.1, 0));
print(f(0.29, 4));
print(f(0.11, 5));

```

---
Tags: code-golf, math, fractal
---