45
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ What about whitespace in output? (leading/trailing?) \$\endgroup\$ – attinat Jun 13 at 7:04
  • \$\begingroup\$ Output must be exactly what was specified. Usually an optional trailing newline is allowed. \$\endgroup\$ – mbomb007 Jun 13 at 16:19
  • 2
    \$\begingroup\$ Darn, my esolang can't complete because there's no ability to produce output with only a-zA-Z. In theory I could use write and Eval to create the necessary instructions, but none of +-*,%'" can be constructed without using (at least) one of +-*,%'"0-9. \$\endgroup\$ – Draco18s Jun 13 at 16:23
  • 9
    \$\begingroup\$ (programmer-of (language 'lisp)) dislikes this. \$\endgroup\$ – MatthewRock Jun 13 at 22:05
  • 3
    \$\begingroup\$ Have to admit, I didn't think this was particularly interesting at first, but the combination of repeated and unique characters really made it something fun to optimize (especially on a stack language!). Very nice. \$\endgroup\$ – brhfl Jun 14 at 18:01

27 Answers 27

67
\$\begingroup\$

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]
\$\endgroup\$
  • 91
    \$\begingroup\$ Whitespace is completely allowed. I see you have taken this literally. \$\endgroup\$ – Benjamin Urquhart Jun 13 at 1:36
  • 3
    \$\begingroup\$ You beat me to it.. Quite a few things can be golfed, though. :) You can remove the trailing NNN to exit, since it already stops with an error when you're doing the add before the print_char, so it won't even come after the Jump_to_Label. Also, why store the 63 at the start and retrieve it in the loop? You could just push it before adding instead. And, why is the Label-nr TTSSSSTN? A Label can even be empty, so just NSSN to create the label and NSNN to jump to the label is sufficient when you're only using one Label. \$\endgroup\$ – Kevin Cruijssen Jun 13 at 7:43
  • 1
    \$\begingroup\$ 318 bytes with the changes I proposed above. Here is the same program with added highlighting. And how did you deducted the constant value 63? I'm not 100% sure it's the shortest constant possible here. If it is, something is wrong with my constant generating program I wrote for an earlier challenge. :) \$\endgroup\$ – Kevin Cruijssen Jun 13 at 7:46
  • 1
    \$\begingroup\$ Yep, I was right. Constant 102 is the most efficient: 281 bytes (or here with highlighting). (NOTE: I've also used one copy to save 4 bytes for the space between ehs dnA (copied from the space between dias ehs). \$\endgroup\$ – Kevin Cruijssen Jun 13 at 7:59
  • 2
    \$\begingroup\$ Ok, now I'm done. :) 265 bytes (or here with highlighting). Added some additional copies. (Here the relevant Whitespace tip.) \$\endgroup\$ – Kevin Cruijssen Jun 13 at 8:11
53
\$\begingroup\$

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 $_.

\$\endgroup\$
  • 17
    \$\begingroup\$ Not knowing Perl, it looks like you just tried to type the sentence, but got in multiple fights with your cat in the process \$\endgroup\$ – popctrl Jun 14 at 14:36
  • 2
    \$\begingroup\$ This may be the most beautiful piece of code I've ever seen written on this website, and I say that as someone who knows Perl. \$\endgroup\$ – Silvio Mayolo Jun 14 at 20:57
  • \$\begingroup\$ Related, but you can replace print with say for -2 characters. Current meta consensus says command line flags like -M5.010 don't count toward byte count. \$\endgroup\$ – Silvio Mayolo Jun 14 at 20:58
32
\$\begingroup\$

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

\$\endgroup\$
  • 5
    \$\begingroup\$ This is the proper counterpoint to the whitespace solution! Have a +1 from me, I also appreciate the generating program... \$\endgroup\$ – Francesco Jun 13 at 12:40
  • \$\begingroup\$ The last section can be removed entirely with careful use of p: create a 59 on the stack while moving up from the space to the s in said, then place it in the code on the way down from d to ,. (Note that (15,15) has 15 by this point.) \$\endgroup\$ – Nitrodon Jun 14 at 16:30
  • \$\begingroup\$ Actually, you can abuse l and p to put several useful characters in the (10,10)-(15,15) rectangle, then retrieve them with g where its more convenient. \$\endgroup\$ – Nitrodon Jun 14 at 16:32
  • \$\begingroup\$ That's a really good idea. It's so hard to think of ><> in this way. It's like coding with BF \$\endgroup\$ – mbomb007 Jun 14 at 16:34
  • \$\begingroup\$ I posted my own answer: codegolf.stackexchange.com/a/186916/69059 \$\endgroup\$ – Nitrodon Jun 14 at 17:12
24
\$\begingroup\$

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:

Sample output

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"
\$\endgroup\$
  • \$\begingroup\$ Hm. I am getting different .COM files from the two assembly sources, starting at offset 0x3e. Edit - Nvm found the difference: Line 117 in the commented version is INC AX while the uncommented is INC AL. \$\endgroup\$ – gastropner Jun 14 at 4:44
  • \$\begingroup\$ I want to see a fully alphabetic binary instead. :-) \$\endgroup\$ – peter ferrie Jun 14 at 21:07
  • 1
    \$\begingroup\$ If you are comfortable locking down NASM as the assembler of choice, you can create labels by doing label1 db on a line of its own. It will yield a warning, but no error. \$\endgroup\$ – gastropner Jun 17 at 2:55
  • 1
    \$\begingroup\$ @gastropner well that would just make it too easy. :P Didn't know about that, thanks! Maybe I should rename my language as "something you can feed into DEBUG.COM". Which incidentally I used to debug this. xD \$\endgroup\$ – Artelius Jun 17 at 6:37
  • 1
    \$\begingroup\$ @PeterCordes now this one is self-modifying! \$\endgroup\$ – Artelius Jun 21 at 1:09
