SnIPPETsX
SnIPPETsX

SnIPPETsX › @james nugent › technical interview saleh

technical interview saleh

Python · by @james nugent · updated Oct 28, 2026 · 109 lines

main.py

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


# ex. n = 3
# []

# [] []

# [] []
# []


# ominos - consecutive squares interconnected

# representation of n-omino

# method to generate a random n-omino instance

# ascii/pretty print is OOS

class NOmino:
  OCCUPIED = 1
  VACANT = 0
  def __init__(self, n):
    if n < 1:
      raise Exception(f"Invalid N Omino {n}")
    self.n = n
    self.populated = 0
    self.board : List[List[int]]= [] # board populated w/ vacant or occupied
    self.points : List[List[int]] = [] # 2d points, x,y
    for row_index in range(n):
      row = []
      for col_index in range(n):
        row.append(NOmino.VACANT)
      self.board.append(row)
    # add origin
    self.board[0][0] = OCCUPIED
    self.populated = 1
    self.points.append( [0, 0])

  def add_to_board(self):
    
    while(self.populated < self.n):
      # print(random.randint(1, 6))
      # find edges in the board
      sampled_point_index = random.randint(len(self.points))
      sampled_point = self.populated[sampled_point_index]
      x, y = sampled_point[0], sampled_point[1]

      # left
      possible_expansions = []
      if x > 0 and self.board[x-1][y] == NOmino.VACANT:
        possible_expansions.append( [x-1, y] )

      # right
      

      # down

      # up
      
      # randomly select 1
      if len(possible_expansions) == 0:
        continue
      else:
        selected_expansion_index = random.randint(len(possible_expansions))
        selected_expansion = possible_expansions[selected_expansion_index]
        sx, sy = selected_expansion[0], selected_expansion[1]
        self.board[sx][sy] = OCCUPIED
        self.populated += 1
        self.points.append( [sx, sy] )

    return self.points
        
      
      # randomly select expand down, left, right, or up as long as not populated already
    
  

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.