Post Reply 
(42S) challenge: repeat a character N times
01-15-2018, 12:38 PM
Post: #1
(42S) challenge: repeat a character N times
Suppose the alpha register contains a single character, and you want it duplicated N times, 0<=N<=44. This will come in handy when drawing lines on the DM-42 ;-)

A simple way would be

Code:
>LBL "$N"
 ASTO ST L
 CLA
 X=0?
 GTO 00
>LBL 02
 ARCL ST L
 DSE ST X
 GTO 02
>LBL 00
 Rv
 END

But that loops 44 times for the longest string. Can you do better & still preserve Y and Z?

So, In:
A: char
Z: z
Y: y
X: N

Out:
A: N times char
Y: z
X: y

My current attempt's worst case is about 2.5 times faster than the above, and still reasonably short at 49 bytes.

Cheers, Werner
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(42S) challenge: repeat a character N times - Werner - 01-15-2018 12:38 PM



User(s) browsing this thread: 1 Guest(s)