Last active
November 23, 2023 11:28
-
-
Save chase-lambert/53de4ee8ad7bfacf9805417675c704e9 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23-11-20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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