21
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 1078 bytes \$\endgroup\$ – Jo King Jun 13 at 14:12
  • \$\begingroup\$ By the way, @JoKing, did you search for the shorter expressions by hand or did you use a program to help? \$\endgroup\$ – bb94 Jun 13 at 17:08
  • 1
    \$\begingroup\$ By hand I'm afraid. An algorithmic way probably wouldn't be too hard \$\endgroup\$ – Jo King Jun 14 at 0:27
  • 1
    \$\begingroup\$ 242 bytes \$\endgroup\$ – Grimy Jun 14 at 16:11
  • \$\begingroup\$ @Grimy Clever, but unfortunately only possible because the Zero Width Space you're using is not a whitespace character \$\endgroup\$ – Jo King Jun 15 at 13:38
14
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ This is the shortest one yet. I think you could win! \$\endgroup\$ – Blue-Maned Hawk Jun 14 at 3:18
12
\$\begingroup\$

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);
}
\$\endgroup\$
  • \$\begingroup\$ This doesn't appear to be fully golfed to me. Surely you would save several bytes by using loops, rather than repeating a series of identical instructions. All of that dec ecx+and [ecx+32], ah stuff can be factored out. \$\endgroup\$ – Cody Gray Jun 13 at 22:43
  • \$\begingroup\$ You are welcome to try. This is the best I could do; I'd be happy to see a different approach. I decided to abandon the idea of loops when I saw that they require a negative jump offset. Maybe this restriction can be solved in a creative way - I don't know how. \$\endgroup\$ – anatolyg Jun 13 at 23:13
  • 1
    \$\begingroup\$ @anatolyg It might come down to what your test environment's stance on self-modifying code is. Or its opinions on executing code you've built on the stack. \$\endgroup\$ – gastropner Jun 14 at 5:42
  • \$\begingroup\$ Doesn't char 0xff violate "No punctuation or non-alphabetic characters whatsoever"? \$\endgroup\$ – val Jun 14 at 15:14
  • \$\begingroup\$ en.wikipedia.org/wiki/Code_page_437 \$\endgroup\$ – anatolyg Jun 14 at 17:28
12
\$\begingroup\$

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.

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

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.

\$\endgroup\$
  • \$\begingroup\$ Beautiful.... I don't understand how sum size gets the sum modulo its size, but everything else checks out! \$\endgroup\$ – Value Ink Jun 13 at 18:50
  • \$\begingroup\$ I put that a bit lazily, it's actually passing in the size of the string as the optional argument to the sum method. \$\endgroup\$ – histocrat Jun 13 at 19:03
