clojure-losangeles

https://www.meetup.com/Los-Angeles-Clojure-Users-Group/
nate 2020-05-14T02:39:26.056900Z

Tonight's meetup was fun, thanks to all who attended!

πŸ‘ 1
βž• 1
bocaj 2020-05-14T02:45:39.058500Z

Did you record again? It's a bit early (putting kids to bed) and I enjoyed watching the last meeting after the fact

nate 2020-05-14T02:53:52.058900Z

Yeah, it was recorded.

bocaj 2020-05-14T02:55:07.059600Z

Yay!

esp1 2020-05-14T02:58:56.061500Z

Ah, sorry i missed it! For some reason I was thinking it was going to start at 7:30 instead of 6 πŸ˜“

esp1 2020-05-14T02:59:42.062300Z

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)))

nate 2020-05-14T03:03:20.063100Z

Very cool @esp1 !

Mario C. 2020-05-14T16:19:34.065200Z

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

Mario C. 2020-05-14T16:23:49.066100Z

I saw a very clever solution and was like "how didn't I think of that!"

nate 2020-05-14T18:03:37.066400Z

my solution is here: https://github.com/justone/misc.clj/tree/master/la-meetup-may-2020

πŸ‘ 1
nate 2020-05-14T18:04:06.067100Z

we worked through making a faster solution during the meetup