or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-8/

Partition and Sequence Counter

A utility library for counting partitions and special combinatorial sequences.

Capabilities

Counts set partitions

  • Computes the number of ways to partition 5 elements into 3 non-empty subsets and returns 25 @test
  • Computes the total number of ways to partition 4 elements into any number of non-empty subsets and returns 15 @test

Counts binary tree structures

  • Computes the number of distinct binary trees with 4 nodes and returns 14 @test
  • Computes the number of ways to correctly match 3 pairs of parentheses and returns 5 @test

Validates inputs

  • Throws an error when computing set partitions with negative numbers @test
  • Throws an error when the subset count exceeds the total elements @test

Implementation

@generates

API

/**
 * Computes the number of ways to partition n elements into k non-empty subsets.
 *
 * @param {number} n - The total number of elements
 * @param {number} k - The number of non-empty subsets
 * @returns {number} The count of ways to partition n into k subsets
 * @throws {Error} If n or k is negative, or if k > n
 */
function countSetPartitions(n, k) {
  // IMPLEMENTATION HERE
}

/**
 * Computes the total number of ways to partition n elements.
 *
 * @param {number} n - The total number of elements
 * @returns {number} The total count of partitions
 * @throws {Error} If n is negative
 */
function countTotalPartitions(n) {
  // IMPLEMENTATION HERE
}

/**
 * Computes the number of structurally different binary trees with n nodes.
 *
 * @param {number} n - The number of nodes
 * @returns {number} The count of distinct binary tree structures
 * @throws {Error} If n is negative
 */
function countBinaryTrees(n) {
  // IMPLEMENTATION HERE
}

module.exports = {
  countSetPartitions,
  countTotalPartitions,
  countBinaryTrees,
};

Dependencies { .dependencies }

mathjs { .dependency }

Provides advanced combinatorial functions for computing special number sequences.