JSFiddle - React, Tailwind, and code Playground

by SwampFall

JavaScript

// calculates the number of structure types
function nost(N) {
	// max length of structures
  var mlos = Math.max(1, Math.floor(N / 2) - 1);
	// structure type, start with 2 (a line structure)
	var st = [2];
  // go from structures with length 1 to mlos
  for (let i = 0; i < mlos; i++) {
    // loop through all the structures with same length
    while (validateStructureType(st, N)) {
    	console.log(JSON.stringify(st));
      nextStructureType(st, N);
    }
    // reset to all 3s
    for (let j = 0; j < st.length; j++) {
    	st[j] = 3;
    }
    // add another 3
    st.push(3);
  }
}

// Check if the structure is valid for given N
function validateStructureType(st, N) {
	let sum = 0;
  for (let i = 0; i < st.length; i++) {
  	sum += st[i];
  }
  sum -= st.length;
  return sum < N - 1;
}

function nextStructureType(st, N) {
	for (let i = 0; i < st.length; i++) {
  	st[i]++;
    for (let j = i - 1; j >= 0; j--) {
    	st[j] = st[i];
    }
    if (validateStructureType(st, N)) {
    	break;
    }
  }
}

nost(11);