class Hanoi { int disks; string target, source, aux; public Hanoi(int disks, string source, string target, string aux) { this.disks=disks; this.source=source; this.target=target; this.aux=aux; } public IEnumerable Movements { get {return new Iterator(new IteratorMethod(HanoiMethod));} } void HanoiMethod(IYield y) { HanoiMethod(y, disks, source, target, aux); } void HanoiMethod(IYield y, int disks, string source, string target, string aux) { if (disks==1) y.Yield("Move from " + source + " to " + target); else { HanoiMethod(y, disks-1,source, aux, target); y.Yield("Move from " + source + " to " + target); HanoiMethod(y, disks-1,aux, target, source); } } } |