Ask a Question related to Ruby, Design and Development.
-
Martin DeMello #1
Re: Possible use for a continuation? [Generating all factors of a given number]
Harry Ohlsen <harryo@qiqsolutions.com> wrote:
Overkill - this should do it:> 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.
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
Martin DeMello Guest
-
RAND() generating same number in rapid sequence
I am using RAND() in rapid sequence, possibly on different connections. I expected to get different numbers from RAND(). I didn't. I get the same... -
Equivalent focal lengths and crop factors...
Haven't read here for a while. Wondered when all this would surface here. Well, it has and it won't go away, so maybe some clarification is in... -
continuation operator
What is the best way to utilize most recent continuation operator \ ? I recently copied Mac director files to PC and they have different... -
Possible use for a continuation? [Generating all factors of agiven number]
daz wrote: Darn! I was hoping to finally get a chance to use one :-). What I was really trying to achieve, though, was to have a generic... -
PDF viewers capable of high zoom factors
I have a map of the British mainland as a .pdf file. In order to see useful local details on it, I want to be able to zoom in by about 50x. I have...



Reply With Quote

