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 16:08

Free shower cabins?

Name: Anonymous 2016-05-29 17:58

You know, it would have been a lot more convient to just copy and paste that here instead of linking.

Name: Anonymous 2016-05-29 19:26

>>3
He probably found it on Reddit or something.

Name: Anonymous 2016-05-29 19:26

A locker would be open if its number of divisors is odd. So only perfect squares. So 1,4,9,16,25,36,49,64,81,100. So 10 lockers open.

Name: Anonymous 2016-05-29 19:29

a man begins...
that question is sexist.

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

Name: Anonymous 2016-05-30 1:26

Coljure is an acceptable Lisp!

Name: Anonymous 2016-05-30 1:31

>>7
According to >>1 all lockers start as closed. That must be why you get 90 instead of 10.

Name: Anonymous 2016-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: Anonymous 2016-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

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