AlexandrAI AGENTS.md
agents-md

AlexandrAI Tools Permutation Combination Agent Guide

Agent guide for BigInt factorial, nCr, nPr, and bounded browser combinatorics validation.

AGENTS.md

Guidance for coding agents working on AlexandrAI Tools Permutation Combination in the alexandrai-tools project.

Project overview

This guide covers src/tools/permutation-combination. factorial returns BigInt factorials, nCr uses the smaller of r and n-r for efficient multiplicative combination calculation, nPr multiplies descending factors, and calcPermComb validates integer non-negative n and r with r not greater than n and n not greater than MAX_PERM_COMB_INPUT.

Primary source files

  • src/tools/permutation-combination/index.ts defines meta, MAX_PERM_COMB_INPUT, factorial, nCr, nPr, PermCombResult, and calcPermComb.
  • src/tools/permutation-combination/index.test.ts covers factorial, nCr, nPr, poker-hand nCr, invalid negatives, r greater than n, non-integers, and too-large input rejection.
  • src/tools/permutation-combination/Body.astro owns n/r inputs and BigInt result display.
  • src/tools/permutation-combination/i18n.ts owns localized labels.
  • src/lib/tools.ts registers the tool metadata.

Setup commands

npm install npm test npm run typecheck npm run build npm run dev

Change rules

  • Return 1n for factorial of zero or one.
  • Return 0n from nCr or nPr when n or r is invalid at the low-level helper.
  • Return 1n for nCr at r equal to zero or r equal to n.
  • Return 1n for nPr at r equal to zero.
  • Use BigInt for exact integer results.
  • Reject non-integer inputs in calcPermComb.
  • Reject n values above MAX_PERM_COMB_INPUT for browser responsiveness.

Testing

Test factorial basics, nCr symmetry, nPr basics, large known values, invalid low-level helper cases, calc validation errors, max input boundary, BigInt display, and UI responsiveness.

PR checklist

  • npm test passes for permutation-combination.
  • Randomness, math, lookup tables, or Unicode behavior is documented exactly.
  • Browser-local behavior and copy/output paths remain private.
  • Invalid inputs and edge cases are covered by tests.