static IterableIterator> allSpreads(final int toSpread, final int buckets) { class StackEntry { int remaining, n, take; L collecting; int position; L step(L stack) { if (position == 0) { if (l(collecting) >= n-1) { result = listPlus(cloneList(collecting), remaining); dropLast(stack); ret result; } position = 1; } else if (position == 1) { if (take <= remaining) { collecting.add(take); new StackEntry e; e.remaining = remaining-take; e.n = n; e.collecting = collecting; stack.add(e); } else { if (empty(stack)) ret endMarker(); dropLast(stack); } } else if (e.position == 2) { removeLast(e.collecting); e.take++; e.position = 1; } } } final new L stack; new StackEntry e; e.n = buckets; e.remaining = toSpread; e.collecting = new L; stack.add(e); ret iff(new F0 { while true { ping(); L result = last(stack).step(stack); if (result != null) ret result; } }); }