aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Wardhaugh <tyler.wardhaugh@entercom.com>2020-08-21 15:51:04 -0700
committerTyler Wardhaugh <tyler.wardhaugh@entercom.com>2020-08-26 13:53:19 -0700
commit34c250bacdfc6630633488cdd0fa25132cbe03ab (patch)
tree81f419a250402c521fa8946bb081bc39439771e1
parent423b552b8547f4125749ae062ca5e73a64dbc931 (diff)
downloadperlweeklychallenge-club-34c250bacdfc6630633488cdd0fa25132cbe03ab.tar.gz
perlweeklychallenge-club-34c250bacdfc6630633488cdd0fa25132cbe03ab.tar.bz2
perlweeklychallenge-club-34c250bacdfc6630633488cdd0fa25132cbe03ab.zip
rename source files in c74
Clojure filenames must use underscores; dashes are not allowed. Add a symlink so that the expected convention (using dashes) leads people to the right place.
l---------[-rw-r--r--]challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-1.clj21
l---------[-rw-r--r--]challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-2.clj34
-rw-r--r--challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj20
-rw-r--r--challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj33
4 files changed, 55 insertions, 53 deletions
diff --git a/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-1.clj b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-1.clj
index 416d2a1d85..924a7a086e 100644..120000
--- a/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-1.clj
+++ b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-1.clj
@@ -1,20 +1 @@
-(ns tw.weekly.ch-1)
-
-(defn majority
- "Calculate the majority element, which is the element in a list that appears more than floor(size_of_list/2), prefering the least significant digit that matches that criteria. Returns -1 if no such element is found."
- [coll]
- (let [minimum (Math/floor (/ (count coll) 2))
- maj (->> coll
- frequencies
- (filter (comp #(> % minimum) second))
- (sort second)
- ffirst)]
- (or maj -1)))
-
-(defn -main
- "Run Task 1 with a list of integers, defaulting to the sample given in the task description."
- [& args]
- (let [N (if (not-empty args)
- (map clojure.edn/read-string args)
- [2, 2, 2, 3, 2, 4, 2])]
- (println (majority N))))
+ch_1.clj \ No newline at end of file
diff --git a/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-2.clj b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-2.clj
index 299ab63690..5a32e17ef9 100644..120000
--- a/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-2.clj
+++ b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch-2.clj
@@ -1,33 +1 @@
-(ns tw.weekly.ch-2
- (:require [clojure.string :as str])
- (:require [flatland.ordered.map :as fo]))
-
-(defn ordered-frequencies
- "A modification of clojure.core/frequencies that guarantees the map returns keys in the order seen in the collection. Thus it returns an ordered map from distinct items in coll to the number of times they appear."
- [coll]
- (persistent!
- (reduce (fn [counts x]
- (assoc! counts x (inc (get counts x 0))))
- (transient (fo/ordered-map)) coll)))
-
-(defn find-fnr [string]
- "Find the first non-repeating character (FNR) for a string."
- (let [counts (ordered-frequencies string)
- non-repeaters (filter (comp #(= 1 %) second) counts)]
- (-> non-repeaters last first)))
-
-(defn find-fnr-over-string
- "Generate a string comprised of the first non-repeating character (FNR) for successive substrings of a given string."
- [string]
- (->> string
- (reductions str "")
- (drop 1)
- (map find-fnr)
- (map #(or % \#))
- str/join))
-
-(defn -main
- "Run Task 2 with a string, defaulting to the sample given in the task description."
- [& args]
- (let [S (or (-> args first) "ababc")]
- (println (find-fnr-over-string S))))
+ch_2.clj \ No newline at end of file
diff --git a/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj
new file mode 100644
index 0000000000..416d2a1d85
--- /dev/null
+++ b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_1.clj
@@ -0,0 +1,20 @@
+(ns tw.weekly.ch-1)
+
+(defn majority
+ "Calculate the majority element, which is the element in a list that appears more than floor(size_of_list/2), prefering the least significant digit that matches that criteria. Returns -1 if no such element is found."
+ [coll]
+ (let [minimum (Math/floor (/ (count coll) 2))
+ maj (->> coll
+ frequencies
+ (filter (comp #(> % minimum) second))
+ (sort second)
+ ffirst)]
+ (or maj -1)))
+
+(defn -main
+ "Run Task 1 with a list of integers, defaulting to the sample given in the task description."
+ [& args]
+ (let [N (if (not-empty args)
+ (map clojure.edn/read-string args)
+ [2, 2, 2, 3, 2, 4, 2])]
+ (println (majority N))))
diff --git a/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj
new file mode 100644
index 0000000000..299ab63690
--- /dev/null
+++ b/challenge-074/tyler-wardhaugh/clojure/src/tw/weekly/ch_2.clj
@@ -0,0 +1,33 @@
+(ns tw.weekly.ch-2
+ (:require [clojure.string :as str])
+ (:require [flatland.ordered.map :as fo]))
+
+(defn ordered-frequencies
+ "A modification of clojure.core/frequencies that guarantees the map returns keys in the order seen in the collection. Thus it returns an ordered map from distinct items in coll to the number of times they appear."
+ [coll]
+ (persistent!
+ (reduce (fn [counts x]
+ (assoc! counts x (inc (get counts x 0))))
+ (transient (fo/ordered-map)) coll)))
+
+(defn find-fnr [string]
+ "Find the first non-repeating character (FNR) for a string."
+ (let [counts (ordered-frequencies string)
+ non-repeaters (filter (comp #(= 1 %) second) counts)]
+ (-> non-repeaters last first)))
+
+(defn find-fnr-over-string
+ "Generate a string comprised of the first non-repeating character (FNR) for successive substrings of a given string."
+ [string]
+ (->> string
+ (reductions str "")
+ (drop 1)
+ (map find-fnr)
+ (map #(or % \#))
+ str/join))
+
+(defn -main
+ "Run Task 2 with a string, defaulting to the sample given in the task description."
+ [& args]
+ (let [S (or (-> args first) "ababc")]
+ (println (find-fnr-over-string S))))