Deutsch English Français Italiano |
<63cd41709a703e4ac6d76427d53fe06d7ee8b8b1.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: Is this program OOP? Date: Mon, 09 Dec 2024 20:08:59 +0800 Organization: A noiseless patient Spider Lines: 208 Message-ID: <63cd41709a703e4ac6d76427d53fe06d7ee8b8b1.camel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Date: Mon, 09 Dec 2024 13:09:01 +0100 (CET) Injection-Info: dont-email.me; posting-host="d21130fcf26d215eec62e322955e4662"; logging-data="418375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yh5471FKC+WxVslCzHiHH" User-Agent: Evolution 3.50.2 (3.50.2-1.fc39) Cancel-Lock: sha1:RMofXqYfocKsPnW5iy/c/2I91yE= Because I said: C++ is the best language to model general problems. So it i= s. Almost all are logical propositions. Except those few keywords, such progra= m=C2=A0won't be recognized as a C++ program, instead of some kind of declarative languag= e. Zebra puzzle is an interesting programing exercise because it is not too ea= sy and also not too difficult. ------------ /* Copyright is licensed by GNU LGPL, see file COPYING. by I.J.Wang 2= 023 Example of solving the zebra puzzle by using propositional logic. Zebra Puzzle https://en.wikipedia.org/wiki/Zebra_Puzzle 1.There are five houses. 2.The Englishman lives in the red house. 3.The Spaniard owns the dog. 4.Coffee is drunk in the green house. 5.The Ukrainian drinks tea. 6.The green house is immediately to the right of the ivory house. 7.The Old Gold smoker owns snails. 8.Kools are smoked in the yellow house. 9.Milk is drunk in the middle house. 10.The Norwegian lives in the first house. 11.The man who smokes Chesterfields lives in the house next to the man wi= th the fox. 12.Kools are smoked in the house next to the house where the horse is kep= t. 13.The Lucky Strike smoker drinks orange juice. 14.The Japanese smokes Parliaments. 15.The Norwegian lives next to the blue house. Note: This program takes lots of time/space, press cntrl-C to exit. (a_logic_p2.cpp is more practical) */ #include <Wy.stdio.h> #include <Sc/PropExpr.h> using namespace Wy; using namespace Sc; constexpr WeName Red("Red"); constexpr WeName Yellow("Yellow"); constexpr WeName Blue("Blue"); constexpr WeName Ivory("Ivory"); constexpr WeName Green("Green"); constexpr WeName Norweg("Norweg"); constexpr WeName Ukrain("Ukrain"); constexpr WeName English("English"); constexpr WeName Spani("Spani"); constexpr WeName Japan("Japan"); constexpr WeName Water("Water"); constexpr WeName Tea("Tea"); constexpr WeName Milk("Milk"); constexpr WeName Orange("Orange"); // OrangeJuice constexpr WeName Coffee("Coffee"); constexpr WeName Kools("Kools"); // Kools constexpr WeName Chest("Chest"); // Chesterfield constexpr WeName OldGold("OldGold"); // OldGold constexpr WeName Lucky("Lucky"); // LuckyStrike constexpr WeName Parl("Parl"); // Parliament constexpr WeName Fox("Fox"); constexpr WeName Horse("Horse"); constexpr WeName Snail("Snail"); constexpr WeName Dog("Dog"); constexpr WeName Zebra("Zebra"); constexpr WeName No1("No1"); constexpr WeName No2("No2"); constexpr WeName No3("No3"); constexpr WeName No4("No4"); constexpr WeName No5("No5"); PropExpr same_house(WeName m1, WeName m2) { return propSEL( propAND(Prop(No1,m1),Prop(No1,m2)), propAND(Prop(No2,m1),Prop(No2,m2)), propAND(Prop(No3,m1),Prop(No3,m2)), propAND(Prop(No4,m1),Prop(No4,m2)), propAND(Prop(No5,m1),Prop(No5,m2)) ); }; PropExpr next_house(WeName m1, WeName m2) { return propSEL( PropExpr(Prop(No1,m1))&&PropExpr(Prop(No2,m2)), PropExpr(Prop(No2,m1))&&propXOR(Prop(No1,m2),Prop(No3,m2)), PropExpr(Prop(No3,m1))&&propXOR(Prop(No2,m2),Prop(No4,m2)), PropExpr(Prop(No4,m1))&&propXOR(Prop(No3,m2),Prop(No5,m2)), propAND(Prop(No5,m1),(Prop(No4,m2))) ); }; PropExpr map11(WeName n1, WeName n2, WeName n3, WeName n4, WeName n5) { return propSEL(Prop(No1,n1),Prop(No1,n2),Prop(No1,n3),Prop(No1,n4),Prop(No1,n5)= )&& propSEL(Prop(No2,n1),Prop(No2,n2),Prop(No2,n3),Prop(No2,n4),Prop(No2,n5)= )&& propSEL(Prop(No3,n1),Prop(No3,n2),Prop(No3,n3),Prop(No3,n4),Prop(No3,n5)= )&& propSEL(Prop(No4,n1),Prop(No4,n2),Prop(No4,n3),Prop(No4,n4),Prop(No4,n5)= )&& propSEL(Prop(No5,n1),Prop(No5,n2),Prop(No5,n3),Prop(No5,n4),Prop(No5,n5)= )&& propSEL(Prop(No1,n1),Prop(No2,n1),Prop(No3,n1),Prop(No4,n1),Prop(No5,n1)= )&& propSEL(Prop(No1,n2),Prop(No2,n2),Prop(No3,n2),Prop(No4,n2),Prop(No5,n2)= )&& propSEL(Prop(No1,n3),Prop(No2,n3),Prop(No3,n3),Prop(No4,n3),Prop(No5,n3)= )&& propSEL(Prop(No1,n4),Prop(No2,n4),Prop(No3,n4),Prop(No4,n4),Prop(No5,n4)= )&& propSEL(Prop(No1,n5),Prop(No2,n5),Prop(No3,n5),Prop(No4,n5),Prop(No5,n5)= ) ; }; // 1.There are five houses. const PropExpr R1=3D map11(Red,Yellow,Blue,Ivory,Green)&& map11(Norweg,Ukrain,English,Spani,Japan)&& map11(Water,Tea,Milk,Coffee,Orange)&& map11(Kools,Chest,OldGold,Lucky,Parl)&& map11(Fox,Snail,Horse,Dog,Zebra); // 2.The Englishman lives in the red house. const PropExpr R2( same_house(Red,English) ); // 3.The Spaniard owns the dog. const PropExpr R3( same_house(Spani, Dog) ); // 4.Coffee is drunk in the green house. const PropExpr R4( same_house(Green,Coffee) ); // 5.The Ukrainian drinks tea. const PropExpr R5( same_house(Ukrain, Tea) ); // 6.The green house is immediately to the right of the ivory house. const PropExpr R6=3D propSEL( propAND(Prop(No1,Ivory), Prop(No2,Green)), propAND(Prop(No2,Ivory), Prop(No3,Green)), propAND(Prop(No3,Ivory), Prop(No4,Green)), propAND(Prop(No4,Ivory), Prop(No5,Green)) ) && propNOR(Prop(No5,Ivory),Prop(No1,Green)); // 7.The Old Gold smoker owns snails. const PropExpr R7( same_house(OldGold, Snail) ); // 8.Kools are smoked in the yellow house. const PropExpr R8( same_house(Yellow, Kools) ); // 9.Milk is drunk in the middle house. const PropExpr R9( Prop(No3,Milk) ); // 10.The Norwegian lives in the first house. const PropExpr R10( Prop(No1,Norweg) ); // 11.The man who smokes Chesterfields lives in the house next to the man = with the fox. const PropExpr R11( next_house(Chest, Fox) ); // 12.Kools are smoked in the house next to the house where the horse is k= ept. const PropExpr R12( next_house(Kools, Horse) ); // 13.The Lucky Strike smoker drinks orange juice. const PropExpr R13( same_house(Lucky, Orange) ); // 14.The Japanese smokes Parliaments. const PropExpr R14( same_house(Japan, Parl) ); // 15.The Norwegian lives next to the blue house. const PropExpr R15( next_house(Norweg, Blue) ); void t0() { ========== REMAINDER OF ARTICLE TRUNCATED ==========