From: Matthew Smillie Date: 2005-12-04T12:33:53+09:00 Subject: Re: Programming Newbie: Ruby or Java? On Dec 3, 2005, at 20:47, William James wrote: >> % 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 >> % >> --------------------------------------------------------------------- >> -- > > I think that your answer is wrong. There are 3 solutions: > > 1. Steve Baird Giuoco Piano 12 > 2. Bert Rose Queen's Gambit 24 > 3. Tom Korn Ruy Lopez 39 > 4. Larry Hart King's Indian 31 > > 1. Steve Rose Giuoco Piano 8 > 2. Bert Baird Queen's Gambit 16 > 3. Tom Korn Ruy Lopez 31 > 4. Larry Hart King's Indian 23 > > 1. Steve Rose Queen's Gambit 40 > 2. Bert Baird Ruy Lopez 16 > 3. Tom Korn Giuoco Piano 31 > 4. Larry Hart King's Indian 32 > > Evidently Prolog isn't well suited for logic problems. I wonder > what it is good for. I'd not celebrate too fast or too much. The given answer is identical to one of yours. I'm not sure how that makes it wrong, exactly, but if you mean that not all answers are generated, this is a fairly simple thing to address: it's a matter of two keystrokes (';', 'enter') to generate further consistent answers for non- deterministic systems in the prolog interpreter. If you want a short insight into the use of learning about prolog, let's use another example: sudoku. Take a look at ruby quiz 43 here: http://www.rubyquiz.com/quiz43.html Now here's a simple prolog solver, strictly for a quick comparison: http://user.it.uu.se/~justin/sudoku.pl To me, the interesting part of the comparison isn't some arbitrary discussion about lines of code or readability, or what language can solve what problem[1], but rather that every single Ruby solution (and I looked at them all) implements a very particular feature of prolog to get at the answer: the non-deterministic 'reducing possibilities for each cell' concept is built right into prolog. In fact, this concept is absolutely central to the language. If you can't take a lesson out of that, well, I'd start getting worried about that "outsourcing" thing if I were you. matthew smillie. [1] If you want to believe a strong version of the Curry-Howard isomorphism, (http://en.wikipedia.org/wiki/Curry-Howard) then it's thoroughly unsurprising that what can be done correctly in one language can also be done correctly in another. It's even less surprising if you remember that any Turing machine can implement any other Turing machine. Of course, if you didn't pay attention in your introductory course in CS because you were too worried about "practical" languages, this *might* be surprising, and you might get drawn into a lot of "my language can beat up your language" sort of arguments. --- nit-picking --- I've left this down here because I don't think it's that important of a point, but given the triumphalist nature of the "prolog isn't well suited for logic problems" comment, I don't think it should go unmentioned: matt% time ruby chess.rb 287.266u 3.160s 5:28.55 88.3% 0+0k 0+1io 0pf+0w Almost five minutes? To solve 8 constraints on 4 lists of 5 elements? I mean, ok, it's a quick and dirty brute force hack, but how is this honestly supposed to convince anyone to use Ruby for anything, let alone discard prolog for constraint programming?