Print the phrase "And she said, 'But that's his.'" using only the alphabet

50

9

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.

Blue-Maned Hawk

Posted 2019-06-12T04:48:48.470

Reputation: 639

What about whitespace in output? (leading/trailing?) – attinat – 2019-06-13T07:04:13.067

Output must be exactly what was specified. Usually an optional trailing newline is allowed. – mbomb007 – 2019-06-13T16:19:02.853

2Darn, 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. – Draco18s no longer trusts SE – 2019-06-13T16:23:19.290

What about control characters? (escape, control, alt, etc.)? – Rɪᴋᴇʀ – 2019-06-13T21:11:53.213

11(programmer-of (language 'lisp)) dislikes this. – MatthewRock – 2019-06-13T22:05:59.637

4Have 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. – brhfl – 2019-06-14T18:01:25.433

1

Can you clarify if extra whitespace in the output is allowed? Like extra trailing newlines? Or only whitespace in the source, plus alphabetic characters. There's a Befunge answer that prints with extra an trailing newline.

– Peter Cordes – 2019-06-15T00:24:25.090

Answers

75

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]

a stone arachnid

Posted 2019-06-12T04:48:48.470

Reputation: 1 053

103Whitespace is completely allowed. I see you have taken this literally. – Benjamin Urquhart – 2019-06-13T01:36:13.203

3You 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. – Kevin Cruijssen – 2019-06-13T07:43:21.703

1318 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. :) – Kevin Cruijssen – 2019-06-13T07:46:17.727

1

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

– Kevin Cruijssen – 2019-06-13T07:59:29.627

3

Ok, now I'm done. :) 265 bytes (or here with highlighting). Added some additional copies. (Here the relevant Whitespace tip.)

– Kevin Cruijssen – 2019-06-13T08:11:50.023

62

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

Grimmy

Posted 2019-06-12T04:48:48.470

Reputation: 12 521

27Not knowing Perl, it looks like you just tried to type the sentence, but got in multiple fights with your cat in the process – popctrl – 2019-06-14T14:36:13.457

2This 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. – Silvio Mayolo – 2019-06-14T20:57:34.833

1Related, 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. – Silvio Mayolo – 2019-06-14T20:58:59.727

33

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

mbomb007

Posted 2019-06-12T04:48:48.470

Reputation: 21 944

5This is the proper counterpoint to the whitespace solution! Have a +1 from me, I also appreciate the generating program... – Francesco – 2019-06-13T12:40:24.177

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.) – Nitrodon – 2019-06-14T16:30:14.507

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. – Nitrodon – 2019-06-14T16:32:35.087

That's a really good idea. It's so hard to think of ><> in this way. It's like coding with BF – mbomb007 – 2019-06-14T16:34:27.060

I posted my own answer: https://codegolf.stackexchange.com/a/186916/69059

– Nitrodon – 2019-06-14T17:12:28.140

28

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"

Artelius

Posted 2019-06-12T04:48:48.470

Reputation: 421

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. – gastropner – 2019-06-14T04:44:06.390

1I want to see a fully alphabetic binary instead. :-) – peter ferrie – 2019-06-14T21:07:34.260

I was initially thinking the answer was the resulting machine code, but it actually is the asm source. We can't use add/sub because 2-operand instructions need a comma, not because of their opcodes. I thought the diff @gastropner saw was a bug because the 1-byte short form of inc ax is 0x40 (ASCII @), while the 2-byte (opcode + modrm) inc al is FE C0. but neither are ASCII. inc any other 16-bit register is fine: the 1-byte short forms of inc/dec use the 0x40 .. 0x4f range of opcodes (with register number in the low 3 bits). AX = 0, so we get 0x40. ASCII A is 0x41. – Peter Cordes – 2019-06-14T23:10:21.827

(I normally golf in x86 machine code, not asm source. IDK if it would be feasible to write a machine-code answer. It might need to be self-modifying code to create the opcode for syscall (x86-64) or int 21h (DOS printing). Oh, anatoly has already posted such an answer :) – Peter Cordes – 2019-06-14T23:16:55.710

Shouldn't the code end with a RET or otherwise exit cleanly? Or does NASM handle this for you? – Oliphaunt - reinstate Monica – 2019-06-15T23:28:10.543

@Oliphaunt the challenge didn't say anything about terminating... but yes you could add a RET. – Artelius – 2019-06-16T10:45:12.977

1If 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. – gastropner – 2019-06-17T02:55:12.220

1@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 – Artelius – 2019-06-17T06:37:26.170

1@PeterCordes now this one is self-modifying! – Artelius – 2019-06-21T01:09:24.850

@Artelius: cool. And re: language: every assembler is basically a different language from a family of related languages, if you're talking about the asm source. So the language of this answer is 8086 IBM PC assembly language (DEBUG.COM) IMO. "Porting" it to other assembly dialects may be trivial or not :P Or after your last update, "8086 IBM PC assembly language (NASM)". – Peter Cordes – 2019-06-21T01:16:33.843

This would be a better answer if you explain how it actually prints the string on the screen. I see a b800 in there, the segment value for the base of VGA memory, assuming text mode. A quick mention of that in the English text of how the answer works would be a good idea. – Peter Cordes – 2019-06-21T01:24:59.727

A better table for opcodes is referenced here: https://stackoverflow.com/a/32487675/509868

– anatolyg – 2019-06-30T16:23:45.000

@anatolyg I beg to differ. Doesn't reference the actual registers or the argument format. – Artelius – 2019-07-02T00:38:47.573

23

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.

bb94

Posted 2019-06-12T04:48:48.470

Reputation: 1 831

11078 bytes – Jo King – 2019-06-13T14:12:47.247

By the way, @JoKing, did you search for the shorter expressions by hand or did you use a program to help? – bb94 – 2019-06-13T17:08:01.680

1By hand I'm afraid. An algorithmic way probably wouldn't be too hard – Jo King – 2019-06-14T00:27:25.623

1242 bytes – Grimmy – 2019-06-14T16:11:16.347

@Grimy Clever, but unfortunately only possible because the Zero Width Space you're using is not a whitespace character – Jo King – 2019-06-15T13:38:18.570

17

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.

Stephen

Posted 2019-06-12T04:48:48.470

Reputation: 12 293

This is the shortest one yet. I think you could win! – Blue-Maned Hawk – 2019-06-14T03:18:56.907

Too bad how this language is presented in a monospaced font… – Hello Goodbye – 2019-11-22T16:40:28.950

14

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);
}

anatolyg

Posted 2019-06-12T04:48:48.470

Reputation: 10 719

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. – Cody Gray – 2019-06-13T22:43:01.013

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. – anatolyg – 2019-06-13T23:13:08.357

1@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. – gastropner – 2019-06-14T05:42:03.027

Doesn't char 0xff violate "No punctuation or non-alphabetic characters whatsoever"? – val says Reinstate Monica – 2019-06-14T15:14:03.507

https://en.wikipedia.org/wiki/Code_page_437 – anatolyg – 2019-06-14T17:28:41.863

The question says you have to print output, not return a string. You should be able to tailcall a WinAPI DLL function, right? Maybe the caller needs to pass a pointer to a print function (justification: makes this function nice and generic :) Then you can push that pointer on the stack (below or above your own return address) and jmp to it? Maybe we can construct a pointer in another register that lets us access [esp-4] with an actual addressing mode of jmp [ecx+32]. – Peter Cordes – 2019-06-15T00:17:23.297

Or port to Linux (int 80h or syscall) or DOS (int 21h) or bootloader (BIOS or store directly to VGA RAM). You would need self-modifying code to create the code bytes for int 0x80 (CD 80) or syscall (0F 05), or sysenter (0F 34). – Peter Cordes – 2019-06-15T00:20:40.960

13

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.

Grimmy

Posted 2019-06-12T04:48:48.470

Reputation: 12 521

11

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.

histocrat

Posted 2019-06-12T04:48:48.470

Reputation: 20 600

Beautiful.... I don't understand how sum size gets the sum modulo its size, but everything else checks out! – Value Ink – 2019-06-13T18:50:58.573

I put that a bit lazily, it's actually passing in the size of the string as the optional argument to the sum method.

– histocrat – 2019-06-13T19:03:08.293

11

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

Nitrodon

Posted 2019-06-12T04:48:48.470

Reputation: 9 181

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. – Nitrodon – 2019-06-16T17:44:06.383

8

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

Esolanging Fruit

Posted 2019-06-12T04:48:48.470

Reputation: 13 542

1You can do base conversions with digits outside of the usual range for the base, such as HYbYCtYbc, HYbXAtYbc and HYbXBtYbc. – Nitrodon – 2019-06-21T15:59:13.270

7

Stax, 133 95 84 79 bytes

AHHvcAvSVvNvXvsrDhYcvxvZLcHxVahyvxxZVvHVChAHHvVAHhvZAJyVahxvVvDhZyvxvAJZcASVAhL

Run and debug it

recursive

Posted 2019-06-12T04:48:48.470

Reputation: 8 616

7

Deadfish~, 943 bytes

iiisdsiciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiicddddddddddcddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsddddddcdddddddddddcdddcdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsddddddcddddddddddddddddddciiiiiiiicdddddcddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddciiiiiiiciiiiiiiiiiiiiiiiiiiiiiiiiiiciiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiicdcddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddddddddddddddddsdddddcddddddddddddcdddddddciiiiiiiiiiiiiiiiiiicdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddddddddddddddddddsddddddcdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcddddddddddddddddddddddsiiiiciciiiiiiiiiicdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddcdddddddc

Try it online!

