Last active
May 17, 2023 00:41
-
-
Save chase-lambert/b8ec55fa36538d5ff5dca179883db43f to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 23.03.05
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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