Tonight's meetup was fun, thanks to all who attended!
Did you record again? It's a bit early (putting kids to bed) and I enjoyed watching the last meeting after the fact
Yeah, it was recorded.
Yay!
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)))
Very cool @esp1 !
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
I saw a very clever solution and was like "how didn't I think of that!"
my solution is here: https://github.com/justone/misc.clj/tree/master/la-meetup-may-2020
we worked through making a faster solution during the meetup