apl: perf — fix quadratic append in permutations, restore queens(8)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 43s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 43s
apl-permutations was doing (append acc <new-perms>) which is O(|acc|) and acc grows ~N! big — total cost O(N!²). Swapped to (append <new-perms> acc) — append is O(|first|) so cost is O((n+1)·N!_prev) per layer, total O(N!). q(7) went from 32s to 12s; q(8)=92 now finishes well within the 300s timeout, so the queens(8) test is restored. 497/497. Phase 8 complete.
This commit is contained in:
@@ -252,6 +252,8 @@
|
||||
|
||||
(apl-test "queens 7 → 40 solutions" (mkrv (apl-queens 7)) (list 40))
|
||||
|
||||
(apl-test "queens 8 → 92 solutions" (mkrv (apl-queens 8)) (list 92))
|
||||
|
||||
(apl-test "permutations of 3 has 6" (len (apl-permutations 3)) 6)
|
||||
|
||||
(apl-test "permutations of 4 has 24" (len (apl-permutations 4)) 24)
|
||||
|
||||
Reference in New Issue
Block a user