VI SOLVES MAZE (update)

Greg McFarlane gregm at otc.otca.oz.au
Mon Jan 14 11:28:40 AEST 1991


Thanks for all those who wrote to me about my maze-solving vi macros.
To quote some of the reviews:
	"I was very impressed ..."
	"A-maze-ing!"
	"ABSOLUTELY THE GREATEST THING I'VE SEEN IN YEARS!"
	"it just flat blew me away"
	"AMAZING!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	"Wow." (from rsalz at bbn.com him/herself)

If you haven't already seen these amazing macros at work, you have
another chance with this update.

To get the correct ending message, ":set noterse" should be done. I have
modified the macros below to do this. (This is probably not worth the effort.)

Anyone who can't get the maze.c file to compile, get a new compiler. I have
included a 5-line maze below for you.

If you can compile it but the maze comes out looking like a fence
and not a maze and you are using SysV or DOS replace the "27" on the
last line by "11"

If you try to figure out how the macros work and wimp out, I will
send a commented version of the macros to anyone who mails me.

By the way, I learnt about the power of vi macros from an item posted by
Dave Hitz to comp.sources.misc: v02i057: vi macros simulate a Turing Machine.
I recommend this to anyone interested in such trivia.

What follows is a repeat of my previous posting, with ":set noterse" added
to the macros, and with a maze to keep those with buggy compilers happy.

=========================================================================

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 net last month. (Maze.c is also included below.)

Just follow this recipe and SEE FOR YOURSELF.
	1. save this article and strip off all lines except those between
		the "cut here for vi macros" markers
	2. run uudecode on the file to produce "maze.vi.macros"
	3. if you haven't already done so, compile maze.c
		(cc -o maze maze.c)
	4. run maze > maze.out and input a small number (for example 10 if
		you are on a fast machine, 3-5 if slow) which
		is the size of the maze to produce
	5. edit the maze (vi maze.out)
	6. include the macros with the vi command:
		:so maze.vi.macros
	7. type the letter "g" (for "go") and watch vi solve the maze
	8. when vi solves the maze, you will see why it lies

Tested on a sparc, a sun and a pyramid (although maze.c will not compile
on the pyramid).

Any donations should be in unmarked small denomination bills :^)=.

uuencoded maze.vi.macros:
(note that the second last line (above "end") consists of a single space)
----------------- cut here for vi macros ----------------------
begin 664 maze.vi.macros
M<V5T(')E;6%P"G-E="!N;VUA9VEC"G-E="!N;W1E<G-E"FUA<"!G($E,"FUA
M<"!)($<_+ at U>,D=1;&UA1UE*>DIE2D1*2U P4V!A"FUA<"!,(%%!;6%'3D(P
M33!%0&T-=UA at 84!M1U0D0B12,$TP14!M#69:8E-B6$=62C!(8&% <D!M50IM
M87 @52!,"FUA<"!1(")C>6P*;6%P($$@<D\*;6%P(%X@<E@*;6%P($X at 0R]N
M&PIM87 @0B B<W *;6%P($T@(FUY) IM87 @5"!#+W,;"FUA<"!2(")N< IM
M87 @4R B<WEL"FUA<"!8(")M>70@"FUA<"!6(&%R&PIM87 @2B B8W *;6%P
M($@@(G)Y) IM87 @1B B;GEL"FUA<"!9(&]S02 @:R!%6B!S05\@;6T at 0EH@
M<T(;"FUA<"!Z("1A(&UM($=:('-"("!L;"!!6B!S0BX@;&P at 05H@<T,@(&H@
M1UH@<T,N(&H at 1UH-<T-?(&UM($1:('-$&PIM87 @92 D82!M;2!%6B!S1"X@
M:&@@0UH@<T4N(&AH($-:('-%&PIM87 @1" D82!M;2!&6B!S1B @:R!%6B!S
M1E\@;6T at 05H-<T<N(&QL($%:('-'("!L;"!!6B!S1QL*;6%P($L@)&$@;6T@
M2%H@<T@@(&H at 1UH@<TA?(&UM($-:&PIM87 @4"!O;D$@:T8@;D(@;$8@;D,@
M1R1*1B!N1"!H1B!N12!H1B!N1B!K1B!N1R!L1B!N2"!')$I&( U!&PIM87 @
%12!D) IN
 
end
----------------- cut here for vi macros ----------------------


maze.c: (if using SysV or DOS replace the "27" on the last line by "11")
credit to John Tromp (tromp at piring.cwi.nl)
----------------- cut here for maze.c ----------------------
char*M,A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf(M="%d",&C);
--            E;             J[              E]             =T
[E   ]=  E)   printf("._");  for(;(A-=Z=!Z)  ||  (printf("\n|"
)    ,   A    =              39              ,C             --
)    ;   Z    ||    printf   (M   ))M[Z]=Z[A-(E   =A[J-Z])&&!C
&    A   ==             T[                                  A]
|6<<27<rand()||!C&!Z?J[T[E]=T[A]]=E,J[T[A]=A-Z]=A,"_.":" |"];}
----------------- cut here for maze.c ----------------------

----------------- cut here for maze.out (5-line maze) ------
._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
| ._| . . ._| | |_._._. . ._|_._._._._. ._|_. ._|_._. ._| | . ._|_. | . ._._. |
| ._|_| |_. | | | | ._._|_._|_._. . |_. | | | ._._| |_._._._| | ._. ._| . . |_|
|_._._._. | ._|_. ._._._. | | ._. |_._. . | ._._| |_. | . ._._._. |_. | |_|_| |
| | . |_._| . ._._._| ._._. ._._| | | |_| . | |_. . ._|_|_| ._._. |_._|_| . | |
|_._|_._._._|_._._._|_|_._._._|_._|_._._._|_._._._|_._._._._|_._._._._._._|_._|
----------------- cut here for maze.out (5-line maze) ------

-- 

                   ACSnet:  gregm at otc.otca.oz.au
Greg McFarlane       UUCP:  {uunet,mcvax}!otc.otca.oz.au!gregm
|||| OTC ||         Snail:  OTC R&D GPO Box 7000, Sydney 2001, Australia
                    Phone:  +61 2 287 3139    Fax: +61 2 287 3299
$B%$%C%U(J $B%f!<(J $B%+%s(J $B%j!<%C%I(J $B%:%#%9(J $B!<(J $B%9%^%$%k(J



More information about the Alt.sources mailing list