Groovy : 122 chars ------------------ Golfed: m=args[0] as int a=[] a<<0 (1..m-1).each{n->b=a[n-1];x=b-n;(x>0&&(!a.contains(x)))?a[n]=x:(a[n]=b+n)} a.each{print "$it "} Ungolfed: m = args[0] as int a = [] a << 0 (1..m-1).each { n-> b = a[n-1] x = b-n (x>0 && (!a.contains(x)) ) ? a[n] = x : (a[n] = b+n) } a.each{print "$it "} Sample Run: bash$ groovy Rec.groovy 14 0 1 3 6 2 7 13 20 12 21 11 22 10 23