From: Martin DeMello Date: 2003-07-09T15:29:09+09:00 Subject: Re: Possible use for a continuation? [Generating all factors of a given number] Harry Ohlsen wrote: > I have a feeling that some kind of recursive method that returns a > continuation might be the way to go, but I'm open to any suggestions, > whatsoever. Overkill - this should do it: class MultiCounter def initialize(a, b = nil) @max = a @min = b || a.map {0} raise "max and min arrays should have the same length" unless @max.length == @min.length @cur = @min end def next inc (@cur.length - 1) end def inc(i) return nil if i < 0 @cur[i] += 1 if @cur[i] > @max[i] @cur[i] = 0 return inc(i - 1) end @cur end end a = MultiCounter.new([3, 2, 2, 1]) while (b = a.next) p b end martin