(defn not-last-car [x]
  "Given percent of reduction, get all the bears, apart from the ones that go to the last car"
  (let [prog-mult (- 1 (/ x 100))
        take-limit (- 1 prog-mult)]
    (take-while #(> % take-limit) (iterate #(* % prog-mult) 1))))

(defn partition-bears [bears]
  "Given a sequence of bears groups them by cars"
  (loop [s bears
         acc []]
    (cond
      (empty? s)
        acc
      (> 1 (+ (first s) (reduce + (peek acc))))
        (recur (rest s) (conj (pop acc) (conj (peek acc) (first s))))
      :default
        (recur (rest s) (conj acc [(first s)])))))

(defn solution [x]
  (let [distribution (-> x not-last-car partition-bears)
        size (count distribution)]
    (println "Cars required" (inc size) "\n"
      (apply str (map-indexed #(str (inc %1) ":" %2 "\n") distribution))
      (str (inc size) ":all other bears"))))

(solution 10)
(solution 20)