MSX Basic Question

Pagina 2/2
1 |

Van kanima

Master (193)

afbeelding van kanima

24-06-2017, 01:47

Even slightly shorter:

10 A$="manuel-san wa ichiban ookii hito desu"
20 A=INSTR(A$," "):IFATHENA$=LEFT$(A$,A-1)+MID$(A$,A+1):GOTO20
30 PRINTA$

Or this version which is slightly longer, but uses a FOR/NEXT loop instead of a GOTO statement. This means it doesn't need its own line, which could be useful for 10-line BASIC contests etc:

10 A$="manuel-san wa ichiban ookii hito desu":FORA=1TO0STEP-1:A=INSTR(A$," "):A$=LEFT$(A$,A+(A>0))+MID$(A$,A+1):NEXT:PRINTA$

Van Manuel

Ascended (18131)

afbeelding van Manuel

24-06-2017, 09:19

I don't think I have anything to add here Smile So their strategy is to 'eat' the string.

Van Latok

msx guru (3836)

afbeelding van Latok

24-06-2017, 22:18

Thanks guys! And indeed, alter A$ is the way to go. Learnt something. Great!

Van Manuel

Ascended (18131)

afbeelding van Manuel

24-06-2017, 22:28

It's the way to go for the shortest implementation, but probably not for the fastest... The string is copied around a lot like this...

Pagina 2/2
1 |