Goose Egg Patterns

The result of solving a goose-egg puzzle with friends :D

by asemahle

HTML

<canvas id="canvas" width="500px" height="10000px"></canvas>

JavaScript

// Setup the canvas
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');

// Define the "dice" as graphs
// Keys represenct graph nodes (sides of dice) 
// and values represent the list of connected nodes (adjacent sides of the die)
const fourSidedDieGraph = {
  1: [2,3,4],
  2: [1,3,4],
  3: [1,2,4],
  4: [1,2,3]
};
const sixSidedDieGraph = {
  1: [2,3,4,5],
  2: [1,3,4,6],
  3: [1,2,5,6],
  4: [1,2,5,6],
  5: [1,3,4,6],
  6: [2,3,4,5]
};
const eightSidedDieGraph = {
  1: [3,4,7],
  2: [3,4,8],
  3: [1,2,5],
  4: [1,2,6],
  5: [3,7,8],
  6: [4,7,8],
  7: [1,5,6],
  8: [2,5,6]
};
const twelveSidedDieGraph = {
  1: [2,3,4,5,6],
  2: [1,3,4,7,8],
  3: [1,2,5,7,9],
  4: [1,2,6,8,10],
  5: [1,3,6,9,11],
  6: [1,4,5,10,11],
  7: [2,3,8,9,12],
  8: [2,4,7,10,12],
  9: [3,5,7,11,12],
  10: [4,6,8,11,12],
  11: [5,6,9,10,12],
  12: [7,8,9,10,11]
};
const twentySidedDieGraph = {
  1: [7,13,19],
  2: [12,18,20],
  3: [9,16,19],
  4: [11,14,18],
  5: [13,15,18],
  6: [14,16,17],
  7: [1,9,15],
  8: [10,16,20],
  9: [3,7,10],
  10: [8,9,12],
  11: [4,13,17],
  12: [2,10,15],
  13: [1,5,11],
  14: [4,6,20],
  15: [5,7,12],
  16: [3,6,8],
  17: [6,11,19],
  18: [2,4,5],
  19: [1,3,17],
  20: [2,8,14]
};
const nimGraph = {
	1: [1,2,3],
  2: [1,2,3],
  3: [1,2,3]
};

// Render the pattern for up to this many eggs
const maxEggs = 2000;

// Returns a 2D array of booleans representing the goose-egg pattern
function getPattern(graph, maxEggs) {
  const solution = [];
  for (let numEggs = 1; numEggs < maxEggs; numEggs++) {
    const line = [];
    solution.push(line);
    for (let value in graph) {
      const options = graph[value];
      let result = false;
      for (let option of options) {
        if (numEggs - option === 0) {
          result = true;
          break;
        }
        if (numEggs - option >= 0 && !solution[numEggs - option - 1][option-1]) {
          result = true;
          break;
        }
      }
      line.push(result);
   ...