Guest User

Untitled

a guest
Sep 18th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn find-best-combination
  2.   [dolls-information weight-restriction index]
  3.   (if (zero? weight-restriction)
  4.     [0 []]
  5.   ;else
  6.     (if (< index 0)
  7.       [0 []]
  8.     ;else
  9.       (let [{doll-weight :weight doll-value :value} (get dolls-information index)]
  10.         (if (> doll-weight weight-restriction)
  11.           (find-best-combination-memoized dolls-information weight-restriction (- index 1))
  12.         ;else
  13.           (let [[vn sn :as no]   (find-best-combination-memoized dolls-information weight-restriction (- index 1))
  14.                 [vy sy :as yes]  (find-best-combination-memoized dolls-information (- weight-restriction doll-weight) (- index 1))]
  15.             (if (> (+ vy doll-value) vn)
  16.               [(+ vy doll-value) (conj sy index)]
  17.             ;else
  18.               no
  19.             )
  20.           )
  21.         )
  22.       )
  23.     )
  24.   )
  25. )
Add Comment
Please, Sign In to add comment