Created
December 7, 2010 03:27
-
-
Save will/731409 to your computer and use it in GitHub Desktop.
null pointer exception
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
; no more null pointer :) | |
(use 'clojure.set) | |
(def tens (range 1 10)) | |
(def ones (range 0 10)) | |
(defn combine [a b] (+ (* 10 a) b)) | |
(defn uniq [a b n] (if (= a n) b a)) | |
(defn safed [a b] (if (zero? b) 0 (/ a b))) | |
(def answers | |
(for [a tens b ones c tens d ones | |
:when (let [ | |
inter (intersection (set [a b]) (set [c d])) | |
inter-int (first inter) | |
ab (combine a b) | |
cd (combine c d) ] | |
(and | |
(= 1 (count inter)) | |
(< (safed ab cd) 1) | |
(not (= 0 b d)) | |
(= (safed ab cd) (safed (uniq a b inter-int) (uniq c d inter-int))) | |
))] | |
[(combine a b) (combine c d)])) | |
(prn answers) | |
(prn (map #(/ (first %) (last %)) answers)) | |
(prn (reduce * (map #(/ (first %) (last %)) answers))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment