Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Last active November 23, 2023 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chase-lambert/53de4ee8ad7bfacf9805417675c704e9 to your computer and use it in GitHub Desktop.
Save chase-lambert/53de4ee8ad7bfacf9805417675c704e9 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23-11-20
(ns between-nums
(:require [clojure.test :refer [deftest is]]))
(defn between-nums [a b op]
(let [[a b] (sort [a b])
nums (range (inc a) b)
prime? (fn [n] (when (> n 1)
(empty?
(filter #(= 0 (mod n %)) (range 2 n)))))]
(case op
"even" (filter even? nums)
"odd" (filter odd? nums)
"prime" (filter prime? nums))))
(deftest between-nums-test
(is (= [4 6 8 10] (between-nums 3 11 "even")))
(is (= [2 3 5 7 11 13] (between-nums 15 1 "prime"))))
@chase-lambert
Copy link
Author

chase-lambert commented Nov 23, 2023

saw the little (sort [a b]) approach here and thought it was a bit cleaner than my original approach: https://github.com/mebble/rendezvous-with-cassidoo/blob/main/2023-11-20.clj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment