Skip to content

Improve heap performance, add integer-only ops and exponent support, and safer reachability pruning#1

Merged
beackers merged 1 commit intosearchfrom
codex/optimize-code-for-number-operation-solutions
Feb 4, 2026
Merged

Improve heap performance, add integer-only ops and exponent support, and safer reachability pruning#1
beackers merged 1 commit intosearchfrom
codex/optimize-code-for-number-operation-solutions

Conversation

@beackers
Copy link
Owner

@beackers beackers commented Feb 4, 2026

Motivation

  • Speed up the search ordering to reduce overhead when exploring many states by replacing repeated full sorts with a proper binary min-heap.
  • Improve accuracy by restricting arithmetic to integer results, adding exponentiation, and deduplicating per-pair results to avoid redundant branches.
  • Make reachability pruning safer and prepare the code for bound-aware pruning by exposing bound metadata and tightening the canReach test.

Description

  • Replace table.sort based priority queue with a binary heap implementation in min.lua using siftUp/siftDown and a priority(state) helper. (min.lua)
  • Add M.setBounds, isInteger, and safePow helpers to states.lua, and wire bounds from knockout.lua via states.setBounds(TARGET_MIN, TARGET_MAX). (states.lua, knockout.lua)
  • Extend ops to include a^b and b^a using safePow, and make division return only exact integer quotients (a % b == 0 / b % a == 0). (states.lua)
  • Ensure M.calc emits only integer results and deduplicates results per operand pair to avoid creating duplicate next states. (states.lua)
  • Simplify and harden M.canReach so it returns true when bounds are missing, rejects invalid bounds, and uses a conservative interval (-sumAbs, sumAbs) to check potential reachability. (states.lua)

Testing

  • Attempted to run lua knockout.lua 1 36 5 6 11 to validate behavior, but the run failed because lua is not available in the execution environment; no automated runtime tests could be completed.

Codex Task

@beackers beackers merged commit 7f07ae3 into search Feb 4, 2026
2 of 4 checks passed
@beackers beackers deleted the codex/optimize-code-for-number-operation-solutions branch February 4, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant