begin quoting Barry Gershenfeld as of Tue, Jan 08, 2008 at 11:05:28AM -0800: > >sliding-tile puzzle of a lizard. There were 8 pieces on a little 3x3 > > > >That night, the cat got up in my lap, arranged itself across my > >forearms, so I decided to "solve" the 3x3 8-piece sliding tile puzzle. > > >Now, this would have been an ideal time to try out Ruby, but with a > >purring cat trapping my arms, that wasn't really practical. > > Just once, I wanna see c/cat/wife
Not much code gets written then. > >Same with perl or TCL... I'd need a reference book at hand, and that > >wasn't going to happen unless I dumped the cat. And it's just wrong > >to dump a purring cat, so I fell back on that old standby we call C. > > So, you're still able to operate. Books aren't really required; with the > Web you have all the reference material available. Admittedly, some are > better than others. PHP shines here. Of course, with the web, you need a mouse (not readily accessible) or lynx (not always very good for reference material). I had manpages near at hand. > >Just for fun. It's just 'noodling'... futzing around, really, until > >I got a reasonable answer. Then I went to bed. > > Just as I expected. Stewart coughs, and out comes runnable code. Nah, I had a couple of boneheaded errors that resulted in memory corruption and segfaults. > >There's lots of stuff to criticize. Have fun. > >----------------------------------------------------------------------------- > > * $Id: sliding_nine.c,v 1.2 2007/12/24 19:55:58 stremler Exp $ > > Aren't we supposed to embed this in the object somehow ( :) ...troll ) Actually, that's a good point. > I let the machine do the criticizing. Who am I to judge? Who do you have to be? > $ gcc sliding_nine.c -o sli -Wall Ah, "failed to compile with -Wall", another one. > sliding_nine.c: In function `make_deque': > sliding_nine.c:74: warning: control reaches end of non-void function Yup, bug. > sliding_nine.c: In function `new': > sliding_nine.c:206: warning: unused variable `a' > sliding_nine.c:206: warning: unused variable `b' > sliding_nine.c: In function `fill_children': > sliding_nine.c:246: warning: unused variable `p' > sliding_nine.c:247: warning: unused variable `temp' Yup, code needs to be cleaned up. > Okay, but the premise is that it /runs/ > > $ ./sli.exe > Usage: ./sli start end > start = 9 character board configuration > end = 9 character board configuration > (Note that a blank is REQUIRED!) > > $ ./sli.exe 246813579 123456789 > Starting with '246813579' and trying for '123456789' > start: 0x9700f8 end: 0x970120 > Bad board configuration: '246813579' in sliding_nine.c at 259 > Segmentation fault (core dumped) Hm. That should be an exit() as well. So, -Wall is a big one. :) > Hmm...OK, there should only be 8 tiles of the 9. "Note that a blank is > REQUIRED!" > > $ ./sli.exe 2468135 7 1234567 8 > Usage: ./sli start end > start = 9 character board configuration > end = 9 character board configuration > (Note that a blank is REQUIRED!) > > Umm...blank as delimiter, blank as...oh, I did learn something about shells: > > $ ./sli.exe "2468135 7" "12345678 " > Starting with '2468135 7' and trying for '12345678 ' > start: 0x9700f8 end: 0x970120 > > (now it's thinking)... > > [2] [4] [6] > [8] [1] [3] > [5] [ ] [7] > > [2] [4] [6] > [8] [ ] [3] > [5] [1] [7] > > and so on, until > > [1] [2] [3] > [4] [5] [6] > [7] [8] [ ] > All correct, I presume? > Okay, I learned this, too: > > $ time ./sli.exe "2468135 7" "12345678 " > sli.txp > > real 0m37.930s > user 0m0.000s > sys 0m0.000s > > ...on a screamin' 533MHz Pentium, in cygwin, under Windows 98. > ...uphill, both ways. Shift! Shift! > (Okay peanut gallery, this is where you post /your/ time...) What, it has bugs, and you want to test *performance*? :-P -- Always remember to use dash Wall To ensure cleanliness of you call Stewart Stremler -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
