Specifically for [livejournal.com profile] coldtortuga

Jan. 1st, 2006 01:56 pm
pmb: (Default)
[personal profile] pmb
A variation on a previous theme:
BaseNumberNumber in Base 10
2121
3232
4312454
54135108
64126152
765142716200
8762513482042460
9827153694416720
109867312109867312
Still churning - these O(nn) algorithms really soak up the CPU time...
(I later hit Ctrl-C, so all numbers after this point are from [livejournal.com profile] coldtortuga)
11A98762413112334364200
12B935217612421877610
13CBA95847213131779700673520

Date: 2006-01-05 06:25 pm (UTC)
From: [identity profile] pmb.livejournal.com
Totally could. (actually, $O(\sum_{i=0}^n {(n choose i) * i!})$ which I think is still O(n!), but I'm not entirely sure... That would make a good intro to algorithms and data structures question.)

Try all permutations of n letters, in reverse lexicographic order, then all permutations of all size n-1 subsets in some appropriate order. The only issue is coding all of that up. The reverse lexicographic order thing isn't too bad, but doing all of the subsets and pulling off the next candidate in the right order is a tricky bit of combinatorial coding that I would prefer to avoid. Using some heuristics, [livejournal.com profile] coldtortuga was able to get the base 10 case down to 10 seconds of searching, but I don't know if his techniques generalize to other bases.

I suppose one could make a heap of generators that would yield the front of the lowest generator on the heap. In the worst case there would be O(n!) generators, but that's only O(n lg n) to pull the top one off the heap, and the answer would probably be found before the heap got to be too large. That would be memory intensive, but not too bad otherwise. Heapification is pretty quick... I bet I could use this technique to find the sequence up to base 14, maybe!

But it sounds like a whole lot of work for just 4 more terms. I prefer to throw CPU at the problem and then walk away if that doesn't suffice. Optimizing non-polynomial algorithms just isn't very fun. Finding a polynomial algorithm is, and so is proving a problem impossible. But I don't see how this problem is NP complete (it seems over-specified, which makes reductions difficult), it doesn't seem like it has a polynomial solution, and number theory was always my most dicey section in discrete math.

Date: 2006-01-05 06:53 pm (UTC)
From: [identity profile] mycrust.livejournal.com
Yeah, this problem has the flavor of something that someone clever could find a way to speed up dramatically by reducing the search space using some generalized facts about divisibility. I am not capable of doing that though. And the answer is kind of cooler than the method anyway.

Date: 2006-01-10 09:46 pm (UTC)
From: [identity profile] coldtortuga.livejournal.com
My "heuristic" approach pretty much follows the algorithm described by [livejournal.com profile] pmb, which is (as ya'll surmise) O(n!).

In base n, start with the set of usable digits D={1, ..., n-1}. For each non-empty subset d of D (in Gray-code order, 'cause I already had a Gray-code subset generator), I find and test all the permutations of d (in the order given by Heaps' algorithm, 'cause I already had Heaps coded up). Gray-code + Heaps' algo does not the most efficient search-order make, but it's not too shabby.

The number of candidates to test in base n is given by A007526 which grows like e*n!

Profile

pmb: (Default)
pmb

October 2009

S M T W T F S
    1 23
45678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 17th, 2026 10:48 am
Powered by Dreamwidth Studios