quot returns the quotient of dividing two numbers, truncating any fractional part. It is useful when whole items must be distributed without splitting them. section 5.7
Its contract is compact:
- Accepts numeric num and div arguments. section 5.7
- Returns the truncated quotient; a double input produces a double result. section 5.7
- Throws ArithmeticException when div is zero. section 5.7
Basic division and container sizing
(quot 38 4) ;; 9 (quot 38. 4) ;; 9.0 For distributing 900 items among containers, combine quot with rem to detect an uneven division and increase the container size when needed; the resulting optimal size is 41.
(defn optimal-size [n m]
(let [size (quot n m) ; #1
left? (zero? (rem n m))] ; #2
(if left?
size
(inc size))))
(optimal-size 900 22) ; #3
;; 41
(partition-all (optimal-size 900 22) (range 900)) ; #4
;; ((0 1 2 3 ... 38 39 40) (41 42 43 ...
;; 79 80 81) ... (82 83 84 ...
Shows quot composed with rem, zero?, inc, and partition-all to calculate and use a whole-container size. section 5.7
