(defn toggle-nth-lockers [a b lockers] (if (> a b) lockers (recur (+ a 1) b (map (fn [{n :num s :state}] (if (= 0 (mod n a)) {:num n :state (if (= s 'open) 'closed 'open)} {:num n :state s})) lockers))))
(defn count-open-lockers [lockers] (count (filter (fn [{n :num s :state}] (= s 'open)) lockers)))
>>7 According to >>1 all lockers start as closed. That must be why you get 90 instead of 10.
Name:
Anonymous2016-05-30 5:19
>>9 Actually the mistake I made was "1 100"--should be "2 100" since the guy starts with them all open and closes the multiples of 2 first. e.g., => (count-open-lockers (toggle-nth-lockers 1 100 (setup-lockers))) 10 with the same code above
Name:
Anonymous2016-05-30 5:21
>>9 and yeah you get 10 also from the above code by just starting off with all closed of course cause all the numbers are multiples of 1