9
\$\begingroup\$

><>, 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.

\$\endgroup\$
  • \$\begingroup\$ After further thought, I think I can make column 9 work by spending a byte on r to move the alignment wherever I want. However, golfing this program hurts my brain a bit. \$\endgroup\$ – Nitrodon Jun 16 at 17:44
7
\$\begingroup\$

evil, 198 bytes

aeeeannkhhwzuuuuuueaeuekwuuuuuuuuuunkhwzaeeeeehknwgueeywguuuuuuhhknnwuuuwhgwpwnngheeuwguuuuuwngwzaeeeaaaeeeeeewhhgwnguuuueewnngawpaawuwnngwpawhgwhhgeeuwpawhguuuueewpwhgwhgwawpwnngaaaaaaeeeewguuuueew

Try it online!

This was quite fun.

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

Stax, 133 95 84 79 bytes

AHHvcAvSVvNvXvsrDhYcvxvZLcHxVahyvxxZVvHVChAHHvVAHhvZAJyVahxvVvDhZyvxvAJZcASVAhL

Run and debug it

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

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 | '.
\$\endgroup\$
  • 1
    \$\begingroup\$ You can do base conversions with digits outside of the usual range for the base, such as HYbYCtYbc, HYbXAtYbc and HYbXBtYbc. \$\endgroup\$ – Nitrodon Jun 21 at 15:59
6
\$\begingroup\$

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)
\$\endgroup\$
  • \$\begingroup\$ Huh - I really thought using v would mess with the h I had earlier. Guess I should've that instead of just assuming. Also, thanks for the heads-up, overzealous deleting happened. I'm curious to see if you can do better than this... \$\endgroup\$ – Sanchises Jun 12 at 11:23
  • \$\begingroup\$ I'd like to try, but it will have to wait. Answering this seems to take a lot of time! \$\endgroup\$ – Luis Mendo Jun 12 at 11:24
  • 1
    \$\begingroup\$ @LuisMendo Yup. Took me an hour or so to make this, and this only includes very local optimisation. I'm sure one can do better with a bit more of a global look at things. \$\endgroup\$ – Sanchises Jun 12 at 11:26
  • \$\begingroup\$ My attempt. I didn't look at yours, so the approaches are hopefully different \$\endgroup\$ – Luis Mendo Jun 12 at 23:21
  • \$\begingroup\$ @LuisMendo I completely forgot that U means ^2, that could've saved me quite a few bytes... \$\endgroup\$ – Sanchises Jun 13 at 8:29
6
\$\begingroup\$

Deadfish~, 943 bytes

iiisdsiciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiicddddddddddcddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsddddddcdddddddddddcdddcdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsddddddcddddddddddddddddddciiiiiiiicdddddcddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddciiiiiiiciiiiiiiiiiiiiiiiiiiiiiiiiiiciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiicdcddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsdddddcddddddddddddcdddddddciiiiiiiiiiiiiiiiiiicdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddddddddddddddddddsddddddcdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddddddddddddsiiiiciciiiiiiiiiicdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddc

Try it online!

No loops allowed :(

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

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).
\$\endgroup\$
  • 1
    \$\begingroup\$ Very nice! Clever touch using O instead of KWE for spaces. And you confirmed my suspicion that it's probably better to sacrifice another clipboard H. \$\endgroup\$ – Sanchises Jun 13 at 8:27
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ +1 Nice idea to use a to recreate those operators, then to call them with x. This shows the data-is-code behavior of dc. When I have time I'll apply your latest trick of storing data into parameters, instead of registers. Do you think we could get an even shorter dc solution by abusing the way P works to print more letters at a time if we're lucky to input the needed huge number using hex only? \$\endgroup\$ – seshoumara Jun 14 at 14:30
  • \$\begingroup\$ @seshoumara It's possible, though my attempts at doing that with other challenges suggests that it's unlikely simply because those values become large quickly. Just to get the first two letters, 'An', we need to P 16750 or 0x416E. If we just happened to get lucky and one of the substrings was comprised exclusively of values A-F, then that might get us a shortcut. That would be some luck, though! Otherwise we'd be either inputting large numbers somehow, coming up with them somehow, or doing a lot of adding and multiplying by 256. Which seems... chunkier than a bunch of Ps. \$\endgroup\$ – brhfl Jun 14 at 14:54
