Skip to content

Instantly share code, notes, and snippets.

@opensussex
Last active November 26, 2019 08:25
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 opensussex/52a07aaf18071d6049ce9fd50f450919 to your computer and use it in GitHub Desktop.
Save opensussex/52a07aaf18071d6049ce9fd50f450919 to your computer and use it in GitHub Desktop.
middle me challenge written in clojure

Challenge Write a function that will take a key of X and place it in the middle of Y repeated N times.

Rules: If X cannot be placed in the middle, return X. N will always be > 0.

(ns test.core
  (:gen-class))

(defn string-side [y n]
  (reduce str (repeat (/ n 2) y)))

(defn middle-me [x y n]
  (if (not= (mod n 2) 0)
    x
    (let [side (string-side y n)]
      (str side x side))))
    
    

(defn -main []
  (println (middle-me "*" "T" 4)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment