Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Last active May 17, 2023 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chase-lambert/b8ec55fa36538d5ff5dca179883db43f to your computer and use it in GitHub Desktop.
Save chase-lambert/b8ec55fa36538d5ff5dca179883db43f to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23.03.05
(ns scramble
(:require [clojure.string :as string]))
(defn scramble-word [w]
(let [middle-letters (subs w 1 (dec (count w)))
mixed-middle (shuffle (seq middle-letters))]
(str (first w) (apply str mixed-middle) (last w))))
(defn scramble [s]
(string/join " "
(reduce (fn [acc w]
(cond
(#{"." "," "?"} w)
(conj (pop acc) (str (last acc) w))
(> (count w) 3)
(conj acc (scramble-word w))
:else (conj acc w)))
[]
(re-seq #"\w+|[^\w\s]" s))))
(comment
(def s "A quick brown fox jumped over the lazy dog.")
(scramble s)) ;; "A qucik bworn fox jumepd oevr the lzay dog."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment