This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-14
Channels
- # announcements (3)
- # aws (7)
- # babashka (108)
- # beginners (222)
- # bristol-clojurians (3)
- # calva (8)
- # chlorine-clover (1)
- # cider (14)
- # clj-kondo (4)
- # cljdoc (6)
- # cljs-dev (89)
- # cljsrn (13)
- # clojars (6)
- # clojure (89)
- # clojure-australia (1)
- # clojure-europe (11)
- # clojure-italy (9)
- # clojure-losangeles (11)
- # clojure-nl (6)
- # clojure-spec (2)
- # clojure-sweden (1)
- # clojure-uk (9)
- # clojurescript (47)
- # conjure (18)
- # datomic (7)
- # docker (1)
- # figwheel (43)
- # figwheel-main (2)
- # fulcro (31)
- # kaocha (3)
- # leiningen (7)
- # luminus (2)
- # nrepl (14)
- # off-topic (24)
- # pathom (5)
- # pedestal (5)
- # rdf (4)
- # re-frame (49)
- # reagent (12)
- # reitit (9)
- # rum (21)
- # shadow-cljs (109)
- # tools-deps (35)
- # vim (8)
- # wasm (1)
Did you record again? It's a bit early (putting kids to bed) and I enjoyed watching the last meeting after the fact
Ah, sorry i missed it! For some reason I was thinking it was going to start at 7:30 instead of 6 ๐
I even did the homework - hereโs the solution I came up with:
(def vowels
#{\a \A
\e \E
\i \I
\o \O
\u \U})
(defn nmin
"nil-safe min function: does not throw NullPointerException if any args are nil.
Returns min of a and b if both are non-nil.
If a or b is nil, returns the other non-nil value.
If both a and b are nil, returns nil."
[a b]
(if a
(if b
(min a b)
a)
b))
(defn nearest-vowels
"Given a string, returns a sequence indicating the distance from the nearest vowel of each character position."
[s]
(->> s
; initial pass over input string -> reversed seq of distance from previous vowel
(reduce (fn [rev-seq c]
(conj rev-seq
(if (get vowels c)
0
(when-let [d (first rev-seq)]
(inc d)))))
'())
; final pass over reversed seq: accumulate distance to next vowel (= distance from previous 0), compare -> seq of distance from closest vowel
(reduce (fn [[res-seq
d-next]
d-prev]
(let [d-next (if (= d-prev 0)
0
(when d-next
(inc d-next)))
d (nmin d-prev d-next)]
[(conj res-seq d)
d-next]))
['()
nil])
(first)))
I took a regex recursive route on this but wasn't happy with it. I'd love to see the solutions everyone came up with
my solution is here: https://github.com/justone/misc.clj/tree/master/la-meetup-may-2020
๐ 4