Clojure, 292 characters after minimizing
I'm just learning clojure and thought it'd be fun to give this a shot. Here's my reasoning:
To strip off consonants from beginning of string:
(drop-while (fn [x] (not (some #(= % x) "aeiou"))) name)
To handle the extra rules for "b", "f" and "m", I broke text into list of phrases:
[", bo-b" "\nBanana-fana-fo-f" "\nFee-fi-mo-m"]
Then, I applied a function that asks whether the phrase ends with the same letter that the name starts with, and used that to transform those 3 phrases based on the rules of the puzzle
Final step is to build a string with results
Here's a first attempt, almost positive I can widdle it down further:
(defn name-game
[n]
(let [[b f m] (map (fn [x] (if (some #(= % (first n) (last x)) "bfm")
(str (apply str (butlast x)) (apply str (rest n)))
(str x (apply str (drop-while (fn [x] (not (some #(= % x) "aeiou"))) n))))) [", bo-b" "\nBanana-fana-fo-f" "\nFee-fi-mo-m"])]
(str n ", " n b f m "\n" n "!")))
I'm just learning clojure and thought it'd be fun to give this a shot. Here's my reasoning:
- To strip off consonants from beginning of string:
(drop-while (fn [x] (not (some #(= % x) "aeiou"))) name)
- To handle the extra rules for "b", "f" and "m", I broke text into list of phrases:[", bo-b" "\nBanana-fana-fo-f" "\nFee-fi-mo-m"]
- Then, I applied a function that asks whether the phrase ends with the same letter that the name starts with, and used that to transform those 3 phrases based on the rules of the puzzle
- Final step is to build a string with results