Create a gist now

Instantly share code, notes, and snippets.

@katsuyan /q2.clj
Last active Sep 25, 2016

What would you like to do?
(require '[clojure.string :as string])
(defn palindromes-num? [num1 num2]
(let [num1-str (str num1)
num2-str (str num2)]
(if (>= num2 1000)
(= num1-str (apply str (reverse num2-str)))
(defn join-num [num1 num2]
(+ (* num2 10) num1))
(defn operators-list []
(let [operators [* join-num]]
(for [x operators y operators z operators :when (not= x y z join-num)] [x y z])))
(defn make-numbers-list [num]
(vec (map read-string (string/split (str num) #""))))
(defn answer? [num]
(let [opls (operators-list)
nums (make-numbers-list num)]
(loop [opls opls]
(if (empty? opls)
(let [ops (first opls)]
(if (or (palindromes-num? num ((ops 0) ((ops 1) ((ops 2) (nums 3) (nums 2)) (nums 1)) (nums 0)))
(palindromes-num? num ((ops 0) ((ops 1) (nums 3) (nums 2)) ((ops 2) (nums 1) (nums 0))))
(palindromes-num? num ((ops 0) ((ops 1) (nums 3) ((ops 1) (nums 2) (nums 1))) (nums 0))))
(recur (rest opls)))))))))
(defn get-answer []
(loop [num 1000]
(if (> num 9999) nil
(if (answer? num)
(println num))
(recur (+ num 1))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment