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:
@@ -883,7 +883,7 @@
|
||||
(let
|
||||
((sub (apl-permutations (- n 1))))
|
||||
(reduce
|
||||
(fn (acc p) (append acc (apl-insert-everywhere n p)))
|
||||
(fn (acc p) (append (apl-insert-everywhere n p) acc))
|
||||
(list)
|
||||
sub)))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user