Embercode
✕
GraphsQuick quiz

Grid search and state BFS in Python

8 questions. Covers State-space BFS with keys and doors in Python.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python def fill(g, r, c): if r < 0 or r >= len(g) or c < 0 or c >= len(g[r]) or g[r][c] != "A": return 0 g[r][c] = "X" return 1 + fill(g, r + 1, c) + fill(g, r - 1, c) + fill(g, r, c + 1) + fill(g, r, c - 1) g = [list("AAB"), list("ABA"), list("AAA")] n = fill(g, 0, 0) print(n, "".join(g[1])) ``
  2. 2. What does this program print? ``python keys = 0 keys |= 1 << (ord("b") - ord("a")) keys |= 1 << (ord("d") - ord("a")) can_open_b = (keys & (1 << (ord("B") - ord("A")))) != 0 can_open_c = (keys & (1 << (ord("C") - ord("A")))) != 0 print(keys, can_open_b, can_open_c) ``
  3. 3. A search keeps one seen mark per cell. On the grid #a## and @.Ab, the correct answer is 5, but the search returns -1. Why?
  4. 4. The state search returns as soon as it removes a state that holds every key. Why is that first answer the smallest number of steps?
  5. 5. Which statements about the grid fill and island counting in the earlier grid lesson are true? Pick all that apply.

    Pick every answer that is true.

5 question(s) left on this page.