SnIPPETsX
SnIPPETsX

SnIPPETsX › tetrominoes 4 squares concatenated tgt

tetrominoes 4 squares concatenated tgt

Python · updated Dec 3, 2026 · 63 lines

main.py

# tetrominoes 4 squares concatenated tgt
# tri-ominoes 
# dominoes
#mono -omino {(0,0)}

# unique ominoes 

# generator, takes in a number and produces a random omino of that size

# object representation / print 

# coordinates of different squares in a grid

# tracking frontier in a set and picking random, growing from there and updating frontier

# 4 directional set for frontier and omino representation O(1)

# neighbors

# return neighbors of a cell

import random

def neighbors(i,j):
 return [(i + 1,j),(i - 1,j),(i,j + 1),(i,j - 1)]
  
  

def ominoGenerator(n): # n in size of omino
  omino = set()
  frontierList = []
  frontier = set()

  omino.add((0,0))
  frontier.extend(neighbors(0,0)) # add multiple tuples
  frontierList = neighbors(0,0)

  for _ in range(n - 1): # grow
    i = random.randint(len(frontierList)) # assume it grabs random value in [0,n)

    frontierList[i], frontierList[-1] = frontierList[-1], frontierList[i]

    loc = frontierList.pop()
    frontier.remove(loc)

    omino.add(loc)

    for nh in neighbors(loc[0],loc[1]):
      if not (nh in omino or nh in frontier):
        frontierList.append(nh)
        frontier.add(nh)


    # n = 3 : (0,0) (1,0)

    
    
    


  return omino
    

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.