Deutsch English Français Italiano |
<fb4cdf9c1c99986b84c6f598858efe1a9473cd26.camel@gmail.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: wij <wyniijj5@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: Is this program OOP? Date: Wed, 11 Dec 2024 01:02:15 +0800 Organization: A noiseless patient Spider Lines: 116 Message-ID: <fb4cdf9c1c99986b84c6f598858efe1a9473cd26.camel@gmail.com> References: <63cd41709a703e4ac6d76427d53fe06d7ee8b8b1.camel@gmail.com> <86plm0iwtj.fsf@linuxsc.com> <035b9e2186f9dc6467806e27a76d98525c104e54.camel@gmail.com> <86h67chxn8.fsf@linuxsc.com> <03fcd46b8d44390c78ca1719e2311b528570d276.camel@gmail.com> <vj9oql$114ip$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Date: Tue, 10 Dec 2024 18:02:16 +0100 (CET) Injection-Info: dont-email.me; posting-host="0ba521b8ff24999df21a7b0e42ad0dc0"; logging-data="1098145"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/W2az/cenweU26yC/JyeEG" User-Agent: Evolution 3.50.2 (3.50.2-1.fc39) Cancel-Lock: sha1:lZ9xnZZrB8ImBphVbTA2yeIzNlI= In-Reply-To: <vj9oql$114ip$1@dont-email.me> On Tue, 2024-12-10 at 17:04 +0100, David Brown wrote: > On 10/12/2024 10:23, wij wrote: > > On Mon, 2024-12-09 at 22:15 -0800, Tim Rentsch wrote: > > > wij <wyniijj5@gmail.com> writes: > > >=20 > > > > On Mon, 2024-12-09 at 09:35 -0800, Tim Rentsch wrote: > > > >=20 > > > > > wij <wyniijj5@gmail.com> writes: > > > > >=20 > > > > > > Because I said:=C2=A0 C++ is the best language to model general > > > > > > problems.=C2=A0 So it is. > > > > > >=20 > > > > > > Almost all are logical propositions.=C2=A0 Except those few key= words, > > > > > > such programwon't be recognized as a C++ program, instead of so= me > > > > > > kind of declarative language. > > > > > >=20 > > > > > > Zebra puzzle is an interesting programing exercise because it i= s > > > > > > not too easy and also not too difficult. > > > > > >=20 > > > > > > ------------ > > > > > > /* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.= Wang 2023 > > > > > >=20 > > > > > > =C2=A0=C2=A0Example of solving the zebra puzzle by using propos= itional logic. > > > > > > =C2=A0=C2=A0Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Pu= zzle > > > > > >=20 > > > > > > [...] > > > > > > */ > > > > > > #include <Wy.stdio.h> > > > > > > #include <Sc/PropExpr.h> > > > > > >=20 > > > > > > using namespace Wy; > > > > > > using namespace Sc; > > > > > >=20 > > > > > > [...] > > > > >=20 > > > > > You're asking a question that cannot be answered because much or > > > > > most of the program is in the two include files, which are not > > > > > shown. > > > > >=20 > > > > > As a general rule, when posting code there should be enough poste= d > > > > > so that readers can at least compile it.=C2=A0 In cases like the = program > > > > > asked about here, what is posted should be enough to both compile > > > > > the program and run the generated executable. > > > >=20 > > > > I thought nobody will be interested with the implement, and what > > > > is shown should be enough for the moment. > > >=20 > > > The point is that what was posted is not enough to answer the > > > question of the Subject: line. > > >=20 > > > > The Zebra Puzzle program has two version, a_puzzle_21.cpp (has > > > > shown) takes too long to complete.=C2=A0 a_puzzle_2.cpp (736 lines,= too > > > > long to post, I thought) is the realistic one written in way I > > > > feel just solving the prolem is enough. > > >=20 > > > I wrote a program in prolog to solve this puzzle.=C2=A0 The entire > > > program is 60 lines long, including 13 blank lines.=C2=A0 It finds > > > the solution in 0.03 seconds.=C2=A0 The program doesn't do anything > > > fancy;=C2=A0 it pretty much just gives the listed conditions in the f= orm > > > of prolog rules, plus 20 lines to establish the structure of the > > > information that is being sought. > >=20 > > Very dubious, show us what you say is true. > >=20 >=20 > Prolog is a language that is ideally suited to such problems.=20 > Basically, you give the language a bunch of objects and facts and=20 > relations about those objects, then you ask it questions about them.=20 > It's at least 35 years since I tried Prolog one afternoon, and that's=20 > exactly the kind of task I played with (though a bit smaller). I know a bit of prolog,lisp (in DOS era). Strongly suspicious what Tim says= .. > This is not a big problem in any language.=C2=A0 It's 5 characteristics f= or=20 > each of 5 houses - that's 3125 possibilities.=C2=A0 Make a big array of= =20 > booleans, initialised to true.=C2=A0 Run through the array and kill any= =20 > combination that is contrary to one of the facts.=C2=A0 It might have bee= n a=20 > worthy benchmark in 1962 but it should not be challenging to solve with= =20 > modern machines.=C2=A0 (Of course it can still inspire interesting soluti= ons=20 > and ways to express code in different languages.) Not that simple, try it to know (your eye may fool you, just like with libw= y). a_puzzle_2.cpp (736 lines) was a random try in normal C++ programming style. I did not try to optimize it. It took 3m22s.=20 a_puzzle_21.cpp has 178 lines, about 40 lines of comments, so 178-40=3D138 = lines. So, I have reason to doubt 60 lines of prolog can do the job. And most importantly, the number of 0.03 seconds is too difficult to explain. Prolog is not really a declarative language, you need to provide 'algorithm= ' to 'compute' the answer. So, there is reason why 'prolog' program can run f= aster. But, unless there is some built-in mechanism in modern=C2=A0prolog to solve= =C2=A0 Zebra-puzzle-like problem, 60 lines of codes is dubious to me and even so, 0.03 seconds remains highly dubious.