aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t1.clj27
-rw-r--r--challenge-080/tyler-wardhaugh/clojure/test/tw/weekly/c80_test.clj10
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t1.clj b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t1.clj
new file mode 100644
index 0000000000..8540ad4d0a
--- /dev/null
+++ b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t1.clj
@@ -0,0 +1,27 @@
+(ns tw.weekly.c80.t1
+ (:require [clojure.edn :as edn])
+ (:require [clojure.set :as set]))
+
+;;; Task description for TASK #1 › Smallest Positive Number Bits
+;Submitted by: Mohammad S Anwar
+;You are given unsorted list of integers @N.
+;
+;Write a script to find out the smallest positive number missing.
+;;;;
+
+(defn smallest-missing
+ "Determine the smallest positive integer missing in a sequence."
+ [coll]
+ (when-let [missing (->> coll
+ ((juxt #(set (range 1 (inc (apply max %)))) set))
+ (apply set/difference)
+ seq)]
+ (apply min missing)))
+
+(defn -main
+ "Run Task 1 with a list of integers N, defaulting to the first one given in the examples."
+ [& args]
+ (let [N (or (some->> args (map edn/read-string)) [5 2 -2 0]) ]
+ (if-let [smallest (smallest-missing N)]
+ (println smallest)
+ (println "No positive integer is missing in the given sequence."))))
diff --git a/challenge-080/tyler-wardhaugh/clojure/test/tw/weekly/c80_test.clj b/challenge-080/tyler-wardhaugh/clojure/test/tw/weekly/c80_test.clj
new file mode 100644
index 0000000000..23d6d1772c
--- /dev/null
+++ b/challenge-080/tyler-wardhaugh/clojure/test/tw/weekly/c80_test.clj
@@ -0,0 +1,10 @@
+(ns tw.weekly.c80-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [tw.weekly.c80.t1 :refer [smallest-missing]]))
+
+(deftest task-1
+ (testing "Task 1, Smallest Positive Number Bits"
+ (is (= (smallest-missing [5 2 -2 0]) 1))
+ (is (= (smallest-missing [1 8 -1]) 2))
+ (is (= (smallest-missing [2 0 -1]) 1))
+ (is (nil? (smallest-missing [1 2 3])))))