Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What is the final solution?

Name: Anonymous 2016-05-29 15:48

Name: Anonymous 2016-05-29 23:04

Did I do it right (srs)?

Clojure

(defn setup-lockers
[]
(for [n (range 1 101)] {:num n :state 'open}))

(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)))


result:
=> (count-open-lockers (toggle-nth-lockers 1 100 (setup-lockers)))
90

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List