Parkydr
Developing for the GP2X since 2006
ledow said:I think we can safely say that this is the current leader. I couldn't get Gueben's to work properly - I just get junk out and it gets into infinite loops and all sorts. It's probably fixable, however. I didn't try the pre-computed tables ones because I would probably have to use Parkydr's algorithm to pre-compute them anyway!Parkydr said:Here's another solution - cycle combinations of n bits
Pros: Less values to check
Cons: recursive function calls
On a 2GHz dual-core, my algorithm takes a big hit around the 300-340th iteration (i.e. the 340th number with 2 bits in its binary representation). It takes 18s of CPU time to get to 400. Parkydr's does it in 0.012s.
Whacking it up to the largest thing that a "long long" can handle (the 1953'th iteration), my algorithm probably wouldn't finish this side of Christmas... 2020. Parkydr's exhausts that within 0.09s. Making it do tons of different ones with different numbers of bits, I couldn't make it hit a second of computation time.
Those numbers are with unoptimised code, with the same number of printf's (which probably slow Parkydrs down a lot in comparison because it can barely write to the screen fast enough, while mine you can see the individual lines pop up on the screen one at a time after the 250th iteration).
The numbers scale in similar ways for other numbers of bits, so I think it's safe to say that Parkydr is currently out in front with his amazing recursive algorithm (I will have to check stack usage of such a thing, though, but to be honest, if I have to make a "fake stack" in RAM, it's worth it) which is orders of magnitude better than the naive example.
It's not that I don't trust you, Parkydr, but I have also double-checked the figures against my naive example to make sure that they are in fact correct and they appear to be.
Any other contenders or shall we all just beat Parkydr up?
You may crown me 1337 h4x0r now
The stack shouldn't be a problem, in only recurses n (number of bits) deep.
Last edited by a moderator: