The goal is to fill the squares in the playground like the squares in the assignment.
There are multiple
ways to solve the challenge.
Every assignment has a trivial solution of just listing all the coordinates. However, the goal is to find a shorter, algorithmic way of coloring the squares. See the manual and examples below for inspiration.
To fill a square at position (x, y) use the following instruction:
(x,y)
Example:
(0,0)
You can use variables to store values. To assign a value to a variable use the following instruction:
variable <- expression
Example:
x <- 3
x <- x + 1
To add a comment use the following instruction:
instruction # comment
Example:
x <- 3 # set x to 3
# this is ignored
To jump to a position use the following instruction:
goto label
Example:
label:
# code
goto label
You can use conditions to control the flow of the program. To use a condition use the following instruction:
expression | condition
Example:
goto start | x = 6
(1,4)
(2,5)
(3,6)
i <- 0
again:
(7,i)
i <- i + 1
goto again | i < 11
i <- 0
loop:
(i,i)
i <- i + 1
goto loop | i < 11
x <- 0
y <- 0
loop:
(x,y) | x % 2 = y % 2
x <- x + 1
y <- y + 1 | x > 10
x <- 0 | x > 10
goto loop | y < 11
i <- 1
next:
j <- 0
k <- 0
goto fill
fill:
(i+k, i+j)
k <- k + 1
goto fill | k < 3
k <- 0
j <- j + 1
goto fill | j < 3
i <- i + 3
goto next | i < 10
y <- 2
next:
(3,y)
(4,y) | y = 5
(5,y) | y = 5
(6,y) | y = 5
(7,y)
y <- y + 1
goto next | y < 9
© 2024 Adrian Rabenseifner