Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun make-banks (&rest values)
- (coerce values 'vector))
- (defun find-max (banks &aux (index 0) imax vmax)
- (map ()
- (lambda (v)
- (when (or (not vmax) (> v vmax))
- (setf vmax v)
- (setf imax index))
- (incf index))
- banks)
- (values vmax imax))
- (defun level-step (banks)
- (prog1 banks
- (multiple-value-bind (max pos) (find-max banks)
- (let ((part (ceiling max (length banks))))
- (setf (aref banks pos) 0)
- (loop
- repeat (length banks)
- do
- (let ((amount (min max part)))
- (setf pos (mod (1+ pos) (length banks)))
- (incf (aref banks pos) amount)
- (decf max amount)))))))
- (defun fixpoint (bank)
- (let ((hash (make-hash-table :test #'equalp)))
- (loop
- for step from 0
- for key = (copy-seq bank)
- for past = (gethash key hash)
- until past
- do
- (setf (gethash key hash) step)
- (setf bank (level-step bank))
- finally
- (return
- (values step (- step past))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement