Re: Is this program OOP?

Liste des GroupesRevenir à cl c++ 
Sujet : Re: Is this program OOP?
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c++
Date : 15. Dec 2024, 10:45:33
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vjm8ft$gr56$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Mozilla Thunderbird
On 14/12/2024 09:22, wij wrote:
On Thu, 2024-12-12 at 08:59 +0100, David Brown wrote:

"21 * 33 * 13 * 33 * 33 = 9810801" is a pretty much *optimized* solution.
Depending on the viewpoint (what kind of problem you want to solve),
the puzzle solving algorithm can be from O(1) to O(2^N).
 
"Optimised" would mean, as I see it, as fast as possible within reasonably practical limits.  (And of course it would be unreasonable to simply pre-calculate the answer.)  For a problem like this, there are three kinds of optimisations - algorithmic, choice of language or compute platform, and optimisation of the implementation itself.
I have done none of these, so IMHO my solution is far from optimal.  All I did was split the problem into two parts based on a simple criteria. To me, the split was so obvious that I do not see it as something special - but perhaps it is one of these things that seems obvious once you have thought of it.
Algorithmic optimisation would involve dividing the problem into more parts, probably using a search tree and stack structure of some kind but ensuring that it is all allocated and handled with as little dynamic allocation as possible.
Language and compute platform choice optimisation would certainly result in something other than single-threaded Python.  It might mean Prolog, it might mean C++.  Maybe this can be done on a GPU in CUDA - I don't know such platforms well.  Certainly it would aim to be multi-threaded (at least, for a similar style of problem that is large enough to justify the overheads).  And a key consideration would be cache friendly structures.
And I didn't bother doing any kind of implementation optimisation at all.  There is probably scope for increasing speed by a factor of 5 or so in straightforward Python, more from the use of numpy.  But there's a lot more possibility in C++.

>
Now I just need to translate my code into C++ :-)
 So far from I know, using C++ to beat those numbers you provided from Python
is no trivial task. I estimate the limit is 0.08s (on my PC's speed) if nothing
significantly changed.
 
I don't think it should be hard to do a lot better than the Python code from a fairly direct translation of the Python - lists to std::vector<>, and so on.  Translating into more optimal C++ code would lead to a huge improvement in speed.  I would not expect the results to be measurable with the "time" command without looping the algorithm many times.

Date Sujet#  Auteur
9 Dec 24 * Is this program OOP?23wij
9 Dec 24 `* Re: Is this program OOP?22Tim Rentsch
9 Dec 24  `* Re: Is this program OOP?21wij
10 Dec 24   +- Re: Is this program OOP?1Ross Finlayson
10 Dec 24   `* Re: Is this program OOP?19Tim Rentsch
10 Dec 24    `* Re: Is this program OOP?18wij
10 Dec 24     `* Re: Is this program OOP?17David Brown
10 Dec 24      +* Re: Is this program OOP?9Muttley
11 Dec 24      i`* Re: Is this program OOP?8David Brown
11 Dec 24      i `* Re: Is this program OOP?7Muttley
11 Dec 24      i  +* Re: Is this program OOP?4Ross Finlayson
12 Dec 24      i  i`* Re: Is this program OOP?3Muttley
12 Dec 24      i  i `* Re: Is this program OOP?2Ross Finlayson
13 Dec 24      i  i  `- Re: Is this program OOP?1Ross Finlayson
12 Dec 24      i  `* Re: Is this program OOP?2Paavo Helde
12 Dec 24      i   `- Re: Is this program OOP?1Muttley
10 Dec 24      `* Re: Is this program OOP?7wij
11 Dec 24       +* Re: Is this program OOP?5David Brown
12 Dec 24       i`* Re: Is this program OOP?4wij
12 Dec 24       i `* Re: Is this program OOP?3David Brown
14 Dec 24       i  `* Re: Is this program OOP?2wij
15 Dec 24       i   `- Re: Is this program OOP?1David Brown
12 Dec 24       `- Re: Is this program OOP?1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal