From: mekly Date: 2005-12-03T10:02:40+09:00 Subject: Re: Programming Newbie: Ruby or Java? > """the reality is that the real world and universities don't always > match up.""" > > I'm a current CS student at ASU (arizona, US) and this statement is SO true. :/ > Besides learning Java, C, & C++... I've had to learn Lisp/Scheme and Prolog. > I mean who uses Prolog?? It's basically dead. > School teaches theory mostly. > Experience teaches you the rest I guess. Many problems in "the real world" (planning, scheduling, etc.) are not so easy to handle in the "living" languages like Java or C++. So, universities are trying to prepare you for "the real world." In many cases a "dead" language like Prolog might be of great help. Of course, it's difficult to give here a non-trivial, industry- specific example (need background). So, below is a five star puzzle solved in GNU Prolog/CLP(FD). I'd love to see how to solve it in any of those practical languages. Best Regards, Leon --------------------------------------------------------------- % Chess Tournament Logic Problem % http://www.geocities.com/Heartland/Plains/4484/lp9705.htm % Copyright � 1997 William T. Pelletier % Stars: 5 % During the final round of Georgia's All-State Chess Tournament, % the eventual top 4 finishers in the tournament played their final % game against 4 different opponents. The tournament boards were % numbered from 1 to 50 to facilitate location and identification % of games. Each of the top 4 finishers played a different opening % in this last game. Use the clues below to determine the first and last % names of the first through fourth place winners of the tournament, % the chess opening each used in his last game, and the number of the % chess board on which he played his final game. % 1. Mr. Hart played the King's Indian Defence. % 2. Steve placed ahead of the one who used the Ruy Lopez opening. % 3. The top 4 players were Larry, Mr. Korn, the contestant who opened % with Queen's Gambit, and a player who played on an even-numbered board. % 4. Mr. Rose finished exactly 2 places ahead of the player on board 31. % 5. The number of the 3rd place winner's board is at least 10 higher or % at least 10 lower than that of Mr. Baird. % 6. The number of the board of the contestant who placed immediately % after Bert is exactly 15 higher than the number of the board played % by the one who placed immediately before Tom. % 7. The lowest board number of the top 4 finishers was exactly half the % number of the board played by the one who placed immediately after % the one who played the Giuoco Piano opening. % 8. The highest board number was exactly 8 higher than the board number % of the man who finished exactly two places after Bert. % Answer: % PLACE 1ST NAME SURNAME OPENING BOARD % First Steve Rose Queen's Gambit #40 % Second Bert Baird Ruy Lopez #16 % Third Tom Korn Giuoco Piano #31 % Fourth Larry Hart King's Indian #32 % ----------------------------------------------------------------------- % GNU Prolog CLP(FD) solution by Leon J. Mekly - 2/20/05 chess :- % Chess Board numbers - first through fourth place Bs = [B1,B2,B3,B4], fd_domain(Bs,1,50), fd_all_different(Bs), % List of players p(Place,Fname,Lname,Opening,BoardNumber) PBs = [ p(1,_,_,_,B1), p(2,_,_,_,B2), p(3,_,_,_,B3), p(4,_,_,_,B4) ], % First Name Places (FNPs) FNPs = [Pbert,Plarry,Psteve,Ptom], fd_domain(FNPs,1,4), fd_all_different(FNPs), % Last Name Places (LNPs) LNPs = [Pbaird,Phart,Pkorn,Prose], fd_domain(LNPs,1,4), fd_all_different(LNPs), % Opening Places (OPs) OPs = [Pgambit,Pindian,Plopez,Ppiano], fd_domain(OPs,1,4), fd_all_different(OPs), Names = [ p(Pbert,bert,_,_,_), p(Plarry,larry,_,_,_), p(Psteve,steve,_,_,_), p(Ptom,tom,_,_,_), p(Pbaird,_,baird,_,_), % 1. Mr. Hart played the King's Indian Defence. p(Phart,_,hart,indian,_), p(Pkorn,_,korn,_,_), p(Prose,_,rose,_,_), p(Pgambit,_,_,gambit,_), p(Pindian,_,hart,indian,_), p(Plopez,_,_,lopez,_), p(Ppiano,_,_,piano,_) ], Phart #= Pindian, % 2. Steve placed ahead of the one who used the Ruy Lopez opening. Psteve #< Plopez, Psteve #< 4, Psteve #= 1 #<=> Plopez #= 2 #\/ Plopez #= 3 #\/ Plopez #= 4, Psteve #= 2 #<=> Plopez #= 3 #\/ Plopez #= 4, Psteve #= 3 #<=> Plopez #= 4, % 3. The top 4 players were Larry, Mr. Korn, the contestant who opened % with Queen's Gambit, and a player who played on an even-numbered board. fd_domain(Bx,1,50), fd_all_different([Plarry,Pkorn,Pgambit,Bx]), Plarry+Pkorn+Pgambit #= 9 #<=> Bx #= B1 #/\ B1 rem 2 #= 0, Plarry+Pkorn+Pgambit #= 8 #<=> Bx #= B2 #/\ B2 rem 2 #= 0, Plarry+Pkorn+Pgambit #= 7 #<=> Bx #= B3 #/\ B3 rem 2 #= 0, Plarry+Pkorn+Pgambit #= 6 #<=> Bx #= B4 #/\ B4 rem 2 #= 0, % 4. Mr. Rose finished exactly 2 places ahead of the player on board 31. Prose #< 3, Prose #= 1 #<=> B3 #= 31, Prose #= 2 #<=> B4 #= 31, % 5. The number of the 3rd place winner's board is at least 10 higher or % at least 10 lower than that of Mr. Baird. Pbaird #\= 3, Pbaird #= 1 #<=> B3 #>= B1 + 10 #\/ B3 #=< B1 - 10, Pbaird #= 2 #<=> B3 #>= B2 + 10 #\/ B3 #=< B2 - 10, Pbaird #= 4 #<=> B3 #>= B4 + 10 #\/ B3 #=< B4 - 10, % 6. The number of the board of the contestant who placed immediately % after Bert is exactly 15 higher than the number of the board played % by the one who placed immediately before Tom. Pbert #< 4, Ptom #> 1, Pbert #= 1 #<=> B2#=B1+15 #\/ B2#=B3+15, Pbert #= 2 #<=> B3#=B2+15, Pbert #= 3 #<=> B4#=B1+15 #\/ B4#=B3+15, % 7. The lowest board number of the top 4 finishers was exactly half the % number of the board played by the one who placed immediately after % the one who played the Giuoco Piano opening. Ppiano #< 4, Ppiano #= 3 #<=> B4#=B1+B1 #/\ B1# B3#=B1+B1 #/\ B1# B2#=B1+B1 #/\ B1# B1 #= B3 + 8 #/\ B1#>B2 #/\ B1#>B4 #\/ B2 #= B3 + 8 #/\ B2#>B1 #/\ B2#>B4 #\/ B4 #= B3 + 8 #/\ B4#>B1 #/\ B4#>B2, Pbert #= 2 #<=> B1 #= B4 + 8 #/\ B1#>B2 #/\ B1#>B3 #\/ B2 #= B4 + 8 #/\ B2#>B1 #/\ B2#>B3 #\/ B3 #= B4 + 8 #/\ B3#>B1 #/\ B3#>B2, listVars([FNPs,LNPs,OPs,Bs],[],VarList), fd_labelingff(VarList), match(Names,PBs), (member(P,PBs),write(P),nl,fail ; true). listVars([],L,L). listVars([L|Ls],T,Flat) :- append(L,T,NT), listVars(Ls,NT,Flat). match([],_). match([P|Ps],Bs) :- member(P,Bs), match(Ps,Bs).