Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!metro!otc!gregm From: gregm@otc.otca.oz.au (Greg McFarlane) Newsgroups: comp.editors Subject: VI SOLVES MAZE (commented macros) Message-ID: <2300@otc.otca.oz> Date: 12 Feb 91 01:40:18 GMT Sender: news@otc.otca.oz Reply-To: gregm@otc.otca.oz.au (Greg McFarlane) Organization: OTC Development Unit, Australia Lines: 464 Submitted-by: gregm@otc.otca.oz.au Archive-name: maze_solving_vi_macros A real working model. See it walk the maze in front of your very own eyes. To prove that you can do anything in vi, I wrote a couple of macros that allows vi to solve mazes. It will solve any maze produced by maze.c that was posted to the alt.sources last month. (Maze.c is also included in this posting as well as an example of its output.) The uncommented version of the macros was sent to alt.sources last month. However, so many people mailed me requesting the commented version of the macros that I decided to post it. I have made some modifications to the original macros to make them easier to follow and also after I learnt that you can escape the special meaning of '|' in macros by using '^V|'. Save this article and unshar it. Then read maze.README. After studying these macros, anyone who cannot write an emacs emulator in vi macros should just curl up and :q!. Coming soon to a newsgroup near you: "Vi macros solve Tower of Hanoi", and a repost of the original "Turing Machine implemented in Vi macros" Anyone who has a version of these macros for edlin or nroff, please post. ---- Cut Here and unpack ---- #!/bin/sh # This is maze_solving_vi_macros, a shell archive (shar 3.32) # made 02/07/1991 14:24 UTC by gregm@otc.otca.oz.au # Source directory /n/arrakis/u/sysdev/gregm/vi.macros # # existing files will NOT be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 1666 -rw-rw-r-- maze.README # 16793 -rw-rw-r-- maze.vi.macros.uu # 481 -rw-rw-r-- maze.out # 441 -rw-rw-r-- maze.c # 441 -rw-rw-r-- maze.ansi.c # if touch 2>&1 | fgrep 'amc' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= maze.README ============== if test X"$1" != X"-c" -a -f 'maze.README'; then echo "File already exists: skipping 'maze.README'" else echo "x - extracting maze.README (Text)" sed 's/^X//' << 'SHAR_EOF' > maze.README && XTo prove that you can do anything in vi, I wrote a couple of macros that Xallows vi to solve mazes. It will solve any maze produced by maze.c Xthat was posted to the net recently. X XJust follow this recipe and SEE FOR YOURSELF. X 1. run uudecode on the file "maze.vi.macros.uu" to X produce the file "maze.vi.macros" X (If you can't wait to see the action, jump to step 4) X 2. compile maze.c with "cc -o maze maze.c" X 3. run maze > maze.out and input a small number (for example 10 if X you are on a fast machine, 3-5 if slow) which X is the size of the maze to produce X 4. edit the maze (vi maze.out) X 5. include the macros with the vi command: X :so maze.vi.macros X 6. type the letter "g" (for "go") and watch vi solve the maze X 7. when vi solves the maze, you will see why it lies X 8. now look at maze.vi.macros and all will be revealed X XTested on a sparc, a sun and a pyramid (although maze.c will not compile Xon the pyramid). X XAnyone who can't get the maze.c file to compile, get a new compiler, Xtry maze.ansi.c which was also posted to the net. XIf you can get it to compile but the maze comes out looking like a fence Xand not a maze and you are using SysV or DOS replace the "27" on the Xlast line of maze.c by "11" XThanks to John Tromp (tromp@piring.cwi.nl) for maze.c. XThanks to antonyc@nntp-server.caltech.edu (Bill T. Cat) for maze.ansi.c. X XAny donations should be in unmarked small denomination bills :^)=. X X ACSnet: gregm@otc.otca.oz.au XGreg McFarlane UUCP: {uunet,mcvax}!otc.otca.oz.au!gregm X|||| OTC || Snail: OTC R&D GPO Box 7000, Sydney 2001, Australia X Phone: +61 2 287 3139 Fax: +61 2 287 3299 X X SHAR_EOF $TOUCH -am 0208005691 maze.README && chmod 0664 maze.README || echo "restore of maze.README failed" set `wc -c maze.README`;Wc_c=$1 if test "$Wc_c" != "1666"; then echo original size 1666, current size $Wc_c fi fi # ============= maze.vi.macros.uu ============== if test X"$1" != X"-c" -a -f 'maze.vi.macros.uu'; then echo "File already exists: skipping 'maze.vi.macros.uu'" else echo "x - extracting maze.vi.macros.uu (Text)" sed 's/^X//' << 'SHAR_EOF' > maze.vi.macros.uu && Xbegin 664 maze.vi.macros XM(B!4:&5S92!M86-R;W,@)W-O;'9E)R!A;GD@;6%Z92!P2!T XM:&4@82UM87IE+6EN9R!M87IE+F,@<')O9W)A;2X*(B *(B!&:7)S="P@82!B XM:70@;V8@;6%Z92!T:&5O6]U('=E6]UF4@:7,@=&\@<'5T('EO=7(@;&5F="!H86YD(&]N XM=&\@82!W86QL(&%N9"!J=7-T(&ME97 @=V%L:VEN9RP*(B!N979E6]U2!G=6%R86YT965D('1O"B(@=V]R:R!I9B!T:&4@;6%Z92!D;V5S(&YO XM="!H879E(&%N>2 G:7-L86YD6]UF4@:7,@;6%D XM92!U<"!O9B!H;W)I>F]N=&%L(&%N9"!V97)T:6-A;"!W86QL6]U2!O;F4@6]U2 Y XM,"!D96=R965S(&%N9"!R97!E870@6]U+"!S;R!S=&5P(&9OF4@<')O9'5C960@8GD@=&AE(&UA>F4N8R!P&ES=',@=&\@ XM=&AE(&YO&ES=',@=&\@ XM=&AE('-O=71H(&]F('EO=2!I9B!T:&4@8VAA6]U(&-O=6QD('5S92!A XM(&QO;W @=VET:"!I9B!S=&%T96UE;G1S(&%N9"!C;VYT:6YU92!S=&%T96UE XM;G1S+" *(B!(;W=E=F5R+"!T:&5S92!C;VYS=')U8W1S(&%R92!N;W0@879A XM:6QA8FQE(&EN('9I(&UA8W)O6]U(&AA=F4@8VAE8VME9"!I9B!T:&5R92!I&ES=&5N8V4@;W(@;F]T(&]F(&$@ XM=V%L;"!I;B!A"B(@<&%R=&EC=6QA'1#:&%R(')E9VES XM=&5R("AN*2X*(B *(B!3=&%T92!T86)L93H*(B!);B!T:&4@)W9I(&-O;6UA XM;F1S)R!C;VQU;6X@:7,@9VEV96X@=&AE(&%C=&EO;G,@=&\@8V%R'0@6]U XM(&AA=F4@=&\@;6%K92!L;W1S(&]F(&QI='1L92!M86-R;W,@86YD"B(@<'5T XM('1H96T@=&]G971H97(N"B(*(B!))VQL(&5X<&QA:6X@=VAA="!)(&UE86X@ XM8GD@86X@97AA;7!L92X@161I="!A(&9I;&4@86YD"B(@='EP92 G.FUA<"!1 XM(')8627!E("71H:6YG(&ES($]++B!)8&T@9&]I XM;F<@86QL('1H:7,@;VX@82!3<&%R8W-T871I;VXN"B(@268@86YY;VYE(')E XM861I;F<@=&AIF4@&%M:6YE(&UA8W)O2!C86QL:6YG(%4L('=H:6-H XM"B(@2!C;VYS:7-T XM:6YG(&]F('1H90HB(&QE='1E2 H XM:6YS=&5A9"!O9B!T>7!I;F<@)V32 M(&9I;F0@=&AE(&QA("T@F4*;6%P($D@("!')#\N#5Y'64ME1% P4S)'; HB"B(] XM/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T] XM/3T]/3T]/3T]/3T]/3T]/3T]"B(@3" M('1H92!L;V]P('=H:6-H(&ES(&5X XM96-U=&5D(&9O'1#:&%R('1A8FQE"B(@(" @(" @(" @ XM("!F;W(@=&AE(&-U32 M('EA;FL@=&AE XM(&-O;6UA;F0@:6YT;R!T:&4@36%C2!I XM;B!T:&4@=&%B;&4L(&YO=R!Y86YK('1H90HB(" @(" @(" @(" @9F]L;&]W XM:6YG('=O'1#:&%R(&EN(')E9VES=&5R(&X*(B @($=4)$(D4B M(&]N(&)O='1O;2!L XM:6YE+"!C2!I;B!T:&4@=&%B;&4L(&YO=R!Y XM86YK('1H90HB(" @(" @(" @(" @;F5X="!S=&%T92!I;G1O('1H92!3=&%T XM92!M86-R;PHB(" @(" @(&)8("T@86YD('EA;FL@=&AE(&%C=&EO;B!C;W)R XM97-P;VYD:6YG('1O('1H:7,@&5C XM='5T92!T:&4@;6%C&5C=71E('1H92!A8W1I XM;VX@87-S;V-I871E9"!W:71H('1H:7,@6%N:R!T:&4@;F5X="!T=V\@8VAA3)L"B(*(CT] XM/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T] XM/3T]/3T]/3T]/3T]/3T]/3T*(B!1("T@6%N:R!T:&ES(&QI;F4@:6YT;R!T XM:&4@36%C20*(@HB/3T]/3T]/3T]/3T]/3T]/3T]/3T] XM/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/3T]/0HB XM($8@+2!Y86YK($YE>'1#:&%R("AT:&ES(&UA8W)O(&ES(&-A;&QE9"!F("T@ maze.out && X._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ X| ._| . . ._| | |_._._. . ._|_._._._._. ._|_. ._|_._. ._| | . ._|_. | . ._._. | X| ._|_| |_. | | | | ._._|_._|_._. . |_. | | | ._._| |_._._._| | ._. ._| . . |_| X|_._._._. | ._|_. ._._._. | | ._. |_._. . | ._._| |_. | . ._._._. |_. | |_|_| | X| | . |_._| . ._._._| ._._. ._._| | | |_| . | |_. . ._|_|_| ._._. |_._|_| . | | X|_._|_._._._|_._._._|_|_._._._|_._|_._._._|_._._._|_._._._._|_._._._._._._|_._| X| SHAR_EOF $TOUCH -am 0208012491 maze.out && chmod 0664 maze.out || echo "restore of maze.out failed" set `wc -c maze.out`;Wc_c=$1 if test "$Wc_c" != "481"; then echo original size 481, current size $Wc_c fi fi # ============= maze.c ============== if test X"$1" != X"-c" -a -f 'maze.c'; then echo "File already exists: skipping 'maze.c'" else echo "x - extracting maze.c (Text)" sed 's/^X//' << 'SHAR_EOF' > maze.c && Xchar*M,A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf(M="%d",&C); X-- E; J[ E] =T X[E ]= E) printf("._"); for(;(A-=Z=!Z) || (printf("\n|" X) , A = 39 ,C -- X) ; Z || printf (M ))M[Z]=Z[A-(E =A[J-Z])&&!C X& A == T[ A] X|6<<27 maze.ansi.c && Xchar*M,A,Z,E=40,J[80],T[3];main(C){for(M=J+E,*J=A=scanf("%d",& XC) ;-- E;J [E ]=M X[E ]= E) printf("._"); for(;(A-=Z=!Z) || (printf("\n|" X) , A = 39 ,C -- X) ; Z || printf (T ))T[Z]=Z[A-(E =A[J-Z])&&!C X& A == M[ A] X|6<<11