I'm attempting to turn a string into a collection of size N. My approach returns the wrong results.
(defn chop
[s pieces]
(let [piece-size (int (/ (count s) pieces))]
(map #(str/join %) (partition-all piece-size s))))
(def big-str (slurp "/path/to/9065-byte-string.txt"))
(count (chop (str/join (take 100 (repeat "x"))) 100))
100
(count (chop (str/join (take 10005 (repeat "x"))) 100))
101
so with my test string that I'm trying to split into 100 pieces, I actually sometimes get 101 pieces (if pieze-size isn't an even multiple of 100). Not sure what is going on. Maybe my math is wrong on piece-size.
It works if I pad the string, but I don't want to do that.
(defn chop
[s pieces]
(let [pad-size (- 100 (mod (count s) pieces))
padded (str s (str/join (take pad-size (repeat " "))))
piece-size (int (/ (count padded) pieces))
]
(println "pad-size=" pad-size)
(println "piece-size=" piece-size)
(map #(str/join %) (partition-all piece-size padded))))
