Groovy web console

subscribe to the feed Subscribe
to this
site

What a Fool I am

Published 4 years ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
l=[15,18,-6,18,9,-7,-1,7,19,19,-5,20,19,5,15,-5,3,18,14,19]
x={l,n->(l.size()..0).each{i->(0..i-2).each{if(l[it]>l[it+1] && n>0 && it>-1){l.swap(it,it+1)};n--}};l}
x(l,500)