Brian Schott pointed out to me that my gnome sort does not work
for text.

This is because
  'a' > 'b'
|domain error

So, to work around this issue:

gt=: -.@(-: /:~)@,"_1

   'a' gt 'b'
0
   'b' gt 'a'
1

The resulting definitions become:

position=: 0 {...@i.@, [
swap=: ] A.~ *...@position * #...@[ !...@- <:@position
gt=: -.@(-: /:~)@,"_1
gnome=: swap~ 2 gt/\ ]
gnomes=: gnome^:_
gnomeps=: gnome^:a:

Also, note that gnomeps does not directly show the
gnome's position.  To find where the gnome was
standing, you can use something like:

   2 ~:/\ gnomeps 'abcba'
0 0 1 1 0
0 0 0 1 1
0 0 1 1 0
0 1 1 0 0

Or, if you prefer
   </\"1]2 ~:/\ gnomeps 'abcba'
0 0 1 0 0
0 0 0 1 0
0 0 1 0 0
0 1 0 0 0

"Improving" the display is left as an exercise
for the student.  This is made somewhat tricky
by the fact that garden gnomes are not ascii
characters.

FYI,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to