Comment detail

循環関数 (Nested Flatten)

剰余を出す関数には mod と rem がありますが、mod は割って負の無限大、rem は 0 方向に丸めた余りを返します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(defun modular (n low high) (+ low (mod n (- high low -1))))

;;; test
(loop for (n low high ans) in
  '((0 100 200 100)
    (50 100 200 150)
    (100 100 200 200)
    (101 100 200 100)
    (-1 100 200 200)
    (1 -5 200 -4)
    (-500 -5 -1 -5))
  do (assert (= (modular n low high) ans))
  finally (princ :ok))

Index

Feed

Other

Link

Pathtraq

loading...