Skip to content

Instantly share code, notes, and snippets.

Last active May 17, 2023 00:42
What would you like to do?
rendezvous with cassidoo challenge: 22.10.17
(ns pass-doors
(:require [clojure.test :refer [deftest is]))
(defn pass-doors [n number-of-passes]
(let [initial (repeat n 1)
passes (range number-of-passes)
toggle-door (fn [d] (if (zero? d) 1 0))
create-sections (fn [doors pass]
(map vec (partition-all (inc pass) doors)))
toggle-section (fn [section pass]
(if (< pass (count section))
(assoc section pass (toggle-door (last section)))
run-passes (reduce (fn [doors pass]
(mapcat #(toggle-section % pass) (create-sections doors pass)))
(filter zero? run-passes))))
(deftest pass-doors-test
(let [n 7
number-of-passes 3]
(is (= 4 (pass-doors n number-of-passes)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment