Skip to content

lucent-lab/algorithm-workshop

Repository files navigation

LLM Algorithms

Utility-first TypeScript toolkit of high-signal algorithms tailored for large language model (LLM) generated code snippets and rapid prototyping scenarios. The project emphasises readable implementations, comprehensive documentation, and runnable examples that translate well into AI-assisted development workflows.

Install

npm install llm-algorithms

ES module import (Node 18+ / modern bundlers):

import { astar, perlin } from 'llm-algorithms';

CDN usage:

<script type="module">
  import { astar } from "https://cdn.jsdelivr.net/npm/llm-algorithms/dist/index.js";
  // ...
</script>

Included Modules (v0.1.0)

Goal Algorithms Import From Example
Pathfinding & navigation astar, dijkstra, jumpPointSearch, computeFlowField, buildNavMesh, findNavMeshPath, manhattanDistance, gridFromString pathfinding/astar.ts, pathfinding/dijkstra.ts, pathfinding/jumpPointSearch.ts, pathfinding/flowField.ts, pathfinding/navMesh.ts examples/astar.ts, examples/flowField.ts, examples/navMesh.ts
Procedural generation perlin, perlin3D, simplex2D, simplex3D, worley, worleySample, waveFunctionCollapse, cellularAutomataCave, poissonDiskSampling, computeVoronoiDiagram, diamondSquare, generateLSystem, generateBspDungeon, generateRecursiveMaze, generatePrimMaze, generateKruskalMaze, generateWilsonMaze, generateAldousBroderMaze, generateRecursiveDivisionMaze procedural/*.ts examples/simplex.ts, examples/worley.ts, examples/waveFunctionCollapse.ts, examples/cellularAutomata.ts, examples/poissonDisk.ts, examples/voronoi.ts, examples/diamondSquare.ts, examples/lSystem.ts, examples/dungeonBsp.ts, examples/mazeRecursive.ts, examples/mazePrim.ts, examples/mazeKruskal.ts, examples/mazeWilson.ts, examples/mazeAldous.ts, examples/mazeDivision.ts
Spatial queries & collision Quadtree, aabbCollision, aabbIntersection, satCollision, circleRayIntersection, sweptAABB spatial/*.ts examples/sat.ts
AI behaviours & crowds seek, flee, arrive, pursue, wander, updateBoids, BehaviorTree, rvoStep, createFSM, createGeneticAlgorithm, computeInfluenceMap ai/steering.ts, ai/boids.ts, ai/behaviorTree.ts, ai/rvo.ts, ai/fsm.ts, ai/genetic.ts, ai/influenceMap.ts examples/steering.ts, examples/boids.ts, examples/rvo.ts, examples/fsm.ts, examples/genetic.ts, examples/influenceMap.ts
Web performance & UI debounce, throttle, LRUCache, memoize, deduplicateRequest, clearRequestDedup, calculateVirtualRange, createWeightedAliasSampler, createObjectPool, fisherYatesShuffle util/*.ts examples/requestDedup.ts, examples/virtualScroll.ts, examples/weightedAlias.ts, examples/objectPool.ts, examples/fisherYates.ts
Gameplay systems createDeltaTimeManager, createFixedTimestepLoop, createCamera2D, createParticleSystem, createSpriteAnimation, createTweenSystem, createPlatformerController, createTopDownController, createTileMapController, computeFieldOfView, createInventory, calculateDamage, createCooldownController, updateStatusEffects, createQuestMachine, createWaveSpawner, createSoundManager, createInputManager, createSaveManager, createScreenTransition util/deltaTime.ts, util/fixedTimestep.ts, gameplay/camera2D.ts, gameplay/particleSystem.ts, gameplay/spriteAnimation.ts, gameplay/tween.ts, gameplay/platformerPhysics.ts, gameplay/topDownMovement.ts, gameplay/tileMap.ts, gameplay/shadowcasting.ts, gameplay/inventory.ts, gameplay/combat.ts, gameplay/questMachine.ts, gameplay/waveSpawner.ts, gameplay/soundManager.ts, gameplay/inputManager.ts, gameplay/saveManager.ts, gameplay/screenTransitions.ts examples/deltaTime.ts, examples/fixedTimestep.ts, examples/camera2D.ts, examples/particleSystem.ts, examples/spriteAnimation.ts, examples/tween.ts, examples/platformerPhysics.ts, examples/topDownMovement.ts, examples/tileMap.ts, examples/shadowcasting.ts, examples/inventory.ts, examples/combat.ts, examples/quest.ts, examples/waveSpawner.ts, examples/soundManager.ts, examples/inputManager.ts, examples/saveManager.ts, examples/screenTransitions.ts
Search & text fuzzySearch, fuzzyScore, Trie, binarySearch, levenshteinDistance, kmpSearch, rabinKarp, boyerMooreSearch, buildSuffixArray, longestCommonSubsequence, diffStrings search/*.ts examples/search.ts
Data & diff pipelines diff, deepClone, groupBy, diffJson, diffJsonAdvanced, applyJsonDiff, applyJsonDiffSelective, flatten, unflatten, diffTree, applyTreeDiff data/*.ts examples/jsonDiff.ts, examples/treeDiff.ts
Graph algorithms graphBFS, graphDFS, topologicalSort, computeMinimumSpanningTree graph/traversal.ts, graph/kruskal.ts examples/graph.ts, examples/kruskal.ts
Visual & geometry convexHull, lineIntersection, pointInPolygon, bresenhamLine, easing, quadraticBezier, cubicBezier, hexToRgb, rgbToHex, rgbToHsl, hslToRgb, mixRgbColors, computeForceDirectedLayout, computeMarchingSquares, computeMarchingCubes geometry/*.ts, visual/*.ts examples/geometry.ts, examples/bresenham.ts, examples/visual.ts, examples/color.ts, examples/forceDirected.ts, examples/marchingSquares.ts, examples/marchingCubes.ts

Scripts

npm run lint        # ESLint + TypeScript rules
npm run typecheck   # Strict TypeScript validation
npm run build       # Emits dist/ with ESM + .d.ts
npm test            # Vitest suite
npm run test:coverage  # Enforce coverage thresholds
npm run benchmark   # Compare algorithm variants locally
npm run size        # Enforce bundle size budget

API Reference

  • Full TypeScript signatures with "Use for" and performance notes live in docs/index.d.ts. Keep this document in sync with src/index.ts so tooling and LLMs can discover the complete surface area.

Why This Library Helps LLMs

Generating long, stateful algorithms inside prompts is error‑prone and wastes context window. This project intentionally ships implementations that are:

  • Big enough to be annoying for an LLM to re‑generate each time (reducing token burn),
  • Deterministic with parameterized options and strong typing, and
  • Covered by tests and examples so agents can compose them confidently.

High‑value algorithms for LLM workflows include complex matchers, graph solvers, and geometry builders that are long, fiddly, and easy to get wrong. The roadmap highlights these under “LLM‑Optimised Additions”.

LLM‑Optimised Additions (Highlights)

  • Aho–Corasick multi‑pattern automaton (string matcher; long to implement, widely useful)
  • Dinic / Push‑Relabel maximum flow (network flow; many moving parts and edge cases)
  • Suffix Automaton or Ukkonen’s Suffix Tree (advanced indexing; compact surface, complex internals)
  • Delaunay Triangulation (Bowyer–Watson) + fast nearest neighbour structures (KD‑Tree)
  • BVH (SAH) or R‑Tree builders (robust spatial indexes that are non‑trivial to code)
  • Polygon clipping (Greiner–Hormann or Weiler–Atherton) for boolean ops (very token‑heavy)
  • Tarjan / Kosaraju SCC (graph decomposition; lower complexity but frequently reused)

See the roadmap for the full list and status.

Roadmap Snapshot

  • Milestone 0.2 next targets crowd-flow integrations (RVO + flow fields) and behaviour-tree decorators for richer AI control.
  • Milestone 0.4 plans a procedural + gameplay systems toolkit (Wave Function Collapse, dungeon suite, L-systems, game loop, camera, particles, inventory, combat, save/load, and more).

Examples live under examples/ and can be executed with tsx/ts-node or compiled for the browser. See examples/astar.ts, examples/flowField.ts, examples/navMesh.ts, examples/cellularAutomata.ts, examples/poissonDisk.ts, examples/voronoi.ts, examples/diamondSquare.ts, examples/lSystem.ts, examples/dungeonBsp.ts, examples/mazeRecursive.ts, examples/mazePrim.ts, examples/mazeKruskal.ts, examples/mazeWilson.ts, examples/mazeAldous.ts, examples/mazeDivision.ts, examples/steering.ts, examples/boids.ts, examples/requestDedup.ts, examples/deltaTime.ts, examples/fixedTimestep.ts, examples/camera2D.ts, examples/particleSystem.ts, examples/spriteAnimation.ts, examples/tween.ts, examples/platformerPhysics.ts, examples/topDownMovement.ts, examples/tileMap.ts, examples/shadowcasting.ts, examples/inventory.ts, examples/combat.ts, examples/quest.ts, examples/waveSpawner.ts, examples/soundManager.ts, examples/inputManager.ts, examples/saveManager.ts, examples/lighting.ts, examples/search.ts, examples/graph.ts, examples/geometry.ts, examples/bresenham.ts, examples/visual.ts, examples/sat.ts, examples/simplex.ts, and examples/worley.ts for quick starts. The examples registry exported from src/index.ts provides a typed index you can traverse programmatically.

Contributing

  1. Fork the repository.
  2. Create a feature branch per algorithm addition.
  3. Update docs (docs/index.d.ts), examples, and tests alongside implementation.
  4. Run the full suite (lint, typecheck, build, test) before opening a PR.

MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors