SnIPPETsX
SnIPPETsX

SnIPPETsX › 1-omino (hannah_farley_technical)

1-omino (hannah_farley_technical)

Python · updated Nov 13, 2026 · 83 lines

main.py

# 1-omino
#
# []
#
# 2-omino
#
# [] []
#
# 3-omino
#
# [] [] []
#
# []
# [] []
#
# 4-omino (non exhaustive)
#
# [] []
# [] []
#
# [] [] []
#    []
#
# 5-omino (non exhaustive)
#
#    []
# [] [] []
#    []



def class nOmino:
  # size n x n
  # 0 = blank space
  # 1 = square
  # shape will contain exactly n 1's 
  shape: [int][int]

  # constructor input n: int
  def init(self, n: int):
    if n <= 0:
      throw TypeError("n must be >=1")
      
    for row in range(n):
      for col in range(n):
        self.shape[row][col] = 0

    # row/col can 0 up to n - 1
    start_row = util.random(0, n)
    start_col = util.random(0, n)


    # number of sqaures already filled in (placed)
    count = 0

    directions = [(1,0), (-1,0), (0, 1), (0, -1)]

    queue = deque([(start_row, start_col)])

    visited 

    while queue and count < n:
      curr_row, curr_col = queue.poprandom()
      self.shape[curr_row][curr_row] = 1
      count += 1
      
      for dr, dc in directions:
        new_row, new_col = curr_row + dr, curr_col + dc
          if 0 <= new_row < n and 0 <= new_col < n:
            queue.append((new_row, new_col))
    
        
      
      
      
      
    
      
      
  
  

Run this Python snippet

Open this snippet on SnIPPETsX to run the Python code in your browser, edit it together with others in real time, or fork it into your own copy. No install or account is needed.