0hc.net Menu
Home Overview
About Menu
Impressum

nextPerm

Moonscript: pLen = 4 a = {} for i=0, pLen-1 a[i]=i pr = (a) -> for i=0, #a io.write a[i], " " print! nextPerm = (a) -> i=#a-1 while not (i<0 or a[i]<a[i+1]) i-=1 if i<0 return false j=#a while not (a[j]>a[i]) j-=1 a[i], a[j] = a[j], a[i] for j=i+1, (#a+i)/2 a[j], a[#a+1+i-j] = a[#a+1+i-j], a[j] return true pr a while nextPerm a pr a
0hc.net    © 2001-2014 Harald Wolfsgruber