[SOLVED] 'Circle of Squares' programming challenge
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If anyone is still interested, I've updated the code attached to my previous post.
It's mostly clean-up after the refactoring for multi-threading, with some style clean-up and a few comments thrown in. I'm content with the code now, so I'm going to tag 4.6 "final".
It's been a fun little spare-time project for the last few weeks, so. a big "Thanks" to igadoter and dogpatch for bringing the challenge to our attention, and also to those like Astrogeek and Pan, who offered advice along the way.
my god, that is something I wanted to continue with, but you were faster.
Quote:
Originally Posted by GazL
Code:
10091 results returned.
real 0m26.851s
user 1m39.975s
sys 0m0.010s
My laptop is not that powerful, so those with more beefy kit will likely get better results from the multithreading.
Code:
time ./circle -v -a -t4 -o /tmp/circle.out 44
...
4 solver threads will be used. Please wait...
10091 results returned.
real 0m10.507s
user 0m38.760s
sys 0m0.000s
Code:
time ./circle -v -a -t20 -o /tmp/circle.out 44
....
10 solver threads will be used. Please wait...
10091 results returned.
real 0m6.257s
user 0m39.484s
sys 0m0.020s
looks like something is wrong with the number of threads or at least I don't really understand it well.
Quote:
Originally Posted by GazL
4.6 (final): reworked candidate bucket code into something a little nicer. Style clean-up, Added some comments.
looks like something is wrong with the number of threads or at least I don't really understand it well.
from my side it is very well written.
Thankyou.
The amount of threads that it will use are limited by:
1) the hardcoded max in the program, which is 32.
2) the value specified by the user.
3) the amount of "jobs" (i.e. candidate pair seeds) the problem can be split into: you can see how many of these there are when -v is used (just above the line about number of threads).
If there are less jobs than the amount of threads specified it just starts that many threads rather than having others sit around with no work to do.
For example, the default 1-32 circle, can use at most 6 threads.
... which reminds me. One thing I realised the other day was that picking a seed value with the most candidates will potentially allow for an additional thread or two. I was going to do that but forgot. It's a small job, so I'll slap it in a 4.7, then finally, it will be "final".
I am very impressed by the programs GazL and dogpatch uploaded. I find it very hard to comprehend; my knowledge of C/C++ is way too modest.
Thank you for your kind words. Appropriate that you give GazL top billing.
Here's my latest, version 1.4. It contains very few changes over 1.32. Reinstates make for WordRing and PalabraRing, and i think addresses those few remaining compiler warnings.
Calling it 1.4 rather than 1.33, because i don't anticipate another version anytime soon. Since i don't have a multi-core computer, probably won't even try to implement GazL's pthread logic.
"mirror" is likely a more accurate term than "duplicate" for these: the sequence is unique, but a reversal.
Solving the "mirrors problem" was what drove the 3.x branch of my program's development and laid the groundwork for the multi-threading support that followed -- which kind of suggested itself and was just a natural evolution. I wish I could claim to have planned it from the outset, but if I did, I'd be lying.
Yes, in my program mirrors (duplicates) are always generated. If you run it with option -o (ordered) it will still internally generate the mirrors (unlike GazL's code), but will not display or count them.
Quote:
Originally Posted by mimorek
I take it you're kidding.
No, i openly acknowledge GazL's code to be superior.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.