class Cycle
def cycle(*args)
args[((@_cycles ||= Hash.new(-1))[args.hash] += 1) % args.size]
end
end
More beautiful code plees?
Name:
Anonymous2009-08-27 0:51
>>1
If what >>12 said was right, here's how to do it in CL:
(let ((ht (make-hash-table :test #'equal)))
(defun cycle (&rest args)
(unless (gethash args ht)
(setf (gethash args ht) args))
(pop (gethash args ht))))