Groovy web console

subscribe to the feed Subscribe
to this
site

Test

Published 6 years ago by Test
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
rotR={s->s[0]!=0?[0,-1*s[0]]:[s[1],0]}
rotL={s->s[0]!=0?[0,s[0]]:[-1*s[1],0]}
def y(s){z(new String[s.length()][s.length()],[s.length()/2,s.length()/2],s,null,[0,1])}
def z(g, l, w, p, h) {if (w.length() && !g[(int)(l[0]+h[0])][(int)(l[1]+h[1])]) {c=w.getAt(0);w=w.substring(1);if(p && p<c){h=rotR(h)}else if(p > c){h=rotL(h)};g[(int)l[0]+h[0]][(int)l[1]+h[1]]=c;z(g,[l[0]+h[0],l[1]+h[1]],w,c,h)}else{g}}

y('spattuuxze').each {
  it.each {
    print it ?: ' '
  }
  print '\n'
}