SHARE
TWEET

Untitled

a guest Dec 4th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (def pw-range [273025 767253])
  2.  
  3. (defn two-adjanced-digits? [x]
  4.   (let [digits (str x)]
  5.     (loop [last-digit (first digits)
  6.            digits (next digits)]
  7.       (cond
  8.         (nil? digits) false
  9.        
  10.         (= (first digits)
  11.            last-digit)
  12.         true
  13.  
  14.         :else (recur (first digits) (next digits))))))
  15.  
  16. (defn increase-digits-or-same? [x]
  17.   (let [digits (map #(Character/getNumericValue %) (str x))]
  18.     (loop [last-digit (first digits)
  19.            digits (next digits)]
  20.       (cond
  21.         (nil? digits) true
  22.         (<= last-digit (first digits)) (recur (first digits) (next digits))
  23.         :else false))))
  24.  
  25. (defn possible-password? [x]
  26.   (and
  27.    (two-adjanced-digits? x)
  28.    (increase-digits-or-same? x)))
  29.  
  30. (->> (range (get pw-range 0) (inc (get pw-range 1)))
  31.        (filter two-adjanced-digits?)
  32.        (filter increase-digits-or-same?)
  33.        count) ;; => 910
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top