Life is like a box of chocolates

Report a typo

Forest loves candy and math very much. Therefore, he decided to eat candy according to a certain formula (i+j)modk=1(i + j) \bmod k = 1, where ii is the row number, jj is the column number and modmod is the modulus operator. Which candies will remain in a square box of size n×nn \times n when he eats all the candies according to the formula?

function reggae(n, k):
    for i in (1, n):
        for j in (1, n):
            if (i + j) mod k == 1 then:
                print("*")
            else:
                print("o")
        println()                 //new line

In other words, what will the program output when calling the function with the arguments n=5n = 5 and k=2k=2?

Note: The figures in the answer choices below represent the different arrangements of * (empty space from eaten candy) and oo (candy not yet eaten) in the square box. A better way to solve this problem is to draw the square box using pen and paper, and run through the given pseudocode.

Select one option from the list
___

Create a free account to access the full topic