The Scrambler
Remove characters from a string one at a time to build the full scramble algorithm.
You can slice strings, measure them, and build new ones character by character. Now combine all three into the scramble algorithm — the heart of the game.
Removing a Character
10 LET w$="planet"
20 PRINT "Start: ";w$
30 LET p=3
40 PRINT "Remove letter ";p;": ";w$(p TO p)
50 LET w$=w$(1 TO p-1)+w$(p+1 TO LEN w$)
60 PRINT "Result: ";w$
70 PRINT
80 LET p=1
90 PRINT "Remove letter ";p;": ";w$(p TO p)
100 LET w$=w$(1 TO p-1)+w$(p+1 TO LEN w$)
110 PRINT "Result: ";w$
To remove the character at position p from w$, take everything before it and everything after it, then join them:
LET w$ = w$(1 TO p - 1) + w$(p + 1 TO LEN w$)
If w$ = "planet" and p = 3, you get w$(1 TO 2) + w$(4 TO 6) — “pl” + “net” = “plnet”. The “a” is gone.
Edge cases work safely on the Spectrum. When p is 1, w$(1 TO 0) returns an empty string. When p equals LEN w$, w$(p + 1 TO LEN w$) also returns empty. No crashes, no special handling needed.
The Full Scramble
5 BORDER 0: PAPER 0: INK 7: CLS
10 FOR i=0 TO 31
12 PRINT AT 0,i; PAPER 2;" "
14 NEXT i
16 PRINT AT 0,8; PAPER 2; INK 7; BRIGHT 1;" WORD SCRAMBLE "
20 PRINT AT 4,10; INK 5;"Unscramble:"
30 LET w$="trumpet"
32 LET t$=w$
34 LET s$=""
36 IF LEN t$=0 THEN GO TO 44
38 LET p=INT (RND*LEN t$)+1
40 LET s$=s$+t$(p TO p)
42 LET t$=t$(1 TO p-1)+t$(p+1 TO LEN t$)
43 GO TO 36
44 IF s$=w$ THEN GO TO 32
50 LET c=(32-LEN s$*2)/2
52 FOR i=1 TO LEN s$
54 PRINT AT 8,c+i*2-2; PAPER 1;" "
56 PRINT AT 9,c+i*2-2; PAPER 1;" "
58 NEXT i
60 FOR i=1 TO LEN s$
62 PRINT AT 8,c+i*2-2; PAPER 1; INK 6; BRIGHT 1;s$(i TO i)
64 BEEP 0.05,5+i*2
66 NEXT i

The word “trumpet” is copied into t$. An empty string s$ will hold the scrambled result. The loop runs until t$ is empty:
- Line 38 picks a random position:
INT (RND * LEN t$) + 1 - Line 40 appends that character to
s$ - Line 42 removes it from
t$
Each pass, t$ shrinks by one character and s$ grows by one. After 7 passes, all letters have moved from t$ to s$ in a random order — then they appear on the blue tiles with the animated reveal.
The Safety Check
Line 44: IF s$ = w$ THEN GO TO 32. If the scramble happens to produce the original word (especially likely with short words like “cat”), it scrambles again. The player should never see the unscrambled answer.
Why Copy First?
Line 30 copies the word: LET t$ = w$. The scramble destroys t$ character by character — without the copy, you’d lose the original. You need it later to check the player’s guess.
Try This
Scramble twice. Run the program twice. The result changes each time — that’s RND at work.
Longer words. Change line 30 to LET w$ = "adventure" and watch 9 letters get rearranged across 9 tiles.
What You’ve Learnt
- Removing a character —
t$(1 TO p-1) + t$(p+1 TO LEN t$)cuts one letter out - The scramble algorithm — pick random, append, remove, repeat until empty
- Safety check — re-scramble if the result matches the original
- Preserving the original — copy with
LET t$ = w$before scrambling