World 3: Read the route
A note with a route
- Now your pet has a route note: a string like
"RRDR". - Your code reads the note letter by letter and outputs the real moves.
Words for this world
| Word | Meaning |
|---|---|
| route | the way from one place to another |
| letter | one character in a string |
| decide | choose what to do; IF decides |
Turn letters into moves
DECLARE Route : STRING
DECLARE i : INTEGER
Route ← "RRD"
FOR i ← 1 TO LENGTH(Route)
IF MID(Route, i, 1) = "R" THEN
OUTPUT "right"
ELSE
OUTPUT "down"
ENDIF
NEXT i
- The loop visits every letter. The
IFdecides what to output.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Your pet has a route note: Route ← "RRRR". R means right. Go through the letters with a loop, and output right for each R.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Now the route has two letters: Route ← "RDRDR". R means right and D means down.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Use all four letters: R right, L left, U up, D down. The route is "DDRRUURR".
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Someone wrote extra x letters in the route: "RxRxDxR". An x means nothing. Print a move only for R และ D.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
A short route: "R3D2R1". Each letter comes with a number: how many times to move. So R3 means right, right, right.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 4/5 · 280 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
The treasure route: "D1R2X1R1". X means dig. Read each letter and number as before.
คลิก Run เพื่อดูผลลัพธ์ที่นี่