No loops allowed :(

a stone arachnid

Posted 2019-06-12T04:48:48.470

Reputation: 1 053

7

evil, 198 bytes

aeeeannkhhwzuuuuuueaeuekwuuuuuuuuuunkhwzaeeeeehknwgueeywguuuuuuhhknnwuuuwhgwpwnngheeuwguuuuuwngwzaeeeaaaeeeeeewhhgwnguuuueewnngawpaawuwnngwpawhgwhhgeeuwpawhguuuueewpwhgwhgwawpwnngaaaaaaeeeewguuuueew

Try it online!

This was quite fun.

HyperNeutrino

Posted 2019-06-12T04:48:48.470

Reputation: 26 575

6

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)

Sanchises

Posted 2019-06-12T04:48:48.470

Reputation: 8 530

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... – Sanchises – 2019-06-12T11:23:49.957

I'd like to try, but it will have to wait. Answering this seems to take a lot of time! – Luis Mendo – 2019-06-12T11:24:43.070

1@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. – Sanchises – 2019-06-12T11:26:01.530

My attempt. I didn't look at yours, so the approaches are hopefully different – Luis Mendo – 2019-06-12T23:21:26.937

@LuisMendo I completely forgot that U means ^2, that could've saved me quite a few bytes... – Sanchises – 2019-06-13T08:29:51.550

6

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

Luis Mendo

Posted 2019-06-12T04:48:48.470

Reputation: 87 464

1Very 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. – Sanchises – 2019-06-13T08:27:41.013

5

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

Shaggy

Posted 2019-06-12T04:48:48.470

Reputation: 24 623

Nice solution. You can save a byte by replacing the first line with Qc dGaB – Embodiment of Ignorance – 2019-06-24T02:12:25.050

5

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.

brhfl

Posted 2019-06-12T04:48:48.470

Reputation: 1 291

+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? – seshoumara – 2019-06-14T14:30:12.957

@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. – brhfl – 2019-06-14T14:54:57.513

4

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

Galen Ivanov

Posted 2019-06-12T04:48:48.470

Reputation: 13 815

1The question was clarified; they removed the interesting part from it. – anatolyg – 2019-06-13T13:06:25.827

@anatolyg Thanks, I stil need it for ', so the 272 bytes solution is the same. – Galen Ivanov – 2019-06-13T13:15:05.640

4

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!

2xsaiko

Posted 2019-06-12T04:48:48.470

Reputation: 699

3

AlphaBeta, 180 177 175 163 bytes

cccaaggtFgDILrFigggDLjDLCLigggggDLjhDLhhhDLCLiggggDLjjggDLihhDLhhhhhDLcaaCLdbbCLcbbbCLHgDLiiiiigDLhDLdaaaCLDLjhhDLjgggDLiihDLcbbbCLhDLdaaaCLjhDLgDLiDLcaaaaCLdaaaCL

Try it online!

WIP

Emigna

Posted 2019-06-12T04:48:48.470

Reputation: 50 798

3

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

OrangeCherries

Posted 2019-06-12T04:48:48.470

Reputation: 321

3

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:

wakekekaayyeapwayydayybyapayybyapycyabcyaayycayyba

Try it online!


Explanation:

The instruction pointer moves as follows:IP path

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.

attinat

Posted 2019-06-12T04:48:48.470

Reputation: 3 495

Isn't only one trailing newline allowed? – Delioth – 2019-06-13T17:45:42.423

The post states "Whitespace is completely allowed". I think it's cool to abuse this wording to justify trailing newlines! – anatolyg – 2019-06-13T18:21:29.783

3

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.

seshoumara

Posted 2019-06-12T04:48:48.470

Reputation: 2 878

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. – brhfl – 2019-06-13T23:31:19.640

@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. – seshoumara – 2019-06-14T03:44:35.283

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... – brhfl – 2019-06-14T13:36:23.783

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! – brhfl – 2019-06-14T14:20:08.323

3

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

ErikF

Posted 2019-06-12T04:48:48.470

Reputation: 2 149

This isn't assembly, this is machine code... – Artelius – 2019-06-16T10:27:25.557

@Artelius Fair enough. I've updated the description. – ErikF – 2019-06-16T12:55:07.350

2

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.

randomdude999

Posted 2019-06-12T04:48:48.470

Reputation: 789

2

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)

peter ferrie

Posted 2019-06-12T04:48:48.470

Reputation: 804

1

Japt, 74 bytes

HdEz
iHdE isiiihiSisiUitiaihitiSitiuibu iUiSiHdC idiiiaisiSieihisiSidiniau

Try it

Oliver

Posted 2019-06-12T04:48:48.470

Reputation: 7 160

1

05AB1E, 145 121 109 bytes

TnVYTOUXZxNJTZXTZZZXYTYxMNYTTMNNNYRYNNYNNNNYTXZMNNYxXRZZZXTYXRZZXZYxTRMRNXRMRMXNNYxYMRNTYxTRYNTZMYXRXXXTZJCXB

Try it online!

Grimmy

Posted 2019-06-12T04:48:48.470

Reputation: 12 521

0

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

anatolyg

Posted 2019-06-12T04:48:48.470

Reputation: 10 719