I recently learned of a simple logic puzzle from my daughter’s mathletes class (run by Coach K’s Mathletes) that I thought would be fun to code up. The puzzle is called “Paint Roller”, and is succinctly described in the image below:

If I were to relabel the rows as A, B and C and the columns as 1, 2 and 3, the image below shows how the correct solution paints the board step by step:

This is relatively simple to code up in R. The full code can be found at this link. The main function is play_game() which starts an interactive version of the game:
set.seed(1)
play_game(row_count = 4, col_count = 4)
This prints an image showing the start and end of the roller puzzle, and a prompt appears in the console asking you for the sequence that generated the end image.

The console will keep prompting you for sequences until you get the correct answer. The code also does some basic validation (e.g. check that the sequence contains valid characters and that no characters are duplicated).

If you get the correct answer, the image tells you that you won and the game ends. You can also enter Q at any time to end the game. When the game ends, it tells you the sequence it used to generate the board. Note that there can be more than one correct sequence: for example, ABC123 and CBA321 will produce the same board.

The play_game() function allows you to specify the number of rows and columns, as well as a custom color palette if you’d like:
set.seed(1)
play_game(row_count = 3, col_count = 4,
color_list = c("green", "cyan", "magenta", "red", "orange", "yellow", "black"))

There are two other functions that might be of interest. The first is make_image(), which makes an image of the board for a given sequence:
make_image("AC1", row_count = 4, col_count = 3)

The other function is show_entire_sequence(), which shows how a sequence paints the board step-by-step. This is especially useful for helping kids visualize what is going on.
show_entire_sequence("A3BC21", row_count = 4, col_count = 4)

Both make_image() and show_entire_sequence() also have the optional color_list argument for setting custom color palettes.