4
\$\begingroup\$

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.

Red console

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

\$\endgroup\$
  • 1
    \$\begingroup\$ The question was clarified; they removed the interesting part from it. \$\endgroup\$ – anatolyg Jun 13 at 13:06
  • \$\begingroup\$ @anatolyg Thanks, I stil need it for ', so the 272 bytes solution is the same. \$\endgroup\$ – Galen Ivanov Jun 13 at 13:15
4
\$\begingroup\$

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!

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

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
\$\endgroup\$
  • \$\begingroup\$ Nice solution. You can save a byte by replacing the first line with Qc dGaB \$\endgroup\$ – Embodiment of Ignorance 2 days ago
3
\$\begingroup\$

AlphaBeta, 180 177 175 163 bytes

cccaaggtFgDILrFigggDLjDLCLigggggDLjhDLhhhDLCLiggggDLjjggDLihhDLhhhhhDLcaaCLdbbCLcbbbCLHgDLiiiiigDLhDLdaaaCLDLjhhDLjgggDLiihDLcbbbCLhDLdaaaCLjhDLgDLiDLcaaaaCLdaaaCL

Try it online!

WIP

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

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

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

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.

\$\endgroup\$
  • \$\begingroup\$ I came up with a dc solution that uses arithmetic by creating macros for +, -, and *. It’s 262 bytes. I’ll keep trying to optimize it to try to get competitive, but I must say I’m disappointed it’s so much fatter than the (relatively) naïve solution. \$\endgroup\$ – brhfl Jun 13 at 23:31
  • \$\begingroup\$ @brhfl Yeah, dc gets verbose pretty fast. Even so, I would very much like to see your solution, so post it! In the meantime, I'm also thinking of either golfing the current method more, using a program, or coming up with another idea for dc. \$\endgroup\$ – seshoumara Jun 14 at 3:44
  • \$\begingroup\$ I managed to tie 240! And I wouldn't be surprised if I was able to golf off one or two more bytes, but... it's a much more obtuse approach for little/no gain. Anyway, I posted it down there somewhere... \$\endgroup\$ – brhfl Jun 14 at 13:36
  • \$\begingroup\$ I got down to 222 by replacing some of my most common registers w/ input/output radix and precision; saves one byte on the store and one byte on every load... Since numbers are immaterial, it doesn't affect anything... You might be able to use this to your advantage as well! \$\endgroup\$ – brhfl Jun 14 at 14:20
3
\$\begingroup\$

Befunge-98 (FBBI), 125 124 bytes

wab









And she said   But that s his












wakekekeayyeap     ayybyapayybyapbyacyabayycapcyaayyba
a



b
wayapoq

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

The output includes 10 trailing newlines.

Having only one trailing newline in output costs +1 byte by replacing an a with dy as so:

wakekekeayyeap     ayybyapayybyapbydycyabayycapcyaayyba

Try it online!


Explanation:

The instruction pointer moves as follows:IP path

The program modifies the text on line 11 (y=10) until it has the desired special characters, then outputs it to file. The only integers directly available are 10...15, which correspond to a...f, respectively. Thus, this heavily abuses arguments to y "Get SysInfo" which luckily are the ones accessible using those numbers:

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

23* stack size

ayy when y=23 allows for repeated access to the stack size, which is then used to generate character codes.

\$\endgroup\$
  • \$\begingroup\$ Isn't only one trailing newline allowed? \$\endgroup\$ – Delioth Jun 13 at 17:45
  • \$\begingroup\$ The post states "Whitespace is completely allowed". I think it's cool to abuse this wording to justify trailing newlines! \$\endgroup\$ – anatolyg Jun 13 at 18:21
3
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ This isn't assembly, this is machine code... \$\endgroup\$ – Artelius Jun 16 at 10:27
  • \$\begingroup\$ @Artelius Fair enough. I've updated the description. \$\endgroup\$ – ErikF Jun 16 at 12:55
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Japt, 74 bytes

HdEz
iHdE isiiihiSisiUitiaihitiSitiuibu iUiSiHdC idiiiaisiSieihisiSidiniau

Try it

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.