Skip to content

Instantly share code, notes, and snippets.

@gaborgsomogyi
Created March 25, 2024 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaborgsomogyi/97a1d269849b0032ebc7ae9b760465d9 to your computer and use it in GitHub Desktop.
Save gaborgsomogyi/97a1d269849b0032ebc7ae9b760465d9 to your computer and use it in GitHub Desktop.
from itertools import product

def generate_paintings():
    colors = ['A', 'B', 'C', 'D']
    hexagons = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7']  # 1 in the middle, 6 around
    
    # Generate all possible combinations of colors for the hexagons
    all_paintings = product(colors, repeat=7)
    
    valid_paintings = []
    
    # Check each painting for neighboring hexagons having the same color
    for painting in all_paintings:
        valid = True
        for i in range(len(hexagons)):
            # Determine the neighbors for each hexagon
            if i == 0:  # H1 (middle hexagon)
                neighbors = [1, 2, 3, 4, 5, 6]
            else:  # H2 to H7
                neighbors = [(i - 1) % 6, (i + 1) % 6, 0]  # 0 represents the middle hexagon
            
            # Check if any neighboring hexagons have the same color
            for neighbor in neighbors:
                if painting[i] == painting[neighbor]:
                    valid = False
                    break
            
            if not valid:
                break
        
        if valid:
            valid_paintings.append(painting)
    
    return valid_paintings

if __name__ == "__main__":
    valid_paintings = generate_paintings()
    print("Number of valid paintings:", len(valid_paintings))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment