tag:blogger.com,1999:blog-8761368585569527306.post1418871057902544314..comments2013-03-17T03:08:15.880-07:00Comments on /dev/null: This Week's Coding Practice: Stacks and the Tower of HanoiAnonymoushttp://www.blogger.com/profile/09657194319507369108noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-8761368585569527306.post-88360391723011618482013-02-25T16:46:47.012-08:002013-02-25T16:46:47.012-08:00Thanks for commenting ;)
First, I don't know ...Thanks for commenting ;)<br /><br />First, I don't know where you got the number 343 from. hanoi.py is 69 lines, with comments. So the Prolog:Python ratio is less than 1:10. The other two files are part of the separate JavaScript solution, most of which is drawing functions and other GUI boilerplate. <br /><br />Second, I don't think comparing my solution to a Prolog one facilitates a fair or meaningful comparison of declarative or imperative. A significant part of the Python solution was implementing a search -- that part is conveniently built into Prolog. If you really want to compare line counts, have a look at http://www.python-course.eu/towers_of_hanoi.php -- their solution is a little over 10 lines.Anonymoushttps://www.blogger.com/profile/09657194319507369108noreply@blogger.comtag:blogger.com,1999:blog-8761368585569527306.post-69845094073741947072013-02-25T16:16:36.091-08:002013-02-25T16:16:36.091-08:00Good expample to compare declarative and imperativ...Good expample to compare declarative and imperative styles of programming.<br /><br />There is an assumption that 1 line of declarative style code requires 20 lines of imperative code.<br /><br />So, we have 343 lines of Pythone lines so far.<br />Comparing them with 9 lines of Prolog code give us ratio of 1:38!!!<br /><br />Well done!<br /><br />Below is Prolog source....<br /><br /> hanoi:-hanoi(5).<br /> hanoi(N) :- move(N, left, middle, right).<br /> move(1, A, _, C) :- inform(A, C), !.<br /> move(N, A, B, C) :-<br /> N1 is N-1,<br /> move(N1, A, C, B),<br /> inform(A, C), !,<br /> move(N1, B, A, C).<br /> inform(Loc1, Loc2) :- write("Move a disk from ", Loc1, " to ", Loc2),nl, !.Anonymoushttps://www.blogger.com/profile/10197257854940987948noreply@blogger.com